Why do I fail to turn on the user led on my nucleo stm32l152 using this assembly code?
Hello everybody,
I'm trying to learn about stm32 microcontrollers and I thought the best way to do that was to start with assembly (well, maybe I was wrong about that, but I started with that). I'm just trying to turn on the user led on my nucleo stm32l152 (not even trying to make it blink, just trying to turn it on).
I read that the user led was on PA5, and that seems to match the layout of the board when you look at it.
Here is my code:
.equ RCC_BASE, (0x40023800)
.equ RCC_AHBENR, (RCC_BASE + 0x1C)
.equ GPIOBEN_FLAG, (0x10)
.equ GPIOA, (0x40020000)
.equ GPIOA_MODER, (GPIOA + 0x00)
.equ GPIOA_OTYPER, (GPIOA + 0x04)
.equ GPIOA_OSPEEDR, (GPIOA + 0x08)
.equ GPIOA_PUPDR, (GPIOA + 0x0C)
.equ GPIOA_ODR, (GPIOA + 0x14)
@ Vector table start
.long 0x20001000
.long _start
@ Vector table end
_start:
# setting RCC_AHBENR GPIOPEN bit to 1
LDR R0, =RCC_AHBENR
LDR R1, [R0]
LDR R2, =GPIOBEN_FLAG
ORR R1, R2
STR R1, [R0]
# GPIOA settings
LDR R2, =0x100000000000
MVN R2, R2
LDR R3, =0x010000000000
LDR R4, =0x110000000000
MVN R4, R4
LDR R0, =GPIOA_MODER
LDR R1, [R0]
AND R1, R2
ORR R1, R3
STR R1, [R0]
LDR R0, =GPIOA_OSPEEDR
LDR R1, [R0]
AND R1, R4
STR R1, [R0]
LDR R0, =GPIOA_PUPDR
LDR R1, [R0]
AND R1, R4
STR R1, [R0]
LDR R0, =GPIOA_OTYPER
LDR R1, [R0]
LDR R5, =0x100000
MVN R6, R5
AND R1, R6
STR R1, [R0]
# activating the pin
LDR R0, =GPIOA_ODR
LDR R1, [R0]
ORR R1, R5
STR R1, [R0]
.global _startI'm also an assembly noob, so maybe it's that. However, I use only simple instructions here, so I think there must rather be something I'm missing about GPIO configuration or the stm32 architecture in general.
Any help would be greatly appreciated.
