2025-08-20 5:22 PM
Hello everyone,
I am fairly new to embedded so bear with me. I am trying to understand bare metal programming.
So basically I managed to turn on the LED on soldiered on the board (PA5) but now am trying to create a delay using basic timer TIM6. My issue is that the LED is barely turning on for a very brief moment before turning off. I think my issue lies in how I am configuring the prescaler and auto-reload register. I looked up online and it says that the default clock speed is 16MHz, but I did not configure any clock source.
Here is my code down below which I used the reference manual to write:
GPIOA->ODR |= (1<<5); // Turning on LED
// Initialize TIM6
RCC->APB1ENR|=(1<<4);
TIM6->CR1|=(1<<0);
TIM6->PSC=16000-1;
TIM6->ARR=1000-1;
TIM6->CNT=0;
while(!(TIM6->SR & (1<<0))){}
TIM6->SR&=~(1<<0);
TIM6->CR1&=~(1<<0);
GPIOA->ODR &= ~(1<<5); //Turning off LED
Thank you.