Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

XMC™ Forum Discussions

gachetp
Level 2
Level 2
10 replies posted 25 sign-ins 10 questions asked

hello, 

I would like to calculate the stack usage of my project so I use this function which is already use in an other porject.

void StackMonitor_Init(void)
{
uint32_t u32StackSize = (uint32_t)&stack_size; // Pointer Address
uint32_t u32StackInit = (uint32_t)(&__stack_start); // Pointer Address
uint32_t *pu32SP = (uint32_t *)__get_MSP(); // Current Main Stack Pointer
pu32SP -= 5; // Make sure I'll not overwrite real data
sp32MaxSP = pu32SP;
while ((uint32_t)pu32SP > (u32StackInit - u32StackSize))
{
*pu32SP = 0xC0C0C0C0U;
pu32SP--;
}
}

I have an handler which appears when I come out of my while.

I don't know to do that.

If someone can help me, it will be very nice.

 

Best regards, 

Pierre Gachet.

0 Likes
1 Solution
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi Pierre,

1. if you have hard fault check registers CFSR, SHCSR, BFAR, MMFAR and from those try to understand what is happening, you can examine also registers that are pushed on stack

2. enable also other fault handlers, this makes easier to detect the cause

3. read following document http://www.keil.com/appnotes/files/apnt209.pdf on how to work with handlers, there are several similar you can find on internet.

 

Best Regards,
Vasanth

View solution in original post

0 Likes
3 Replies
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi Pierre,

Are you telling that your control is going to a hanlder while you are trying to runt the code ? Did you try to identify the handler being triggered and read the registers on the time of failure?

Best Regards,
Vasanth

0 Likes

Hello Vsanth, 

thank you for your reponse. I don't know how to do that. How can I identify the handler, registers on the time of failure ? 

 

Already thank you, 

Pierre 

0 Likes
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi Pierre,

1. if you have hard fault check registers CFSR, SHCSR, BFAR, MMFAR and from those try to understand what is happening, you can examine also registers that are pushed on stack

2. enable also other fault handlers, this makes easier to detect the cause

3. read following document http://www.keil.com/appnotes/files/apnt209.pdf on how to work with handlers, there are several similar you can find on internet.

 

Best Regards,
Vasanth

0 Likes