This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can i change SP at run time in CM33?

Dear All.

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.

Regards,

Deepak

Parents Reply Children
  • 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.

    6165.startup_IOTKit_CM33.s.zip

    thanks,

    Deepak

  • Thanks Deepak.

    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.

    thanks,

    Deepak

  • 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↵

    6120001

    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?

  • Hi Deepak,

    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

    regards,

    Joseph