We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
I am using a STM32F4 series board with Arm Cortex M4 processor to develop a simple scheduler for learning purposes. I have a code snippet where I first set up the stack start location for a task, and then initialize PSP (stack pointer) to its very first location, and then manually fill the stack with some values as follows:
/// Code Start
pTask = (uint32_t *)TASK1_STACK_START; //Stack Start location for Task1
*pTask = (uint32_t) SET_XPSR_FOR_THUMB; //Store the xPSR value in address :TASK1_STACK_START
pTask--; //Decrement
//Code End
In the above code when I execute the very first "pTask--;", I get an IMPRECISERR. However when I modify the sequence as below, the exception went away
//Modified Code Start
*pTask = (uint32_t) SET_XPSR_FOR_THUMB; //Store the xPSR value in address :TASK1_STACK_START - 4
//Modified code end
Although I am aware that the decrement needs to happen before setting a value in Arm Cortex, I was setting the xPSR value first in order to make use of the very first Stack location TASK1_STACK_START. (in the second case, the first stack location TASK1_STACK_START will go unused) Could someone tell me why this is the case ? Is there any internal check in Arm processors whereby decrements are mandated before storing value to a stack location , and throw an exception otherwise ? Thanks
Hello, what type of pointer is pTask? I remember that on ARMv7-M, the stack needs to be aligned (to 2 or 4, if I recall correctly). If the stack pointer (sp) is unaligned, it might cause issues.