Question
STM32: enter and exit correctly to/from an ISR (assembly code)
Posted on November 28, 2015 at 18:34
Hello everybody,
At the moment I'm studying for an exam based on microcontrollers and I have choose the stm32 family, but I need to program this microcontroller in assembly. In the last meeting with my professor, he had a doubt on how I handled the interrupt routine. I had explain that my code doesn't fail and doesn't saturate the stack, but maybe I'm wrong and I wrote a ''bad code''. Could someone enlighten me about this? I wrote this interrupt routine:PUBLIC USART1_IRQ37
SECTION .text:CODE:REORDER:NOROOT(1)
USART1_IRQ37
push {LR}
BL get_char
BL checking
BL put_char
pop {PC}
I need to save the LR, because the code will jump in others subroutines. Am I right?
With the instruction:
pop {PC} Does it exit correctly from the ISR?
Another question. In one subroutine I want to exit from the ISR and return directly to ''main'' and wait for another interrupt in sleep mode, if a counter is less than 3.
section .text:CODE:NOROOT(2)
THUMB
get_char
ldrb r3, [r2, #4]
strb r3, [r5, r4]
add r4, r4, #1 ; count++
cmp r4, #3 ; if r4 >= 3
BCS complete
pop {PC} ; return to main
complete
mov r4, #0 ; count=0
BX LR ; return from function call Am I doing everythig right?
I will appreciate any tip!
Regards