Difference between revisions of "arm-wince"

From Free Pascal wiki
Jump to navigationJump to search
m (Add platform template)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This page describes setup of a crosscompiling environment (Host is Win32)
+
{{Platform only|WinCE|WinCE|Windows CE}}
  
== Download cross compiler ==
+
This page describes setup of a crosscompiling environment (host is Win32),.
 +
 
 +
== The easy way: download the 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.
 
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.
  
Line 8: Line 10:
 
First install FPC for Win32, then install arm-wince cross compiler as add-on package.
 
First install FPC for Win32, then install arm-wince cross compiler as add-on package.
  
== Building WinCE cross compiler from sources ==
+
== The hard way: building WinCE cross compiler from sources ==
 
+
This tutorial demonstrates how to build the '''arm-wince''' crosscompiler on Windows which allows you to compile Windows CE programs from your Windows desktop.  
During the tutorial some paths will be supposed to demonstrate the build process. Just substitute those paths with the ones on your system.
 
 
 
This tutorial demonstrates how to build '''arm-wince''' crosscompiler.  
 
  
'''Step 1''' - Cross binutils
+
{{Note|During the tutorial some paths will be used to demonstrate the build process. Just substitute those paths with the ones on your system.}}
 +
We will suppose that:
 +
* your FPC compiler is located here: <tt>c:\fpc\bin\i386-win32\fpc.exe</tt>
 +
* your Free Pascal source code is located here: <tt>c:\fpc</tt>
  
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.
+
=== Step 1: Cross binutils ===
 +
Binutils are the basic tools necessary to create executables, such as: linker (ld), assembler (as), archiver (ar), 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.
+
You need cross binutils for arm-wince (i.e. they run on your desktop but produce output suitable for arm-wince). Get them from ftp://ftp.freepascal.org/pub/fpc/contrib/cross/arm-wince-binutils.zip.
  
 
Extract them to some dir in the path on your machine.
 
Extract them to some dir in the path on your machine.
We will suppose that you extracted the cross binutils to: <tt>C:\Programas\arm</tt>
+
We will suppose that you extracted the cross binutils to: <tt>C:\cross\arm</tt>
  
  
'''Step 2''' - Cross compiler
+
=== Step 2: Building the cross compiler ===
 +
Now you need to build the FPC cross compiler for the ARM processor. To do that, you need:
 +
* FPC sources
 +
* a working installation of FPC
 +
* the cross binutils mentioned above
  
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
 
 
You can get the latest fpc source repository from Subversion: http://www.freepascal.org/develop.html#svn
 
 
 
We will suppose 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
 
  
 
In order to build the cross compiler it is necessary to have a correct <tt>PATH</tt> environment variable.
 
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:
+
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 called
 +
<tt>c:\fpc\compiler\create_cross_arm_wince.cmd</tt>
 +
with the following code:
  
<syntaxhighlight lang="bash">
+
<syntaxhighlight lang="dos">
PATH=C:\Programas\fpc\bin\i386-win32;C:\Programas\arm
+
PATH=c:\fpc\bin\i386-win32;C:\cross\arm
 
make cycle CPU_TARGET=arm OS_TARGET=wince
 
make cycle CPU_TARGET=arm OS_TARGET=wince
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Put this file on <tt>C:\Programas\fpc\compiler</tt>, open the Windows command line, go to this folder and execute the batch file.
+
Now open the Windows command line, and run the batch file:
 
+
<syntaxhighlight lang="dos">
On the end of the compile you should not see any errors.  
+
cd /d c:\fpc\compiler
 +
create_cross_arm_wince.cmd
 +
</syntaxhighlight>
  
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>
+
The compile should run without any errors.  
  
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>
+
You should now have a <tt>ppccrossarm.exe</tt> in <tt>c:\fpc\compiler</tt> and some <tt>.o</tt> and <tt>.ppu</tt> files in <tt>c:\fpc\rtl\units\arm-wince</tt>
  
 +
Now copy those files to your Free Pascal installation.
 +
* Copy the cross compiler <tt>ppccrossarm.exe</tt> to <tt>c:\fpc\bin\i386-win32\</tt>
 +
* Copy the units in <tt>c:\fpc\rtl\units\arm-wince</tt> to <tt>c:\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.
+
=== Step 3: Configuration file ===
 +
Now you need to edit your FPC configuration file in <tt>c:\fpc\bin\i386-win32\fpc.cfg</tt> in order to use <tt>ppccrossarm.exe</tt> easily.
  
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>
 
<pre>
-Twince
+
#IFDEF CPUARM
-FuC:\Programas\fpc\units\arm-wince
+
#IFDEF WINCE
 +
# Settings specific to cross compilation to wince on ARM.
 +
-FuC:\fpc\units\arm-wince
 
-XParm-wince-
 
-XParm-wince-
-FDC:\Programas\arm
+
-FDC:\cross\arm
 +
#ENDIF
 +
#ENDIF
 
</pre>
 
</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.
+
Now when you want to compile for WinCE you just have to specify the OS and Arch targets to FPC or Lazarus:
 
+
<syntaxhighlight lang="DOS">
'''Remember to substitute the paths with the ones on your system.'''
+
fpc -Twince -Parm yourfile.pas
 
