Arm Community
Site
Search
User
Site
Search
User
Support forums
Arm Development Studio forum
Cortex M3 - How detect stack overflow?
Jump...
Cancel
Locked
Locked
Replies
5 replies
Subscribers
119 subscribers
Views
20290 views
Users
0 members are here
Options
Share
More actions
Cancel
Related
How was your experience today?
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion
Cortex M3 - How detect stack overflow?
Andre Pereira
over 12 years ago
Note: This was originally posted on 12th January 2011 at
http://forums.arm.com
Hi everybody,
I've started developing whit ARM few weeks a go and I have this doubt:
The Cortex-M3 have some hardware detection of stack overflow?
Let me explain:
I've used PIC24 for my last projects, and using as example, the PIC24 have the register "SPLIM" (Stack Pointer Limit) where you write the address of the last byte of your software stack and if your software try to write in more than the address wrote in the SPLIM register, the processor causes a "trap" (a kind of interruption with an dedicated vector).
Using this "trap" you can know if you have any stack overflow.
The ARM Cortex-M3 have something like that?
I've searched in the ARM v7 and the Cortex-M documentation and I just found something about BusFault in stacking but I don't understand very well.
Sorry for my poor english (I'm from Brazil) and thanks in advance.
André Rairan.
Parents
Joseph Yiu
over 12 years ago
Note: This was originally posted on 13th January 2011 at
http://forums.arm.com
Hi,
Technically possible, but the trouble is that usually compiler suite place data in the beginning of SRAM. So in this case you will have to place the data above the initial stack pointer value, which can be messy to setup (depends on tool chain).
Secondly, once you get the bus fault, the stack pointer will be in invalid memory location. So you can't program your bus fault handler or hard fault handler in C as it might try to use stack.
Thirdly, the C compiler might insert stack pointer initialization code in C startup code (before enter main).
So the actual value of stack pointer at the start of the main could be quite different from the initial stack pointer in vector table,
Another thing you need to consider is the amount of stack space the interrupt handlers uses. If the interrupt can be nestes, you need to calculate the worst case stack size required when a number of interrupt nesting occurred.
Do you want the stack overflow detection to be used in debug time or runtime?
For run time maybe you can consider using the MPU (Memory Protection Unit) for this.
regards,
Joseph
Cancel
Vote up
0
Vote down
Cancel
Reply
Joseph Yiu
over 12 years ago
Note: This was originally posted on 13th January 2011 at
http://forums.arm.com
Hi,
Technically possible, but the trouble is that usually compiler suite place data in the beginning of SRAM. So in this case you will have to place the data above the initial stack pointer value, which can be messy to setup (depends on tool chain).
Secondly, once you get the bus fault, the stack pointer will be in invalid memory location. So you can't program your bus fault handler or hard fault handler in C as it might try to use stack.
Thirdly, the C compiler might insert stack pointer initialization code in C startup code (before enter main).
So the actual value of stack pointer at the start of the main could be quite different from the initial stack pointer in vector table,
Another thing you need to consider is the amount of stack space the interrupt handlers uses. If the interrupt can be nestes, you need to calculate the worst case stack size required when a number of interrupt nesting occurred.
Do you want the stack overflow detection to be used in debug time or runtime?
For run time maybe you can consider using the MPU (Memory Protection Unit) for this.
regards,
Joseph
Cancel
Vote up
0
Vote down
Cancel
Children
No data