移植:IAR cortex-M3 +ucos-III 时遇到的一些问题,归根到底是编译器不是很熟悉,这里记录下....
下载方式:
IAR设置的下载链接方式 与 板子的实际环境不统一,同样报错:"Failed to get CPU status after 4 retries retry?"
我的板子下载接口SWD方式,对应的IAR设置如下:
新建的IAR工程,莫名进入App_Fault_ISR异常处理程序:
之前移植的ucos-III,带着ST的V3.5库,稍微动一些代码,就会进入App_Fault_ISR,然那些代码与内存数据结构并无关系,着实郁闷。。。
多方比对,调试+++,定位到IAR设置问题。最后找到options-Debugger-download这块。
常规设置如下:
试着理解下这几项的含义,跑偏勿怪。。。
Attach to program:
"Makes the debugger attach to a running application at its current location, without resetting or halting (for J-Link only) the target system. To avoid unexpected behavior when using this option, the Debugger>Setup option Run to should be deselected. "
附加到程序:使调试器附加到一个正在运行的应用程序在其当前位置,无需重置或停止(仅供J-Link)目标系统。为了避免意想不到的行为,当使用此选项时,Debugger>Setup option "Run to" 应该去掉。
Verify download:
"Verifies that the downloaded code image can be read back from target memory with the correct contents"
验证下载:验证下载的代码映像可以从目标内存中读取正确的内容
Suppress download:
"Disables the downloading of code, while preserving the present content of the flash. This command is useful if you want to debug an application that already resides in target memory.
If this option is combined with the Verify download option, the debugger will read back the code image from non-volatile memory and verify that it is identical to the debugged application.
Note: It is important that the image that resides in target memory is linked consistently with how you use C-SPY for debugging. This applies, for example, if you first link your application using an output format without debug information, such as Intel-hex, and then load the application separately from C-SPY. If you then use C-SPY only for debugging without downloading, you cannot build the debugged application with any of the options Semihosted or IAR breakpoint—on the General Options>Library Configuration page—as that would add extra code, resulting in two different code images."
抑制下载:禁用下载代码,同时保留目前的flash内容。这个命令是有用的,如果您想要调试一个应用程序,该应用程序已经在目标内存驻留。
如果这个选项结合验证下载选项,调试器会读回代码映像从非易失性内存,并验证它是与被调试的应用程序相同。
注意:It is important that the image that resides in target memory is linked consistently with how you use C-SPY for debugging.
例如,如果你第一次联系您的应用程序使用一个没有调试信息输出格式,如Intel-hex,,则 C-SPY与加载应用程序分开的。
如果你然后使用C-SPY只有调试没有下载,你不能用任何构建调试应用程序关于Semihosted选项或IAR断点,在the General Options>Library Configuration 页,添加额外的代码,从而导致两种不同的图片代码。
Use flash loader(s) :
"Use this option to use one or several flash loaders for downloading your application to flash memory. If a flash loader is available for the selected chip, it is used by default. Press the Edit button to display the Flash Loader Overview dialog box."
使用flash加载程序:使用这个选项使用一个或多个闪存flash应用程序加载器下载。如果一个flash加载程序可供选择的芯片,在默认情况下使用它。按下编辑按钮对话框显示Flash加载程序概述。
关于IAR的设置,推荐关键字--”IAR EWARM项目选项常用设置“
关于'CSTACK':(stack)栈指针
IAR中debug程序,断点位置会提示:"Tue Dec 15, 2015 14:06:55: The stack pointer for stack 'CSTACK' (currently 0x2000161C) is outside the stack range (0x20002878 to 0x20003078) " ,这很正常。
网友给出的解释:
应用程序启动时要有一个堆栈,不管是裸机,还是基于uCOS,,那就是CSTACK堆栈uCOS-III运行起来后,每个任务有自己的堆栈,所以,当任务运行的时候,IAR编译器会识别到堆栈指针不在CSTACK之内,所以会报The stack pointer for stack 'CSTACK' (currently 0x20007A1C) is outside the stack range (0x20008B88 to 0x20009B88) 这个不是问题,是正常的,,当然,uCOS-III官方移植中,中断堆栈也是独立的,专门用于处理中断,这个好处就是:每个任务堆栈不必考虑中断嵌套层数,从而不用为中断嵌套增加堆栈大小。所以执行中断程序时,也会报The stack pointer for stack 'CSTACK' (currently 0x20007A1C) is outside the stack range (0x20008B88 to 0x20009B88) CSTACK只是在系统启动时使用,之后就没用了,所以可以配置的小一点,以免造成太大的浪费。