STM32 timer delay - assembler

Dear ARM-Community,

I need help on my timer implementation. I want to let the LED flash with 1Hz on my STM32F0-Nucleo with an 48MHz internal clock.

My C code is working perfectly:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
#define LD3 (0x03)
int main() {
//setup LED
RCC->AHBENR |= RCC_AHBENR_GPIOBEN;
GPIOB->MODER &= ~(0x3 << (LD3*2));
GPIOB->MODER |= (0x1 << (LD3*2));
GPIOB->OTYPER &= ~(1 << LD3);
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
TIM2->CR1 &= ~(TIM_CR1_CEN);
TIM2->PSC = 47999;
TIM2->ARR = 499;
TIM2->CR1 |= TIM_CR1_CEN;
TIM2->EGR |= TIM_EGR_UG;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Here is my assembler code, which does not work 100%:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
@enable TIM2
ldr r0, =APB1ENR
movs r1, #0x1
str r1, [r0]
@reset TIM2 clk
ldr r0, =TIM2_CR1
orrs r1, r1
str r1, [r0]
@set output cmp mode
ldr r0, =TIM2_CCMR1
movs r1, #0x7
lsls r1, r1, #0x4
str r1, [r0]
@set prescaler
ldr r0, =TIM2_PSC
eors r1, r1
ldr r1, =#47999
@ldr r1, =#0xbb7f
str r1, [r0]
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I tested the LED already with a simple loop, that worked. All the vectors are also set correctly! But now, even though I set the right values, the delay is not working correctly.

I guess it has strangely to do something with the ARR, because I can change the f with it.

I have no clue what is wrong here. Can somebody help me?

Thank you!

0