This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Moderator note: This thread was split from F28M35H52C: Concerto Remote Firmware update options - C2000 microcontrollers forum - C2000™︎ microcontrollers...
Hi Santosh,
While inside my M3 bootloader, i am trying to update the application side MSP value and to do this i am trying something as pointed out below. With this approach the MSP and SP get incremented by 2 bytes than what i am actually loading through register R0.
inline void set_sp (uint32_t app_stack){
asm(" msr msp, r0\n");
}
This increment of 2 bytes intern causes my application code to call FaultISR routine.
What i actually pass to app_stack (r0) = 0x20002358
&
What actually gets passed to MSP = 0x200002360
If i do not try to set the MSP / SP value i can make a comfortable jump to my application from bootloader and everything resumes normal.
Can you please confirm if this is how arm ISA behaves or is there something i am missing.
Thanks
Hi Santosh,
Santosh Athuru said:can you confirm why you are changing stacks? are you trying to use privileged and user mode(s)?
I actually do not require to set my stack pointer value. But i am trying to do so just to have more robust software implementation. Where in i am trying to make sure that i have set the rite value of SP for application program before i make a jump from Bootloader.
But because you brought up the privilaged and user mode option, can you please let me know if there is a single assembly instruction available to toggle between the modes ? If not how can application software toggle the ARM modes ? I believe on reset the ARM will be by default set to privileged mode and user have to explicitly change the mode to user like its done in RTOS rite ? Can you point out what register should i use to change the mode ?
Santosh Athuru said:SP is auto aligned to a word, 4- byte boundary. Can you check if this is what is happening? Also check dis-assembly window, if the inline function is truly inlined or something else is happening and adding a extra PUSH to increment the SP?
Some observations that i made based on your suggestions. Please follow through the below screen shots.
From the above image we can see that at this instance, i am trying to write a value 0x20002358 to my stack and this is what i pass to the register R0 as the argument. I see no problem with inline function.
This is where things gets interesting. As soon as i come out of the inline function i see that the SP value has grow by 2 bytes ??
To add to the confusion, the appentry value itself changes to 0x00000001 ???
But when i not set the SP value the appentry value is 0x0022162B which is my ResetISR value of my application (Verified this from application .map file)!! So the it jumps to this value and my blinky application works happily. (Below screenshot shows the value of appentry when SP is not set)
Santosh Athuru said:Why can't you use a simple MOV SP R0 instruction, if you are not switching modes and are not using different privilege levels?
This is what i used and following behavior is what i have pointed out above.
Thanks