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

Flags of APSR Register in Cortex M3

Note: This was originally posted on 19th April 2011 at http://forums.arm.com

Hello all,
I am having probelm in writing Flags of APSR Register in Cortex M3. The result of a comparison cuases the negative flag to get set to 1. Next instruction reads the APSR using MRS instruction. Before executing this instruction I clear the negative flag to 0. If I execute the instruction of reading the APSR after clearing the negative flag, program jumps to hardfault handler. Reference manual states that these flags are writable.
We can write APSR using MSR instruction too. But is it possible to change a single bit(Flag) as I have mentioned above?
Thanks in advance
  • Note: This was originally posted on 21st April 2011 at http://forums.arm.com

    How do you clear the APSR? By a debugger?
    Yes I do so using Debugger. I am using IAR Tool chain and here I have possibility to view all registers including APSR and writable bits can be changed to 0 or 1. There is another T bit in EPSR register which defines ARM mode when written to 0 and for Thumb mode it has to be written to 1. I am not touching this bit at all. All I do it to chnage the state of flag in APSR from 1 to 0 and vice versa. the program hits hardfault exception for all flags no matter the flag is changed from 0 to 1 or 1 to 0.
  • Note: This was originally posted on 20th April 2011 at http://forums.arm.com

    How do you clear the APSR? By a debugger?

    If you write 0 to the xPSR using a debugger (only a guess), you might have accidentally cleared the T bit (Thumb state). This cause a fault exception when you step into the next instruction as it means you are trying to execute an ARM instruction.

    regards,
    Joseph
  • Note: This was originally posted on 22nd April 2011 at http://forums.arm.com

    Hi,

    I have tested this using Keil MDK with ULINK2 with Cortex-M3 r2p0 but didn't get any problem.
    I used a simple test
    __asm void test_1(void)
    {
       MOVS  R0, #0     ; Breakpoint set here, then single step through
       MOVS  R1, #
       SUBS  R0, R0, R1  ; Set N flag, then use MDK uVision debug to clear N bit to 0
       MRS   R0, APSR
       BX   LR
    }
    It might worth checking the value of xPSR before and after the change to see if the debugger change other bits.
    Also, when it enter hard fault, please check the values of various fault staus registers.

    It might also worth email IAR to see if they are aware of any known problem which might affect this.

    I am away next week so won't be able to check the forum until May.

    regards,
    Joseph