+
</syntaxhighlight>
'''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".
 
  
 +
{{Note|When using Lazarus, make sure the compiler path/file in Lazarus options is set to "fpc.exe", not "ppc386.exe"}}
  
 
== Building FPC libraries ==
 
== Building FPC libraries ==
 
+
If you want to build libraries available with FPC just go to the library folder and execute:
If you want to build libraries available with FPC just go to library folder and execute:
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
PATH=C:\Programas\fpc\bin\i386-win32;C:\Programas\fpc\compiler;C:\Programas\arm
+
PATH=c:\fpc\bin\i386-win32;c:\fpc\compiler;C:\cross\arm
 
make OS_TARGET=wince CPU_TARGET=arm PP=ppcrossarm.exe
 
make OS_TARGET=wince CPU_TARGET=arm PP=ppcrossarm.exe
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 101: Line 93:
 
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.
 
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
+
=== 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.
 
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.
  
Line 109: Line 100:
 
There is a tutorial on how to set up the Emulator for ActiveSync [http://www.pocketpcfaq.com/faqs/5.0/emulator.htm here].
 
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
+
===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]
 
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]
  
Line 118: Line 108:
 
Check [[WinCE_port_Hints]] for more details on programming under Windows CE platform.
 
Check [[WinCE_port_Hints]] for more details on programming under Windows CE platform.
  
'''Step 3''' - Compiling
+
=== Step 3: Compiling ===
 
+
An example file to compile:
A example file to compile:
 
  
<syntaxhighlight>
+
<syntaxhighlight lang="pascal">
 
program test;
 
program test;
  
Line 139: Line 128:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Sample command line to compile <tt>test.pas</tt>:
+
Command line to compile <tt>test.pas</tt>:
  
<syntaxhighlight lang="bash">ppcrossarm test.pas</syntaxhighlight>
+
<syntaxhighlight lang="DOS">fpc -Twince -Parm test.pas</syntaxhighlight>
  
You will get <tt>test.exe</tt> executable file. Copy it to your Windows CE device and run.
+
You will get a <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.
 
[http://wiki.lazarus.freepascal.org/index.php/Windows_CE_Interface#Screenshots Here] is a screenshot of a software created this way.
  
 +
[[Category:WinCE]]
 
[[Category:Cross compilation]]
 
[[Category:Cross compilation]]
[[Category: ARM]]
+
[[Category:ARM]]

Latest revision as of 02:24, 9 August 2020

WinCE Logo.png

This article applies to Windows CE only.

See also: Multiplatform Programming Guide

This page describes setup of a crosscompiling environment (host is Win32),.

The easy way: download the 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.

The hard way: building WinCE cross compiler from sources

This tutorial demonstrates how to build the arm-wince crosscompiler on Windows which allows you to compile Windows CE programs from your Windows desktop.

Light bulb  Note: During the tutorial some paths will be used to demonstrate the build process. Just substitute those paths with the ones on your system.

We will suppose that:

  • your FPC compiler is located here: c:\fpc\bin\i386-win32\fpc.exe
  • your Free Pascal source code is located here: c:\fpc

Step 1: Cross binutils

Binutils are the basic tools necessary to create executables, such as: linker (ld), assembler (as), archiver (ar), strip and some others.

You need cross binutils for arm-wince (i.e. they run on your desktop but produce output suitable for arm-wince). Get them from ftp://ftp.freepascal.org/pub/fpc/contrib/cross/arm-wince-binutils.zip.

Extract them to some dir in the path on your machine. We will suppose that you extracted the cross binutils to: C:\cross\arm


Step 2: Building the cross compiler

Now you need to build the FPC cross compiler for the ARM processor. To do that, you need:

  • FPC sources
  • a working installation of FPC
  • the cross binutils mentioned above

You can get the latest FPC source repository from Subversion: http://www.freepascal.org/develop.html#svn

In order to build the cross compiler it is necessary to have a correct PATH environment variable. On Windows it is very easy to get a PATH crowded with information put by installers. To ensure that your path is correct, create a batch file called c:\fpc\compiler\create_cross_arm_wince.cmd with the following code:

PATH=c:\fpc\bin\i386-win32;C:\cross\arm
make cycle CPU_TARGET=arm OS_TARGET=wince

Now open the Windows command line, and run the batch file:

cd /d c:\fpc\compiler
create_cross_arm_wince.cmd

The compile should run without any errors.

You should now have a ppccrossarm.exe in c:\fpc\compiler and some .o and .ppu files in c:\fpc\rtl\units\arm-wince

Now copy those files to your Free Pascal installation.

  • Copy the cross compiler ppccrossarm.exe to c:\fpc\bin\i386-win32\
  • Copy the units in c:\fpc\rtl\units\arm-wince to c:\fpc\units\arm-wince


Step 3: Configuration file

Now you need to edit your FPC configuration file in c:\fpc\bin\i386-win32\fpc.cfg in order to use ppccrossarm.exe easily.

#IFDEF CPUARM
#IFDEF WINCE
# Settings specific to cross compilation to wince on ARM.
-FuC:\fpc\units\arm-wince
-XParm-wince-
-FDC:\cross\arm
#ENDIF
#ENDIF

Now when you want to compile for WinCE you just have to specify the OS and Arch targets to FPC or Lazarus:

fpc -Twince -Parm yourfile.pas
Light bulb  Note: When using Lazarus, make sure the compiler path/file in Lazarus options is set to "fpc.exe", not "ppc386.exe"

Building FPC libraries

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

PATH=c:\fpc\bin\i386-win32;c:\fpc\compiler;C:\cross\arm
make OS_TARGET=wince CPU_TARGET=arm PP=ppcrossarm.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 here.

Step 2: Installing the command line

Download and install PocketCMD by SymbolicTools. Get it here (this site seems to be gone) but try here [1]

To enable the console on newer devices (I needed it in my 6.1CE pro), you may to set the following registry value link

HKEY_LOCAL_MACHINE\Drivers\Console\OutputTo -> 0

Check WinCE_port_Hints for more details on programming under Windows CE platform.

Step 3: Compiling

An example file to compile:

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.

Command line to compile test.pas:

fpc -Twince -Parm test.pas

You will get a test.exe executable file. Copy it to your Windows CE device and run.

Here is a screenshot of a software created this way.