Difference between revisions of "WinCE port"

From Free Pascal wiki
Jump to navigationJump to search
Line 7: Line 7:
 
* CPU support for WinCE target:
 
* CPU support for WinCE target:
 
** [[ARM]] CPU is fully supported. See [[arm-wince]] how to setup a crosscompiling enviroment  
 
** [[ARM]] CPU is fully supported. See [[arm-wince]] how to setup a crosscompiling enviroment  
** [[i386]] CPU support was not tested too much and may contain bugs. Patches are welcome. See [[i386-wince]] for howto compile for i386-wince
+
  There are readymade crosscompiler package available(See Lazarus download sources)
 +
** [[i386]] CPU support was not tested too much and may contain bugs. Patches are welcome.Normally there is no readymade crosscompiler package for this CPU. See [[i386-wince]] howto setup a cross compile enviroment(Win32 Host)
 
* The following platforms are supported:
 
* The following platforms are supported:
 
** Devices based on WinCE 3.0 or later
 
** Devices based on WinCE 3.0 or later
Line 18: Line 19:
 
* [http://community.freepascal.org:10000/docs-html/rtl RTL] and [http://community.freepascal.org:10000/docs-html/fcl FCL] units are working.
 
* [http://community.freepascal.org:10000/docs-html/rtl RTL] and [http://community.freepascal.org:10000/docs-html/fcl FCL] units are working.
  
== Download cross compiler ==
 
The easiest way to start development for WinCE is to download the latest release version of FPC for Win32 and arm-wince cross compiler for Win32.
 
  
Download them here: http://www.freepascal.org/download.var
 
 
First install FPC for Win32, then install arm-wince cross compiler as add-on package.
 
 
== Building WinCE cross compiler from sources ==
 
 
During the tutorial some paths will be suposed to demonstrate the build process. Just substitute those paths with the ones on your system.
 
 
This tutorial demonstrates how to build '''arm-wince''' crosscompiler.
 
See [[i386-wince]] for target i386-wince (crosscompiler and binutils are not needed there, as the standard i386-Win32 versions can be used)
 
 
 
'''Step 1''' - Cross binutils (not necessary for [[i386-wince]])
 
 
These are the basic tools necessary to create executables, such as: Linker (ld), Assembler (as), Archiver (ar) (Creates smartlinking .a files), strip and some others.
 
 
You need cross binutils for arm-wince, get them from  ftp://ftp.freepascal.org/pub/fpc/contrib/cross/arm-wince-binutils.zip for Win32.
 
 
Extract them to some dir in the path on your machine.
 
We will supose that you extracted the cross binutils to: <tt>C:\Programas\arm</tt>
 
 
 
'''Step 2''' - Cross compiler (not necessary for [[i386-wince]])
 
 
Now you need to build fpc cross compiler for ARM processor. To do that you need fpc 2.2.0 or later sources and working installation of fpc 2.2.0 for Win32.
 
 
You can get the latest fpc source repository from Subversion: http://www.freepascal.org/develop.html#svn
 
 
We will supose that your Win32 fpc compiler is located here: <tt>C:\Programas\fpc\bin\i386-win32</tt>
 
 
And your Free Pascal source code is located here: <tt>C:\Programas\fpc</tt>
 
 
 
'''Step 3''' - The Build process (See [[i386-wince]] for the build process for that target)
 
 
In order to build the cross compiler it is necessary to have a correct <tt>PATH</tt> environment variable.
 
On Windows it is very easy to get a <tt>PATH</tt> crowded with information put by installers. To ensure that your path is correct, create a batch file with the following code:
 
 
<pre>
 
PATH=C:\Programas\fpc\bin\i386-win32;C:\Programas\arm
 
make cycle CPU_TARGET=arm OS_TARGET=wince
 
</pre>
 
 
Put this file on <tt>C:\Programas\fpc\compiler</tt>, open the Windows command line, go to this folder and execute the batch file.
 
 
On the end of the compile you should not see any errors.
 
 
You should have a <tt>ppccrossarm.exe</tt> in <tt>C:\Programas\fpc\compiler</tt> and some <tt>.o</tt> and <tt>.ppu</tt> files in <tt>C:\Programas\fpc\rtl\units\arm-wince</tt>
 
 
Now copy those files to your Free Pascal installation. The cross compiler <tt>ppccrossarm.exe</tt> should go to <tt>C:\Programas\fpc\bin\arm-wince</tt> and the units to <tt>C:\Programas\fpc\units\arm-wince</tt>
 
 
 
'''Step 4''' - Configuration file
 
 
Now you need to create <tt>fpc.cfg</tt> configuration file in <tt>C:\Programas\fpc\bin\arm-wince</tt> folder in order to use <tt>ppccrossarm.exe</tt> easy.
 
 
Create empty <tt>fpc.cfg</tt> file in <tt>C:\Programas\fpc\bin\arm-wince</tt> folder and add the following lines to it:
 
<pre>
 
-Twince
 
-FuC:\Programas\fpc\units\arm-wince
 
-XParm-wince-
 
-FDC:\Programas\arm
 
</pre>
 
 
Finally add <tt>C:\Programas\fpc\bin\arm-wince</tt> and <tt>C:\Programas\fpc\bin\i386-win32</tt> to your <tt>PATH</tt> environment variable.
 
 
'''Remember to substitute the paths with the ones on your system.'''
 
 
'''Alternative Step 4''' - Configuration file for hybrid compilation
 
 
If you want to compile your projects with the same "fpc" for both win32 and winCE platforms, you can do the following:
 
* copy ppcrossarm.exe into your fpc/bin/i386-win32 directory
 
* edit your fpc.cfg in that directory and add:
 
<pre>
 
-FuC:\path_to_fpc\units\arm-wince
 
-XParm-wince-
 
-FDC:\path_to_arm_binutils
 
</pre>
 
 
'''Remember to substitute the paths with the ones on your system.'''
 
 
Now when you want to compile for WinCE you just have to specify the OS and Arch targets to fpc.
 
 
NOTE: if you use Lazarus this will work flawlessly, but make sure to point lazarus to "fpc.exe" not "ppc386.exe".
 
 
== Compiling a Test Project ==
 
 
You compiled the compiler! Now, what can I do with it? This is a tutorial to create a hello world like software with your new compiler.
 
 
'''Step 1''' - Installing and Configuring the Emulator
 
 
You will need a Windows CE Emulator configured for ActiveSync. The ActiveSync is necessary to install PocketCMD, a command line tool to run our hello world software.
 
 
Download the free Pocket PC device emulator from Microsoft. It emulates ARM CPU. http://msdn.microsoft.com/mobility/downloads/Emulator/default.aspx
 
 
There is a tutorial on how to set up the Emulator for ActiveSync [http://www.pocketpcfaq.com/faqs/5.0/emulator.htm here].
 
 
'''Step 2''' - Installing the command line
 
 
Download and install '''PocketCMD''' by SymbolicTools. Get it [http://www.symbolictools.de/public/pocketconsole/applications/PocketCMD here] (this site seems to be gone) but try here [http://www.mobile2day.de/platform_wince/device/CASIO/Cassiopeia+E-115/download.html?file=c112516.exe&prod=14571]
 
 
To enable the console on newer devices (I needed it in my 6.1CE pro), you may to set the following registry value [http://forum.xda-developers.com/showthread.php?t=275019&highlight=console link]
 
HKEY_LOCAL_MACHINE\Drivers\Console\OutputTo -> 0
 
 
Check [[WinCE_port_Hints]] for more details on programming under Windows CE platform.
 
 
'''Step 3''' - Compiling
 
 
A example file to compile:
 
 
<pre>
 
program test;
 
 
{$apptype console}
 
 
var
 
  Str: string;
 
begin
 
  WriteLn('Software Developed with:');
 
  WriteLn('The Free Pascal Compiler');
 
  WriteLn('');
 
  WriteLn('Please, enter your name:');
 
  ReadLn(Str);
 
  WriteLn('Your name is: ' + Str);
 
end.
 
</pre>
 
 
Sample command line to compile <tt>test.pas</tt>:
 
 
<tt>ppcrossarm test.pas</tt>
 
 
You will get <tt>test.exe</tt> executable file. Copy it to your Windows CE device and run.
 
 
[http://wiki.lazarus.freepascal.org/index.php/Windows_CE_Interface#Screenshots Here] is a screenshot of a software created this way.
 
  
 
== Debugging WinCE applications ==
 
== Debugging WinCE applications ==

Revision as of 20:18, 26 February 2012

WinCE Logo.png

This article applies to Windows CE only.

See also: Multiplatform Programming Guide

English (en) italiano (it) português (pt) русский (ru) 中文(台灣)‎ (zh_TW)

WinCE port is quite complete and usable. The port was started and maintained by Yury Sidorov. Oliver (Oro06) ported WinCE API headers.

Status

  • FPC 2.2.0 or later supports WinCE target.
  • CPU support for WinCE target:
    • ARM CPU is fully supported. See arm-wince how to setup a crosscompiling enviroment
  There are readymade crosscompiler package available(See Lazarus download sources) 
    • i386 CPU support was not tested too much and may contain bugs. Patches are welcome.Normally there is no readymade crosscompiler package for this CPU. See i386-wince howto setup a cross compile enviroment(Win32 Host)
  • The following platforms are supported:
    • Devices based on WinCE 3.0 or later
    • Pocket PC 2002 – WinCE version: 3.0
    • Pocket PC 2003 – WinCE version: 4.20
    • Pocket PC 2003 Second Edition – WinCE version: 4.21
    • Windows Mobile 5 – WinCE version: 5.0
    • Windows Mobile 6 – WinCE version: 5.2
    • Windows Mobile 6.5 - WinCE version: 5.2.1
  • RTL and FCL units are working.


Debugging WinCE applications

GDB can be used to debug your WinCE applications remotely via ActiveSync. Download GDB 6.4 for Win32 host and arm-wince target here: ftp://ftp.freepascal.org/pub/fpc/contrib/cross/gdb-6.4-win32-arm-wince.zip

Some hints:

  • Pass --tui parameter to GDB to enable TUI interface which makes debugging more comfortable.
  • Use unix line endings (LF only) in your pascal source files. Otherwise GDB will show sources incorrctly.

How to use:

First, make ActiveSync connection to your Pocket PC device.

Then launch gdb:

gdb --tui <your_executable_at_local_pc>

On gdb prompt type:

run or just r

GDB will copy your executable to the device in \gdb folder and run it.

Here is a short list of most needed GDB commands:

  • r args - run program with args arguments.
  • s - step into.
  • n - step over.
  • ni - step over instrument.step over assembly instruction.
  • c - continue execution.
  • br <function_name> - set a breakpoint at function_name. Use PASCALMAIN to set a breakpoint at program start.
  • br <source_file>:<line_number> - set a breakpoint at specified source line.
  • disas - show disassembly of current location.
  • x/fmt address - dump memory at address with special format.use "help x" for more informations.
  • bt - back trace.print back trace of the call stack.
  • where - Display the current line and function and the stack of calls that got you there.
  • q - Quit gdb.

To learn more how to use GDB read its documentation here: http://www.gnu.org/software/gdb/documentation

Building FPC libraries

If you want to build libraries available with FPC just go to library folder and execute:

PATH=C:\Programas\fpc\bin\i386-win32;C:\Programas\fpc\compiler;C:\Programas\arm
make OS_TARGET=wince CPU_TARGET=arm PP=ppcrossarm.exe

For example you want to build FCL. Go to fpc\fcl folder and execute the command above. You will get FCL compiled units in fpc\fcl\units\arm-wince.

See Also

Links

Here are some links related to ARM CPU Architecture

Contacts

Write any questions regarding WinCE port to Yury Sidorov