cancel
Showing results for 
Search instead for 
Did you mean: 

avoid returning from interrupt

stenasc
Senior
Posted on August 30, 2014 at 23:22

Hi Forum,

Is there any way to avoid returning from an USART1 interrupt? The booting process of our unit takes some time so we want to jump to the main menu quickly by pressing a key on the keyboard. This works and the main menu is displayed, but before we can select an option on the menu, the unit returns to the booting process.

Is there any way of disabling the interrupt return so that the application permanently kills the booting process.

Many Thanks

Bob
5 REPLIES 5
Posted on August 31, 2014 at 11:46

There are perhaps other more subtle ways of doing this, but one approach your model could take would be to modify the return stack frame (PC) where the interrupt returns too, and then leave the IRQ normally. The code being returned too likely wants to reset the stack pointer (SP) as it won't be returning anywhere, and the stack consumed will be undefined, and perhaps significantly reduced.

The value of the link register (LR) is likely to be a magic value specifying which stack the processor state is on. This would be complicated if you preempt other interrupts, so your EXTI/USART interrupt probably should be set to the lowest of priorities.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
stenasc
Senior
Posted on August 31, 2014 at 21:59

Hi Clive,

Thanks for that and apologies for asking but do you have a code snippet for doing such a thing. I've never had to manipulate the SP or PC?

Bob

Andrew Neil
Chief II
Posted on September 01, 2014 at 15:01

That sounds fraught with danger!!

Surely, if you can get it into your ''main menu'' you could also get it to flag to the bootloader to exit?!

stenasc
Senior
Posted on September 02, 2014 at 08:56

Hi Neil,

Done. It sounds simple now, but the brain must have shut down. It was after all around 2am when I was working on this.

Many Thanks

Bob

Posted on September 03, 2014 at 21:38

Thanks for that and apologies for asking but do you have a code snippet for doing such a thing. I've never had to manipulate the SP or PC?

Well not exactly, I tend to craft things on the fly, I'll pull this out of the air, untested

; Stack Frame - See TRM or Definitive Guide
; +0 R0
; +4 R1
; +8 R2
; +12 R3
; +16 R12
; +20 LR
; +24 PC
; +28 PSR 
; Entry R0 is new function address, LR is return context for interrupt
; Code is assumed to be inlined with the IRQ Handler, otherwise you
; could copy LR to R1 before calling and watch out for the stack moving
TST LR, #4 ; Determine correct stack
ITE EQ
MRSEQ R1, MSP ; Read MSP (Main)
MRSNE R1, PSP ; Read PSP (Process)
STR R0, [R1, #24] ; Replace Interrupted PC in stack frame

0690X0000060MmfQAE.gif
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..