2014-03-17 04:28 AM
AREA StackSwitch, CODE, READONLY
IMPORT PrintHex
EXPORT Start
EXPORT Reset_Handler
stack_base DCD 0x28000
THUMB
PRESERVE8
ENTRY
Reset_Handler
Start
MOV r0, &sharp0xf00d
PUSH {r0}
MOV r0, &sharp0
BL Mode_Switch
POP {r0}
BL PrintHex ; TASK 1: Fix the program so that this prints 0xf00d
; ** by only making changes inside Mode_Switch
; and ensuring that you are still in process
; mode when you
; get here ** B Finish
Mode_Switch
MOV r0, &sharp0x2 ; set stack to PSP
MSR CONTROL, r0 ; do it
ISB ; wait for it to be done
BX lr ; and return safely
; ================
; End your program
; ================
Finish
B Finish
END ; Mark end of file
Hi, I'm currently learning how to use the ARM STM32F4 Discovery board and I've come across a problem I'm not sure how to solve. The code above doesn't actually do what is expected since we switch stacks and then POP r0 (from the wrong stack) which isn't what we want.
I cannot switch back to the stack like in MODE_SWITCH and I don't want to copy the value into a register before I make the switch to the other stack. How do I use MSR or MRS (presuming I am in privileged mode at this point) to get r0 from the other register so I can pop the correct value?
I've spent a while looking through the documentation and experimenting but I can't seem to get it work.
thanks!
#discovery #stm32f42014-03-17 06:36 AM
You could save R0/R1, store the SP in R1, and the use R1 to recover the original R0/R1 before returning.
Or pop and push the top value in the subroutine.2014-03-17 01:52 PM
Thanks for your reply Clive but I'm afraid I still don't quite understand what you are suggestion. Assume any code that I add will be in the MODE_SWITCH subroutine. I am specifically trying to learn how to use the MSR/MRS operations.
Apologies for the simple questions but you have to start somewhere!Much appreciated.2014-03-17 02:53 PM
Mode_Switch
POP {r1}
MOV r0, #0x2 ; set stack to PSP
MSR CONTROL, r0 ; do it
ISB ; wait for it to be done
PUSH {r1}
BX lr ; and return safely
2014-03-21 09:33 AM
I'm afraid the purpose of this task is for me to try and get to grips with the MSR and MRS instructions, my solution should involve those instructions. Does anyone have any experience with this? Feel free to point me towards any resources you have found useful for me to research.
Regards2014-03-21 10:19 AM
My code uses MSR, and performs the stated task
; TASK 1: Fix the program so that this prints 0xf00d
; ** by only making changes inside Mode_Switch
; and ensuring that you are still in process
; mode when you
; get here **
I can see another clever way of doing this too.
Perhaps the secondary task is to use MRS, and to print out the content of the CONTROL register, or a message, that addresses the latter clause and ensuring, or proving, that was in the Process Mode, using the PSP
2014-03-22 10:07 AM
Thanks for your help Clive, I've figured it out - much appreciated.