Question
STM32 UART Baremetal
Hey guys, I've been playing around with STM32F334R8 Nucleo board's USART module. As a part of it, I have written a small bare-metal code to print a character and unfortunately, my code isn't working. I am seeing junk on my putty window sometimes and it's remaining blank on some other times. Here is my code
#include "stm32f3xx.h" // Device header
void delay(int n)
{
for(int i=0;i<n*1000000;i++){} //Gives 1 second delay
}
void Init(void)
{
RCC->AHBENR |= (1<<17);
RCC->APB1ENR |= (1<<17);
GPIOA->AFR[0] |= 0x0700;
GPIOA->MODER |= (1<<5);
USART2->BRR = ((SystemCoreClock*2)/9600); //16MHz Frequency
USART2->CR1 = (1<<3);
USART2->CR1 |= (1<<0);
}
int main(void)
{
Init();
while(!(USART2->ISR & (1<<7))){};
for(int i=0;i<50;i++)
{
USART2->TDR = 'K' & 0xFF;
delay(1);
}
}Please let me know where I am going wrong. Thank you.
