C언어 > freepascal - TARGET Embedded

TODAY852 TOTAL2,918,743
사이트 이용안내
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선

BASIC4MCU | C언어 | 델파이 | freepascal - TARGET Embedded

페이지 정보

작성자 master 작성일2018-09-29 13:33 조회1,992회 댓글0건


TARGET Embedded


Embedded port


  • best support is available in svn trunk version
  • compilers are working, register definitions are available, but libs for peripheral's access are rare to non-existing. Hardware can be accessed via hardware registers.
  • Not all controllers of each family are supported. If you're interested in support for further controllers, please subscribe to the fpc-devel mailing list and write a mail so adding the support can be discussed

ARM Embedded


Get latest FPC from svn:

svn co http://svn.freepascal.org/svn/fpc/trunk fpc

Get arm-embedded binutils.

For windows, they are available at http://svn.freepascal.org/svn/fpcbuild/binaries/i386-win32. 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.

To build binutils from sources http://wiki.lazarus.freepascal.org/Binutils has instructions, for example, ./configure --target=arm-linux --prefix=/opt/embarm/ --program-prefix=arm-embedded- --disable-werror, has been known to work on binutils 2.21.1 to build the binaries in the form that the fpc target embedded build desires.

Build FPC for arm-embedded (OABI):

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

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 useful. However, one must be careful 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.

SUBARCH is required and should match your target processor, e.g.:

  • for the LPC 21xx parts which are ARM7TDMI (not to be confused with armv7!) based use SUBARCH=armv4
  • for cortex-m3 parts (stellaris, stm32, etc) use SUBARCH=armv7m
  • for cortex-m devices that support DSP extensions use SUBARCH=armv7em. The compiler does not yet support the cortex-m* FPU
  • for cortex-m0 devices use -Cparmv6m


Below you find a simple example program for the LPC2124 microcontroller, save it as tled1.pp to follow the description. The program is made for development boards like the LPC-WEB from OLIMEX (http://www.olimex.com/dev/lpc-e2124.html). When you press button 1, led 1 lights for a certain time, same for button 2 and led 2.

procedure Wait(d : dword);
  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 }

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.

When using a board like the mbed (http://mbed.org) which is cortex-m3 based. Another ARM core but uses only thumb/thumb2 instructions not ARM/thumb instructions. A few subtle differences, first building fpc

make clean buildbase installbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=arm SUBARCH=armv7m

Second when compiling your program

fpc -Parm -Tembedded -Wplpc1768 -Cparmv7m myprogram.pp

The -Cparmv7m option causes thumb2 code to be generated instead of the default (ARM based), probably not a bad idea to use the -Cp for processors using ARM instructions as well. -Wp as with the example above specifies the specific target, in this case microcontroller, to build for.

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

This is done in the file compiler/arm/cpuinfo.pas Here you need to add an identifier for the controller in the tcontrollertype enum At the same time you must update the embedded_controllers array. The array holds information about the amount of flash and sram in the controller, and what rtl unit should be included by default when compiling for that controller.

Note: Make sure the string of the two arrays are long enough to contain the strings you write

Add the linker script to the compiler

Adding a linker script consists of adding the controllertype enum identifier to the case statement in compiler/systems/t_embed.pas If this is not done the compiler will generate an internalerror

Create an RTL unit with startup code and register definitions

Creating an RTL unit means creating a unit that'll automatically be used in a project compiled for the given controller type. This unit should supply an entry point and basic initialization code. Enough to get the controller running

This unit, which must be named the same as the string written in the controllerunitstr field in the embedded_controllers array, goes into the directory rtl/embedded/arm/ where there are some examples already

After that the rtl/embedded Makefile.fpc should be modified, and rebuilt so it also builds the newly added rtl unit


See wiki page AVR.


See wiki page TARGET Embedded Mipsel.

Useful links

See Also








댓글 0

조회수 1,992

등록된 댓글이 없습니다.

C언어HOME > C언어 > 전체 목록

게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020