Stack usage (CWS-H12-PRO v. 4.5)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Stack usage (CWS-H12-PRO v. 4.5)

跳至解决方案
3,143 次查看
Sten
Contributor IV
Am I missing something, or does not the CW compiler/linker inform you about the stack usage. I am also using a Cosmic compiler for the HC08-family, and it has a very convenient stack usage map in the linker's MAP-file that tells you the total stack needed for all entry points (main() and ISRs), and from that is is easy to define the stack size. I have found the -Ll option in CW and had a look at the generated logfile.txt, but to, from that, manually calculate the total stack usage for a not so small project, would be very difficult.
 
One way to determine the stack usage would of course be to examine the stack content with the debugger after the application has run for a while, but that is not a very scientific way of doing it and does not guarantee that the worst case was found.
 
Any ideas, anybody?
 
Sten
 
标签 (1)
标记 (1)
0 项奖励
1 解答
746 次查看
CrasyCat
Specialist III

Hello

This is not working in the current version of the tools, but has been recorded as a feature request for future release of the tools.

CrasyCat

在原帖中查看解决方案

0 项奖励
3 回复数
747 次查看
CrasyCat
Specialist III

Hello

This is not working in the current version of the tools, but has been recorded as a feature request for future release of the tools.

CrasyCat

0 项奖励
746 次查看
Technoman64
Contributor III
I tested the following code using the simulator for a HCS12DJ256. Not sure if this is what you are looking for though. Should be able to create a test project and paste this code into main.c
 
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dj256.h>     /* derivative information */

#pragma LINK_INFO DERIVATIVE "mc9s12dj256b"
 
/* Define to turn on stack checking */
#define DEBUG_STACK
 
/* Macro to calculate amount of stack used */
#define STACK_CHECK asm PSHX; asm TSX; asm STX StackPtr; asm PULX;\
  StackUsed = StackStart - StackPtr /*; asm BGND */

/* Macro to save stack start */
#define STACK_START asm PSHX; asm TSX; asm STX StackStart; asm PULX
 
/* Variables for stack checking only asllocated if DEBUG_STACK is defined */
#ifdef DEBUG_STACK
unsigned int StackPtr = 0;
unsigned int StackStart = 0;
unsigned int StackUsed = 0;        
#endif
 
/* Just some variables */
int i;
int Array[100];
 
/* Just a function for testing stack usage */
void Function1(void){
 int Array2[10];
 
 /* If we are stack checking do it here */
 #ifdef DEBUG_STACK
  STACK_CHECK;
 #endif
 
 /* Do something */
 for(i=0; i<10; i++){
  Array[i] = i;
 }
 
 /* Use local array so compiler does not optimize it out */
 Array2[0] = Array[5];
}
 
/* Main function */
void main(void) {
 
   /* Get stack starting position */
 #ifdef DEBUG_STACK
  STACK_START;
 #endif
 
 /* Call test function */
 Function1();
 
 for(;:smileywink: {} /* wait forever */
}
746 次查看
Sten
Contributor IV

Thanks CrasyCat and Technoman,

while waiting for the feature to be included in the tools, I will use the idea with inline stack checking to collect the deepest stack during runtime.

Sten

0 项奖励