Search code examples
stack-overflowcortex-mrtosucos

MSP stack overflow on Cortex-M4 running UCOS-II RTOS


I am using UCOS-II, the underlying operating system for my project. Now, I have encountered a problem that is very difficult for me. I hope someone can give me some advice. I'm running it on a Cortex-M4, and the picture below is what confuses me.

enter image description here

As you can see, I found the top of the MSP stack in SRAM, and I found that 1/2 of the entire MSP stack was covered by EXC_RETURN, which made me confused. Since the amount of my project code is quite large (I discovered this problem during the testing process), I am not very sure which part of the code should be posted. I have almost no modifications to the UCOS-II code, they are all from the official Git storehouse.

It took me a long time to locate this problem. I tried to solve it and read the UCOS-II related assembly code, but I did not solve the problem smoothly.


Solution

  • I've solved this problem! ! ! The reason is that I further call UCOS's PendSV in my own PendSV function, which will result in one more layer of function call stack. When entering my PendSV, the stack will switch to MSP and 0xfffffffd will be pushed into MSP. , which causes the MSP stack to be filled with 0xfffffffd