[STM32F1] MDK 怎么查看堆栈使用情况

[复制链接]
12738|12
 楼主| 21ID 发表于 2014-9-9 15:36 | 显示全部楼层 |阅读模式
使用MDK时,怎么查看堆栈的使用情况。比如用了多少,还有多少。
香水城 发表于 2014-9-9 17:46 | 显示全部楼层
预先从RAM中分配的用作STACK的区域是知道的。

那么随时查看堆栈指针SP?
mmuuss586 发表于 2014-9-9 18:43 | 显示全部楼层

这个不知道;
zh113214 发表于 2014-9-9 22:44 | 显示全部楼层
虽然我也不知道,不过还是给你顶一个!!
 楼主| 21ID 发表于 2014-9-10 09:47 | 显示全部楼层
香水城 发表于 2014-9-9 17:46
预先从RAM中分配的用作STACK的区域是知道的。

那么随时查看堆栈指针SP?

谢谢版主!这个我知道,只是这样比较麻烦:)
 楼主| 21ID 发表于 2014-9-10 09:48 | 显示全部楼层
zh113214 发表于 2014-9-9 22:44
虽然我也不知道,不过还是给你顶一个!!

谢谢!
z00 发表于 2014-9-10 13:41 | 显示全部楼层
在MDK的帮助文件中 搜索"Stack use in C and C++" 这篇**里面有介绍 看看是不是想要的
lnhjsdf 发表于 2014-9-10 14:10 | 显示全部楼层
HORSE7812 发表于 2014-9-10 15:19 | 显示全部楼层
 楼主| 21ID 发表于 2014-9-10 16:18 | 显示全部楼层
z00 发表于 2014-9-10 13:41
在MDK的帮助文件中 搜索"Stack use in C and C++" 这篇**里面有介绍 看看是不是想要的 ...

stack.jpg
我没找到
z00 发表于 2014-9-10 21:22 | 显示全部楼层
use is difficult to estimate because it is code dependent, and can vary between runs depending on the code path that the program takes on execution. However, it is possible to manually estimate the extent of stack utilization using the following methods:

Link with --callgraph to produce a static callgraph. This shows information on all functions, including stack use.

Link with --info=stack or --info=summarystack to list the stack usage of all global symbols.

Use the debugger to set a watchpoint on the last available location in the stack and see if the watchpoint is ever hit.

Note
µVision uses ULINK debug adaptors, with the CoreSight interface, which have no performance penalties.

Use the debugger, and:

Allocate space in memory for the stack that is much larger than you expect to require.

Fill the stack space with copies of a known value, for example, 0xDEADDEAD.

Run your application, or a fixed portion of it. Aim to use as much of the stack space as possible in the test run. For example, try to execute the most deeply nested function calls and the worst case path found by the static analysis. Try to generate interrupts where appropriate, so that they are included in the stack trace.

After your application has finished executing, examine the stack space of memory to see how many of the known values have been overwritten. The space has garbage in the used part and the known values in the remainder.

Count the number of garbage values and multiply by sizeof(value), to give their size, in bytes.

The result of the calculation shows how the size of the stack has grown, in bytes.

Use RTSM, and define a region of memory where access is not allowed directly below your stack in memory, with a map file. If the stack overflows into the forbidden region, a data abort occurs, which can be trapped by the debugger.

Methods of reducing stack usage
In general, you can lower the stack requirements of your program by:

writing small functions that only require a small number of variables

avoiding the use of large local structures or arrays

avoiding recursion, for example, by using an alternative algorithm

minimizing the number of variables that are in use at any given time at each point in a function

using C block scope and declaring variables only where they are needed, so overlapping the memory used by distinct scopes.
QQ截图20140910211849.png
fanxsd 发表于 2015-8-10 10:38 | 显示全部楼层
楼主找到好的办法用 MDK 查看堆栈的使用了吗?
sfd123 发表于 2019-3-7 14:23 | 显示全部楼层
楼主找到简单好用的办法了吗?我也想知道啊!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

157

主题

912

帖子

5

粉丝
快速回复 在线客服 返回列表 返回顶部