I am trying to back trace and get the call of faulty application after getting an exception, in this i need to update SP from HardFault Handler.
I tried in many way like "MOV SP, Rn" , "MSR SP, Rn" and etc but finally ended up with either Compilation error or Lockup state after execution of this instruction.
Already I've updated PSP from Handler, but i need to change SP to get called stack frames.
Please help me to do this.
Could you show the code fragment, and tell us what is the error message?
(and which tool chain you are using?)
Below is my code fragment:
__asm(" LDR R0, StackConst \n" " StackConst: .word Stack \n"); __asm(" LDR R0, [R0] \n"); __asm(" MOV R2, #20 \n"); __asm(" LDR R4, [R0, R2] \n"); //get LR __asm(" MOV LR, R4 \n"); //set LR __asm(" ADD R2, R2, #4 \n"); __asm(" LDR R5, [R0, R2] \n"); //get PC __asm(" ADD R0, R0, #0x20 \n"); __asm(" movs r1, #2 \n" /* r1 = 2. */ " msr CONTROL, r1 \n"); /* Switch to use PSP in the thread mode. */ __asm(" MSR PSP, R0 \n"); //set PSP //__asm(" MOV SP, R0 \n"); //set SP __asm(" MOV PC, R5 \n"); //set PC after exception __asm(" BKPT #04 \n");
When Enable the Bold line instruction CPU is going in Lockup state error "0xEFFFFFFA : Failed to read 4 bytes from address 0xEFFFFE6E"
when replace the Bold line instruction with __asm(" MSR SP, R0 \n"); //set SP getting compilation error error: invalid operand for instruction
can i do like this, isn't it invalid?
There are some restrictions about inline assembler. The following link is for Arm compiler 5 (I can't find equivalent link for AC6 so I am not sure if it is identical).
You might need to separate the assembly part as an assembly file.
I tried with separate assembly file for that, but still same error.
am i missing something else to get it work?
Could you post the assembly file and tell us which version of tool you are using? thanks
Running on AC6 for ARM CM33
Please find attachment.
I don't see any error message when assembling your file.
armasm --cpu Cortex-M33 -g startup_IOTKit_CM33.s -o startup_IOTKit_CM33.o
(I am using Arm Compiler 6.12 on Linux).
Right now i have commented the faulty instruction(line no 254) which gets compiled but not able to execute this.
If i replace with this "MSR SP, R0 " then i get compile error.
My main intention to move the R0 into SP registers.
I added line 254 back and it still assembled fine, no error message.
> armasm --cpu Cortex-M33 -g startup_IOTKit_CM33.s -o startup_IOTKit_CM33.o --list=startup_IOTKit_CM33.lst
241 0000000E BackTrace_CallStack PROC 242 0000000E EXPORT BackTrace_CallStack 243 0000000E IMPORT FaultedStack 244 0000000E 4810 LDR R0, =FaultedStack 245 00000010 6800 LDR R0, [R0] 246 00000012 F04F 0214 MOV R2, #20 247 00000016 5884 LDR R4, [R0, R2] ;get LR 248 00000018 46A6 MOV LR, R4 ;set LR 249 0000001A F102 0204 ADD R2, R2, #4 250 0000001E 5885 LDR R5, [R0, R2] ;get PC 251 00000020 F100 0020 ADD R0, R0, #0x20 252 00000024 F380 8809 MSR PSP, R0 ;set PSP 253 00000028 BE00 BKPT #0 254 0000002A 4685 MOV SP, R0 ;set SP 255 0000002C 46AF MOV PC, R5 ;set PC after excep tion
Can you tell me which version of armasm you are using?
$> armasm --version_number
and the exact command line you use when you see the error?
$> armasm --version_number↵
I don't get any error with "254 0000002A 4685 MOV SP, R0 ;set SP" but it fails to move R0 into SP while execution.
replacing line no 254 with "MSR SP, R0" gives error,
with this way i want to move R0 into SP register, is it right?
For MSR instruction, you need to use either MSP / PSP / MSP_NS / PSP_NS.
Since the processor is in Handler mode (using MSP), you could write it as
MSR MSP, r0
Thanks a lot.
View all questions in Cortex-M / M-Profile forum