0
\$\begingroup\$

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
asked Mar 20, 2016 at 7:38
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

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 or POP PC if you have pushed LR to stack.

answered Mar 20, 2016 at 9:39
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.