Hi,
I'm using the STM32 F407 (Cortex M4), and I am also only using assembly in uVision IDE. So far I have managed to setup a ISR for a pushbutton generated interrupt via GPIO. This all works, I get the ISR handler hit, but after I perform my ISR function how do I return back to thread mode, and set the PC back to last point of execution ?
I have tried doing a straightforward BX LR like the ARM wiki states, (LR is currently set to 0xFFFF FFF9 which is the exception return set by the CPU), I thought when the CPU saw I was trying to set PC to this it would auto handle the transition back to thread, but it goes straight to hard fault handler. Then I tried manually popping off r0,r4 and then pop PC, to set the PC directly to the 5th item on the stack (only main stack is used), this was the previous execution address, but I'm not sure how to change back to thread from handler mode.
So my question is does the CPU handle switching execution back to thread after handler, or do I have to manually unwind the stack, set the PC correctly and change mode back to thread ?
Thanks.
On Cortex-M, there is no special handling needed. Just return and the core will do what is needed.Make sure to set both psp and msp!
Hi Thanks for the answer, it seems my stack alignment was wrong and this was causing my return straight to hard fault. Control now lands back to thread mode and all it took was a simple BX LR. Now though I seem to be getting the same interrupt firing repeatedly, here is my ISR :
EXTI0_IRQHandler PROC ldr r0,[r11,#0x14+PORTD] ; R0 < @GPIOD_ODR eor r0,r0, #BluLed ; R0 = Toggle Blue Led str r0,[r11,#0x14+PORTD] ; R0 > @GPIOD_ODR ldr r0, =0xE000E280 ;=NVIC_ICPR0 ; clear pending interrupt from EXTI0_IRQn channel ldr r1, =0x40 str r1, [r0] BX LR ENDP
What do I need to stop the Interrupt coming back ? Interestingly if I step though, my ISR returns happily and the interrupt trigger again, it's only if I continue program execution that the ISR executes again.,
No need to clear pending in the NVIC, but in the EXTI peripheral you might have to acknowledge it (EXTI_PR?).
View all questions in Cortex-M / M-Profile forum