Code REport
Code REport
h>
#include <stdio.h>
#include "stm32f4xx.h"
//Defines
#define GPIOA_EN (1U << 0)
#define USART1_EN (1U << 4)
#define CR1_TE (1U << 3)
#define CR1_UE (1U << 13)
#define SR_TXE (1U << 7)
//Prototypes
static void usart_set_baudrate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t
BaudRate);
static uint16_t compute_usart_bd(uint32_t PeriphClk, uint32_t BaudRate);
void usart1_write(int ch);
void usart1_tx_init(void);
int main(void)
{
usart1_tx_init();
while (1){
usart1_write('Y');
}
return 0;
}
void usart1_tx_init(void) {
//CONFIGURE USART GPIO PIN
//Enable clock GPIOA
RCC->AHB1ENR |= GPIOA_EN;
//Set PA9 to Alternate Function
GPIOA->MODER &= ~(0x03 << 18);
GPIOA->MODER |= (0x02 << 18);
//Set PA9 (TX) to AF07
GPIOA->AFR[1] &= ~(0x0F << 4);
GPIOA->AFR[1] |= (0x07 << 4);