STM32F103xx Assembly - unable to run application
I am "Learning" assembly, So I have tried to program my stm32f103 in assembly (a simple program to blink a led). The problem is that the program runs when uploaded using st-flash utility. But, If I press reset button, the program stops working.
Here are few things that I debugged in STM32CubeProgrammer.
- The program seems runs if do a reset from the programmer but not on board.
- I get a unable to run error If I try to run the CPU from CubePrg after manual button reset.
- Moreover the Program Counter register seems to jump to 0xFFFFFFFE in the above case (Not always).
I am using Ubuntu and Nucleo-64 board.
PS. I didnt use any startup_*.s file. Instead placed the 2 vector address by using word and main program at 0x08000200 using .org directive
EDIT:
The program counter now always goes to 0.
Code:
.equ RCC_BASE, 0x40021000
.equ APB2ENB, RCC_BASE + 0x18
.equ GPIOA_BASE, 0x40010800
.equ GPIOA_CONF_L, GPIOA_BASE + 0x0
.equ GPIOA_BSSR, GPIOA_BASE + 0x10
.equ GPIOA_ODR, GPIOA_BASE + 0xC
.syntax unified
.cpu cortex-m3
.thumb
// Global memory locations.
.global reset
.word 0x20001000
.word reset
.text
.entry
reset: .proc
;LDR r3, =_estack
;MOV sp, r3
push {r7}
ADD r7, sp, #0
B _main
_main:
// Enable Clock APH
LDR r3, =APB2ENB
LDR r2, [r3]
ORR r2,r2,#0x4
STR r2, [r3]
// Reset Pin PA5
LDR r3, =GPIOA_BSSR
LDR r2, [r3]
MOV r2, #0x20
STR r2, [r3]
//Set PinMode PA5 as OUTPUT
LDR r3, =GPIOA_CONF_L
LDR r2, [r3]
MOV r2, #0x100000
STR r2, [r3]
// Set Default High on PA5
LDR r3, =GPIOA_ODR
LDR r2, [r3]
MOV r2,#0x20
STR r2, [r3]
mov r3, #0
B loop
.endp
loop:
LDR r3, =GPIOA_ODR
LDR r2, [r3]
ORR r2,r2,#0x20
STR r2, [r3]
MOV r4,#0xFF40
BL _delay
LDR r3, =GPIOA_ODR
LDR r2, [r3]
AND r2,r2,#0xFFFFFFDF
STR r2, [r3]
MOV r4,#0xFF40
BL _delay
B loop
_delay:
SUB r4,r4,#0x1
CMP r4,#0
BNE _delay
BX lr
.align
.endFinally, got it working. The problem is the address of the reset handler. I set second vector address to reset_label+1. But, why?
Still curious how it worked the first time (when uploaded).
