NavHAL 0.1.0
NAVRobotec's architecture-agnostic HAL for embedded systems.
Loading...
Searching...
No Matches
uart.h File Reference

UART driver interface for STM32F4 (Cortex-M4). More...

#include "common/hal_types.h"
#include <stdint.h>
Include dependency graph for uart.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define uart2_write(val)
#define uart1_write(val)
#define uart6_write(val)
#define PERIPH_BASE   0x40000000UL
#define AHB1PERIPH_BASE   (PERIPH_BASE + 0x00020000UL)
#define APB1PERIPH_BASE   (PERIPH_BASE + 0x00000000UL)
#define APB2PERIPH_BASE   (PERIPH_BASE + 0x7400)
#define RCC_BASE   (AHB1PERIPH_BASE + 0x3800)
#define USART2_BASE   (APB1PERIPH_BASE + 0x4400)
#define USART1_BASE   0x40011000
#define USART6_BASE   0x40011400
#define RCC_APB1ENR   (*(__IO uint32_t *)(RCC_BASE + 0x40))
#define RCC_APB2ENR   (*(__IO uint32_t *)(RCC_BASE + 0x44))
#define USART2_SR   (*(__IO uint32_t *)(USART2_BASE + 0x00))
#define USART2_DR   (*(__IO uint32_t *)(USART2_BASE + 0x04))
#define USART2_BRR   (*(__IO uint32_t *)(USART2_BASE + 0x08))
#define USART2_CR1   (*(__IO uint32_t *)(USART2_BASE + 0x0C))
#define USART1_SR   (*(__IO uint32_t *)(USART1_BASE + 0x00))
#define USART1_DR   (*(__IO uint32_t *)(USART1_BASE + 0x04))
#define USART1_BRR   (*(__IO uint32_t *)(USART1_BASE + 0x08))
#define USART1_CR1   (*(__IO uint32_t *)(USART1_BASE + 0x0C))
#define USART6_SR   (*(__IO uint32_t *)(USART6_BASE + 0x00))
#define USART6_DR   (*(__IO uint32_t *)(USART6_BASE + 0x04))
#define USART6_BRR   (*(__IO uint32_t *)(USART6_BASE + 0x08))
#define USART6_CR1   (*(__IO uint32_t *)(USART6_BASE + 0x0C))
#define RCC_APB1ENR_USART2EN   (1 << 17)
#define RCC_APB2ENR_USART1EN   (1 << 4)
#define RCC_APB2ENR_USART6EN   (1 << 5)
#define USART_CR1_UE   (1 << 13)
 USART Enable.
#define USART_CR1_TE   (1 << 3)
 Transmitter Enable.
#define USART_CR1_RE   (1 << 2)
 Receiver Enable.
#define USART_SR_TXE   (1 << 7)
 Transmit Data Register Empty.
#define USART_SR_RXNE   (1 << 5)
 Read Data Register Not Empty.

Enumerations

enum  hal_uart_t { UART1 , UART2 , UART6 }
 UART identifier enumeration. More...

Functions

void uart_init (uint32_t baudrate, hal_uart_t uart)
 Initialize the specified UART peripheral.
void uart_write_char (char c, hal_uart_t uart)
 Transmit a single character via the specified UART.
void uart_write_int (int32_t num, hal_uart_t uart)
 Transmit a 32-bit signed integer via UART.
void uart_write_float (float num, hal_uart_t uart)
 Transmit a floating-point number via UART.
void uart_write_string (const char *s, hal_uart_t uart)
 Transmit a null-terminated string via UART.
void uart1_init (uint32_t baudrate)
 Initialize USART1 peripheral.
void uart1_write_char (char c)
 Transmit a single character via USART1.
void uart1_write_int (int32_t num)
 Transmit a 32-bit signed integer via USART1.
void uart1_write_float (float num)
 Transmit a floating-point number via USART1.
void uart1_write_string (const char *s)
 Transmit a null-terminated string via USART1.
void uart2_init (uint32_t baudrate)
 Initialize USART2 peripheral.
void uart2_write_char (char c)
 Transmit a single character via USART2.
void uart2_write_int (int32_t num)
 Transmit a 32-bit signed integer via USART2.
void uart2_write_float (float num)
 Transmit a floating-point number via USART2.
void uart2_write_string (const char *s)
 Transmit a null-terminated string via USART2.
void uart6_init (uint32_t baudrate)
 Initialize USART6 peripheral.
void uart6_write_char (char c)
 Transmit a single character via USART6.
void uart6_write_int (int32_t num)
 Transmit a 32-bit signed integer via USART6.
void uart6_write_float (float num)
 Transmit a floating-point number via USART6.
void uart6_write_string (const char *s)
 Transmit a null-terminated string via USART6.
char uart_read_char (hal_uart_t uart)
 Read a single character from the specified UART.
int uart_available (hal_uart_t uart)
 Check if data is available to read.
int uart1_available (void)
 Check if data is available to read from USART1.
char uart1_read_char (void)
 Read a single character from USART1.
int uart2_available (void)
 Check if data is available to read from USART2.
char uart2_read_char (void)
 Read a single character from USART2.
int uart6_available (void)
 Check if data is available to read from USART6.
char uart6_read_char (void)
 Read a single character from USART6.
uint32_t uart2_read_until (char *buffer, uint32_t maxlen, char delimiter)
 Read characters into a buffer until a delimiter is found or max length is reached.

Detailed Description

UART driver interface for STM32F4 (Cortex-M4).

This header defines memory-mapped registers, macros, and function prototypes for UART (USART1, USART2, USART6) peripheral control on the STM32F401RE MCU.

The implementation provides:

  • UART initialization with configurable baud rates
  • Character, integer, float, and string transmission
  • Character reception
  • Data availability checking
  • Type-generic write macros for simplified usage
  • Support for all three available UART peripherals (USART1, USART2, USART6)
Note
Architecture-specific for STM32F401RE. Included through dispatcher based on CORTEX_M4.
All UART functions are blocking (polling mode) implementations.
Author
Ashutosh Vishwakarma
Date
2025-07-23

Enumeration Type Documentation

◆ hal_uart_t

enum hal_uart_t

UART identifier enumeration.

Identifies which UART peripheral to use for operations.

Enumerator
UART1 

USART1 - APB2 peripheral, typically higher speed.

UART2 

USART2 - APB1 peripheral.

UART6 

USART6 - APB2 peripheral.