iar对堆栈管理的比较好,但是有时也会出问题。
iar 提供了很多功能,帮助我们分析 系统使用堆栈的情况。
--call_grahp 这个参数启用后会输出函数使用栈的信息,
原型:
--call_graph
Syntax: --call_graph {filename | directory}
Description: Use this option to produce a call graph file. If no filename extension is specified, the
extension cgx is used. This option can only be used once on the command line.
Using this option enables stack usage analysis in the linker.
首先设置root 目录,在函数前面添加一个参数:
#pragma call_graph_root="main"
void main (void)
{
…………
}
如果包含函数指针,那么需要指定,该指针可能会指向的函数:
{
#pragma calls =App_TaskStart
(void)ptcb;
……
}
编译链接之后,在文件中会输出信息:
<function>
<id>85</id>
<name>main</name>
<root>main</root>
<address>0x200261e0</address>
<stack>24</stack>
<callee>81</callee>
<callee>252</callee>
<callee>256</callee>
<call>
<callee>318</callee>
<arg>
<index>0</index>
<function>84</function>
</arg>
</call>
</function>
<function>
<id>85</id>
<name>main</name>
<address>0x200261e0</address>
<stack>24</stack>
<callee>81</callee>
<callee>252</callee>
<callee>256</callee>
<call>
<callee>318</callee>
<arg>
<index>0</index>
<function>84</function>
</arg>
</call>
</function>
<function>
<id>210</id>
<name>__iar_program_start</name>
<root>Program entry</root>
<address>0x20000000</address>
</function>
<function>
<id>742</id>
<name>__iar_return_from_swi</name>
<root>software interrupt</root>
<address>0x2002ba54</address>
<stack>0</stack>
</function>
启用之后,同时可以在map文件中会有一些信息
*******************************************************************************
*** STACK USAGE
***
Call Graph Root Category Max Use Total Use
------------------------ ------- ---------
main 176 176
Program entry 0 0
Uncalled function 4 584 16 320
在连接脚本中,通过这个命令可以检查是否有溢出:
Error[Lp034]: no stack usage could be calculated for at least one function in category "main"
但是总是有个错误:
Error[Lp034]: no stack usage could be calculated for at least one function in category "main"
不知道为什么。