Please someone help me with my code. I am newbie and trying to turn off LED inside systick handler. I tried with GDB but systick handler is never triggered. What am I missing?
.section interrupt_vector, "a", %progbits
.word 0x0
.word reset_handler + 1
.org 0x3C
.word stk_handler + 1
.section interrupt_handler, "ax", %progbits
reset_handler:
//enable GPIOA
LDR R0, =AHB1ENR
LDR R1, [R0]
MOV R2, GPIOA_ENABLE
ORR R3, R1, R2
STR R3, [R0]
//configure GPIOA_MODER
LDR R0, =GPIOA_MODER
LDR R1, [R0]
MOV R2, PIN5_GPIO_MODER
ORR R3, R1, R2
STR R3, [R0]
//enable systick
LDR R0, =STK_LOAD
MOV R1, STK_LOAD_MASK
STR R1, [R0]
LDR R0, =STK_VAL
MOV R1, 0x0
STR R1, [R0]
LDR R0, =STK_CTRL
MOV R1, STK_CTRL_MASK
STR R1, [R0]
//Turn LED on
LDR R0, =GPIOA_ODR
LDR R1, [R0]
MOV R2, PIN5_GPIO_ODR
ORR R3, R1, R2
STR R3, [R0]
LDR R0, =main + 1
BX R0
stk_handler:
LDR R0, =GPIOA_ODR
MOV R1, 0x0
STR R1, [R0]
LDR R0, main + 1
BX R0
main:
nop
b main
Best Answer
Your code does not setup the
SP
correctly, which triggers a hardfault as soon as the first SysTick interrupt.Note that to return from interrupt you must use
BX LR
orPOP PC
if you have pushedLR
to stack.