STM32H7 Stack overflow detection using MPU fails on Keil/MDK
Hello,
I'm on a custom H75x board and I want to implement a stack (+ RTOS heap) overflow detection using the MPU.
I placed stack, heap and RTOS heap into DTCM like this:
; ____________________ __ 0x20000000
; | |
; | ^ | -> 0x4000 = 16KB
; | C-Stack / \ |
; | | |
; |_______________|____| __ 0x20004000
; | | |
; | | |
; | \ / C-Heap | -> 0x10000 = 64KB
; | v |
; |____________________| __ 0x20014000
; | | |
; | | |
; | RTOS-Heap \ / | -> 0xC000 = 48kB
; | v |
; |____________________| __ 0x20020000I intend to supervise memory access above and below the DTCM memory via MPU.
For stack overflow test, I call a function which allocates an array in the stack with size > stacksize, e.g.
static void fTest(uint32_t len)
{
int8_t abFill[len];
abFill[0] = (uint8_t)0xCD;
abFill[len-1] = (uint8_t)0xAB;
:
}If I step-debug thru these lines I can see that the SP is outside of stack memory and the array write ends up in a bus fault. If I configure the MPU then the mem fault handler is fired. Seems the MPU is not explicitly necessary for overflow check?
Unfortunately, this is only true for ST/GNU/FreeRTOS.
If I do the same on Keil/MDK/RTX5 no fault handler is triggered. The PC ends up in a code region which doesn't seem related to what I expected.
What's wrong?
Thank you
