Embedded/zh CN

From Lazarus wiki
Revision as of 06:36, 21 August 2009 by Kandu (talk | contribs)
Jump to navigationJump to search

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

   对嵌入式target(目标操作系统,目标架构)的支持正在开发中,只支持少数控制器。尽管如此,为嵌入式arm设备做程序还是可行的。嵌入式target没有操作系统,只有几kB的RAM和几十kB的flash。一个典型的target就是NXP公司的LPC家族的流行的设备诸如LPC2124,它拥有16kB的RAM和256kB的flash,使用ARM7的指令集。

嵌入式移植

状态

  • 仅仅在svn上的2.3.1版本才能得到可用的支持
  • 当前仅有arm嵌入式设备得到支持
  • 当前支持的控制器仅限于NXP LPC和ATMEL AT91控制器。如果你有兴趣对其他控制器提供支持,请在这儿捐献你的代码fpc-devel mailing list然后写封信使得我们可以讨论是否加入这个支持。

ARM嵌入式

构建

从svn上获取最新的FPC源码:

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

获取ARM嵌入式binutils。

对于windows,他们可以在 http://svn.freepascal.org/svn/fpcbuild/binaries/i386-win32 得到。你可以checkout所有的目录或者仅仅手工下载arm-embedded-ar.exe,arm-embedded-as.exe,arm-embedded-ld.exe,arm-embedded-strip.exe,arm-embedded-objdump.exe和arm-embedded-objcopy.exe。把这些utils放到被PATH变量包含的目录。

编译FPC对arm-embedded的支持:

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

以上的命令仅仅编译编译器和rtl,因为受限于嵌入式系统的性能编译所有的包是无意义的。不管怎样,要小心不要覆盖了已经存在于系统上的arm编译器。如果这可能发生,INSTALL_PREFIX必须被指定,以使得安装程序被放入另一个文件夹。

Testing

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 (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.

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

 while d<>0 do
   dec(d);

end;


begin

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

end. </delphi>

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

 fpc -Parm -Tembedded -Wplpc2124 tled1.pp
 -Parm

tells the compiler to compile for arm.

 -Tembedded

tells the compiler to compile for the embedded target.

 -Wplpc2124

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