TARGET Embedded

From Lazarus wiki
Revision as of 22:43, 27 June 2009 by FPK (talk | contribs) (Adding new controllers)

English (en) español (es) 中文(中国大陆)‎ (zh_CN) 中文(台灣)‎ (zh_TW)

The embedded target is still under development and only a few controllers are supported. Nevertheless, it's possible to create programs for embedded arm devices. The embedded target targets systems without any operating system and typically several kBs of RAM and several dozens of kB of flash. A typical target is the LPC family of NXP with popular members like the LPC2124 with 16 kB RAM and 256 kB flash using the ARM7 instruction set.

Embedded port


  • useful support is only available in 2.3.1 from svn
  • currently only arm-embedded is supported
  • supported controllers are limited to NXP LPC controllers

ARM Embedded


Get latest FPC from svn:

 svn co fpc

Get arm-embedded binutils.

For windows, they are available at You can either checkout the whole directory with or download only arm-embedded-ar.exe, arm-embedded-as.exe, arm-embedded-ld.exe, arm-embedded-strip.exe, arm-embedded-objdump.exe and arm-embedded-objcopy.exe manually. Put these utils in a directory included in your path.

Build FPC for arm-embedded:

 cd fpc
 make clean buildbase installbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=arm

This builds only the compiler and the rtl instead of the whole FPC. Because of the limited capabilities of the embedded systems supposed to be used, building all packages is not usefull. However, one must be carefull to avoid overwriting an existing arm compiler on the system. If this is the case, INSTALL_PREFIX should be used to install into a different directory and switch between those.


Below you find a simple example program, save it as tled1.pp to follow the description. The program is made for development boards like the LPC-WEB from OLIMEX ( When you press button 1, led 1 lights for a certain time, same for button 2 and led 2.

<delphi> procedure Wait(d : dword); begin

 while d<>0 do



 { initialize PLL }
 { initialize LEDs }
 { port 0.8: output }
 { port 0.10: output }
 { turn off both LEDs }
 { initialize button inputs }
 { port 0.9: input }
 { port 0.15: input }
 { endless loop}
 while true do
     { button 1 pressed }
     if TBitvector32(GPIO0_IOPIN)[15]=0 then
         { turn on LED, inverse logic }
         { wait }
         {  turn off LED, inverse logic }
     { button 2 pressed }
     if TBitvector32(GPIO0_IOPIN)[9]=0 then
         { turn on LED, inverse logic }
         { wait }
         { turn off LED, inverse logic }

end. </delphi>

If FPC for arm-embedded is installed as described above, the program can be compiled by

 fpc -Parm -Tembedded -Wplpc2124 tled1.pp

tells the compiler to compile for arm.


tells the compiler to compile for the embedded target.


tells the compiler to compile for the NXP LPC 2124. This has two effects: first, a unit (lpc21x4 in this case) containing the startup code and the port etc. definitions for this controller is loaded. Further, the compiler uses a linker script which fits the needs of this controller.

The result of the compiler is a .hex file which can be programmed by the NXP flash programming utility.

Adding new controllers

Adding a new controller type requires basically three steps: first, extend the compiler so it knows about the name of the controller then add a linker script and finally create an rtl unit with the register definitions and the startup code.

Add the controller type to the compiler

Add the linker script to the compiler

Create an rtl unit with startup code and register definitions

Useful links