ARM下Keil转到Eclipse后的几个问题
Keil转战到Eclipse下,
首先,Eclipse的交叉工具链的环境要进行设置;
其次,在Keil中的Scatter file在Eclipse下要重新编写;
最后,Eclipse的调试环境要进行配置。
Eclipse的环境搭建可参考:
http://wenku.baidu.com/link?url=LFu2GDqSIvpvs-8eC4Lb3Z3Js2zB03W4ou81uRTYmc-t2RHMWN_Hmvq0XGQKeKVpD_l3aroqK7w0GC-bRA65sKjouPiXpFUmzEcbNhsqiyq
基于Eclipse的嵌入式ARM开发环境建立
问题1,关于中断
Keil中的中断函数申请如下:
void __irq FunctionName(void)
就是函数带一个__irq的前缀。
如果此函数在Eclipse下编译,error: expected '=', ',', ';', 'asm' or '__attribute__'before 'FunctionName
那么在Eclispe中怎么申请一个中断(或者中快速中断)函数呢?
参考网址:
http://velep.com/archives/1014.html三星6410裸机程序开发4:eclipse中实现6410中断功能
http://blog.csdn.net/jjjzmj1987/article/details/5091525关于 中断函数申明 static void Dma0Done() __attribute__((interrupt("IRQ")));
示例:
void FunctionName(void) __attribute__ ((interrupt("IRQ")));
void FunctionName (void)
{
//do something
}
Note: 除了可以使用IRQ中断方式之外,还可以写FIQ,SWI,ABORT,UNDEF的中断处理函数。
但在Eclipse内编译时却出现了:
error:interrupt Service Routines cannot be coded in Thumb mode
在Eclipse的C/C++ Build->Setting里将Instruction Set Thumb (-mthumb)改为ARM (-marm)或者Toolchain default,Thumb interwork (-mthumb-interwork)勾选上,重新编译。如下图:
上面选项是什么意思,可参考:http://blog.csdn.net/armeasy/article/details/6250969
-mthumb
Generate code for the Thumb instructionset. The default is to use the 32-bit ARM instruction set. This optionautomatically enables either 16-bit Thumb-1 or mixed 16/32-bit Thumb-2instructions based on the -mcpu=name and -march=name options. This option is notpassed to the assembler. If you want to force assembler files to be interpretedas Thumb code, either add a `.thumb' directive to the source or pass the-mthumb option directly to the assembler by prefixing it with -Wa.
-mthumb-interwork
Generate code which supports callingbetween the ARM and Thumb instruction sets. Without this option the twoinstruction sets cannot be reliably used inside one program. The default is-mno-thumb-interwork, since slightly larger code is generated when-mthumb-interwork is specified.
问题2,关于程序入口参数
以前用ARM的IDE工具,使用的是ARM标准的汇编语言。现在要使用GNU的工具,当然要了解一点GNU ARM汇编的不同之处。
Keil的程序,在Eclipse重新建立工程后,编译通过,链接时出现一个警告:
ld.exe:warning: cannot find entry symbol _start; defaulting to 00008018
不能找到_start入口。
在Keil下,程序的入口指定为
__ENTRY
[CODE].section<.section_name> {,”<flags>”}
开始一个新的代码或数据段。
.text, 代码段;.data, 初始化数据段;.bss, 未初始化数据段。
这些段都有缺省的标志(flags)联接器可以识别这些标志。(与armasm中的AREA相同)
下面是ELF格式允许的段标志
标志
含义
a 允许段
w 可写段
x 执行段
问题3,文件后缀
.c文件后缀必须是小写c,如果改成大写C,将会导致此文件不编译。
汇编文件的结尾貌似必须是大写S。
问题4,sbrkr.c:(.text+0x18): undefined reference to ‘_sbrk’
根据网址:https://forum.sparkfun.com/viewtopic.php?t=5390&start=15
运行类似的命令:arm-elf-ar -d libc.asyscalls.o,将syscalls从libc.a中剥离。
在项目中添加syscalls.c文件,还没有写DebugWrite原型,编译就通过了。
可能的原因是因为我调用了sprintf之类的库函数,导致在底层调用时没有找到相应的链接函数,这部分链接函数可以自己实现。
但是我现在采用的是直接重新实现sprintf函数,因为目前我还只用到了sprintf函数。可以调试,还要看看有没有什么问题。
@2015-03-14
今天Lwip部分移植上。编译出现了这个。
d:/program/arm_cross/arm-2013.11-24-v4-8-1/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib\libc.a(lib_a-sbrkr.o):In function `_sbrk_r':
sbrkr.c:(.text+0x18):undefined reference to `_sbrk'
d:/program/arm_cross/arm-2013.11-24-v4-8-1/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib\libc.a(lib_a-signalr.o):In function `_kill_r':
signalr.c:(.text+0x1c): undefined reference to `_kill'
d:/program/arm_cross/arm-2013.11-24-v4-8-1/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib\libc.a(lib_a-signalr.o):In function `_getpid_r':
signalr.c:(.text+0x44):undefined reference to `_getpid'
d:/program/arm_cross/arm-2013.11-24-v4-8-1/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib\libc.a(lib_a-writer.o):In function `_write_r':
writer.c:(.text+0x20):undefined reference to `_write'
d:/program/arm_cross/arm-2013.11-24-v4-8-1/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib\libc.a(lib_a-closer.o):In function `_close_r':
closer.c:(.text+0x18):undefined reference to `_close'
d:/program/arm_cross/arm-2013.11-24-v4-8-1/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib\libc.a(lib_a-fstatr.o):In function `_fstat_r':
fstatr.c:(.text+0x1c): undefined reference to `_fstat'
d:/program/arm_cross/arm-2013.11-24-v4-8-1/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib\libc.a(lib_a-isattyr.o):In function `_isatty_r':
isattyr.c:(.text+0x18):undefined reference to `_isatty'
d:/program/arm_cross/arm-2013.11-24-v4-8-1/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib\libc.a(lib_a-lseekr.o):In function `_lseek_r':
lseekr.c:(.text+0x20):undefined reference to `_lseek'
d:/program/arm_cross/arm-2013.11-24-v4-8-1/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib\libc.a(lib_a-readr.o):In function `_read_r':
readr.c:(.text+0x20):undefined reference to `_read'
collect2.exe: error: ld returned 1 exit status
这是由于在用arm-none-eabi工具进行编译时,没有newlib库导致的。之前解决了关于这个库的一下小问题,当时是采用了printf和sprintf之类的函数,最后解决方法是自己在底层实现了sprintf函数。但这次报的太多了,因此想将newlib移植过来。newlib里面就是一些常用的系统库函数。
如果是在linux下编译,linux本身就带glibc库,可能就不会出现这个问题了。
从这个网址上ftp://sourceware.org/pub/newlib/index.html下载了newlib2013-12-23: newlib-2.1.0.tar.gz(16.2MB)。之所以没有下载最新的是因为,最新的那几次版本太频繁了,怕不稳定。这个应该就够了。
在configure,make all时,过程中出现了不少问题,configure的参数不一样有时候也导致编译不过。make install有时虽然成功了,仍然报这些错。可能是configure时的参数不对。看到网上说,其实并不是所有的newlib内的函数你都需要,如果移植成功,可能你编译出来的目标文件比较大。再加上newlib不好移植,于是有转战实现syscalls.c文件。参考了:
https://balau82.wordpress.com/2010/12/16/using-newlib-in-arm-bare-metal-programs/
http://contiki.sourceforge.net/docs/2.6/a00523_source.html
在里面的一些函数实现过程中调用了其他的函数,其他的函数暂时还没有实现。不过网址http://contiki.sourceforge.net/docs/2.6/a00523_source.html上关于其他的函数也有实现。所以可以参考看看是怎么实现的。
在网址http://www.embecosm.com/appnotes/ean9/ean9-howto-newlib-1.0.html的5.3. Standard System Call Implementations中也有介绍怎么实现这些函数,文中说这是一种最简单的方法,供参考。
问题5调试执行mrc p15,0,r0,c1,c0,0,跑飞
在调试时,运行到执行协处理器命令时程序异常,程序跳转到0x00000004地址出,即未定义指令异常。最终发现问题在于工程选项中Thumb和ARM指令的设置上。在自己的工程中找到设置Thumb和ARM指令的地方,选择尝试。