ARM Cortex M0 -> checking stack overflow

Asked by Dejan Rebraca

Hello,

are there some mechanisms to check stack overflow during runtime?
I tried to add -mapcs-stack-check options but I have compile warnings:
-mapcs-stack-check incompatible with -mno-apcs-frame [enabled by default]

I tried to add the option -mapcs-frame, but still have the same warning messages.

Could you please give me some hints or point me to some other way to check stack overflow in runtime?

Tnx,
Dejan

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Frank Pilhofer (fpnonce2010) said :
#1

Dejan,

my solution is to place the stack at the beginning of RAM. I am using an STM32F0, where RAM starts at 0x2000.0000. So I use the linker script to place the stack at 0x2000.0000 to 0x2000.0200. The initial stack pointer which goes in the vector table is set to the end of the stack. The nice thing is that I now get a hard fault as soon as the stack overflows, which makes it easy to diagnose.

This only works in a bare-bones setup, though. If you have an RTOS where each task has its own stack, you need a task switch handler to check the integrity of each stack.

Frank

Revision history for this message
Dejan Rebraca (d-rebraca) said :
#2

Hi Frank,

Actually that's not so bad idea, will consider it. The only problem here could be that the beginning of RAM is reserved by part of the code where we don't even have the source, we got it in form of library.

Tnx,
Dejan

Revision history for this message
Joey Ye (jinyun-ye) said :
#3

Dejan,

Catching stack overflow without OS support is hard. -mapcs-stack-check is not the solution you are seeking. It only work above an OS, and it also need all runtime libraries built with -mapcs-frame.

Besides Frank's solution, another approach is have a sys_tick handler to check SP value periodically, which might happen to catch the overflow.

- Joey

Can you help with this problem?

Provide an answer of your own, or ask Dejan Rebraca for more information if necessary.

To post a message you must log in.