STM32 Traffic Control
Loading...
Searching...
No Matches
uart.c File Reference

UART drive implementation. More...

#include "stm32f446xx.h"
#include "uart.h"
#include <stdint.h>

Macros

#define GPIOAEN   (1U<<0)
#define UART2EN   (1U<<17)
#define CR1_TE   (1U<<3)
#define CR1_RE   (1U<<2)
#define CR1_UE   (1U<<13)
#define SR_TXE   (1U<<7)
#define SYS_FREQ   16000000
#define APB1_CLK   SYS_FREQ
#define UART_BAUDRATE   115200

Functions

int __io_putchar (int ch)
 Low-level character output function for printf redirection.
void uart2_init (void)
 Initialize UART2 peripheral.
void uart2_write (int ch)
 Transmit a single character over UART2.

Detailed Description

UART drive implementation.

This file provides low-level UART2 initialization and transmit functionality. The UART is primarily used for serial logging and debug output cia printf() redirectiion.

Macro Definition Documentation

◆ APB1_CLK

#define APB1_CLK   SYS_FREQ

◆ CR1_RE

#define CR1_RE   (1U<<2)

◆ CR1_TE

#define CR1_TE   (1U<<3)

◆ CR1_UE

#define CR1_UE   (1U<<13)

◆ GPIOAEN

#define GPIOAEN   (1U<<0)

◆ SR_TXE

#define SR_TXE   (1U<<7)

◆ SYS_FREQ

#define SYS_FREQ   16000000

◆ UART2EN

#define UART2EN   (1U<<17)

◆ UART_BAUDRATE

#define UART_BAUDRATE   115200

Function Documentation

◆ __io_putchar()

int __io_putchar ( int ch)

Low-level character output function for printf redirection.

This function is called by the C standard library to output characters when using fucntions such as printf(). Characters are transmitted over UART2.

Parameters
chCharacter to transmit
Returns
The transmitted character

◆ uart2_init()

void uart2_init ( void )

Initialize UART2 peripheral.

UART2 is configured for basic asynchronous communication and is used primarily for logging and debugging.

◆ uart2_write()

void uart2_write ( int ch)

Transmit a single character over UART2.

This function blocks until the transmit data register is empty, then writes the provided character to the UART data register.

Parameters
chCharacter to transmit.