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

UART driver implementation for STM32F4 series. More...

Include dependency graph for uart.c:

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 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 uart6_init (uint32_t baudrate)
 Initialize USART6 peripheral.
void uart2_init (uint32_t baudrate)
 Initialize USART2 peripheral.
void uart2_write_char (char c)
 Transmit a single character via USART2.
void uart1_write_char (char c)
 Transmit a single character via USART1.
<<<<<<< HEAD=======void uart6_write_char(char c) { UARTx_Reg_Typedef *usart=GET_USARTx_BASE(6);if(usart==NULL) return;while(!(usart->SR &USART_SR_TXE)) ;usart->DR=c;} void uart2_write_int(int32_t num) { char buf[12];int i=0;if(num==0) { uart2_write_char('0');return;} if(num< 0) { uart2_write_char('-');num=-num;} while(num > 0) { buf[i++]='0'+(num % 10);num/=10;} while(i--) { uart2_write_char(buf[i]);} } void uart1_write_int(int32_t num) { char buf[12];int i=0;if(num==0) { uart1_write_char('0');return;} if(num< 0) { uart1_write_char('-');num=-num;} while(num > 0) { buf[i++]='0'+(num % 10);num/=10;} while(i--) { uart1_write_char(buf[i]);} } void uart6_write_int(int32_t num) { char buf[12];int i=0;if(num==0) { uart6_write_char('0');return;} if(num< 0) { uart6_write_char('-');num=-num;} while(num > 0) { buf[i++]='0'+(num % 10);num/=10;} while(i--) { uart6_write_char(buf[i]);} } void uart2_write_float(float num) { if(num< 0) { uart2_write_char('-');num=-num;} int32_t integer=(int32_t) num;uart2_write_int(integer);uart2_write_char('.');float floating=num - integer;uart2_write_int((int32_t)(floating *100000+0.5f));} void uart1_write_float(float num) { if(num< 0) { uart1_write_char('-');num=-num;} int32_t integer=(int32_t) num;uart1_write_int(integer);uart1_write_char('.');float floating=num - integer;uart1_write_int((int32_t)(floating *100000+0.5f));} void uart6_write_float(float num) { if(num< 0) { uart6_write_char('-');num=-num;} int32_t integer=(int32_t) num;uart6_write_int(integer);uart6_write_char('.');float floating=num - integer;uart6_write_int((int32_t)(floating *100000+0.5f));} void uart2_write_string(const char *s) { while(*s) { uart2_write_char(*s++);} } void uart1_write_string(const char *s) { while(*s) { uart1_write_char(*s++);} } void uart6_write_string(const char *s) { while(*s) { uart6_write_char(*s++);} } > > > > > > > char uart_read_char (hal_uart_t uart)
 Read a single character from the specified UART.
char uart1_read_char (void)
 Read a single character from USART1.
char uart2_read_char (void)
 Read a single character from USART2.
char uart6_read_char (void)
 Read a single character from USART6.
int uart_available (hal_uart_t uart)
 Check if data is available to read from specified UART.
int uart1_available (void)
 Check if data is available to read from USART1.
int uart2_available (void)
 Check if data is available to read from USART2.
int uart6_available (void)
 Check if data is available to read from USART6.
uint32_t uart2_read_until (char *buffer, uint32_t maxlen, char delimiter)
 Read characters from USART2 until delimiter or max length.

Detailed Description

UART driver implementation for STM32F4 series.

<<<<<<< HEAD

This file provides UART communication functions for STM32F4 microcontrollers.

It supports USART1, USART2, and USART6 peripherals with:

UART initialization and I/O functions for STM32F4 UART1, UART2, and UART6.

This file provides the implementation of UART communication functions for STM32F401RE microcontroller. It supports USART1, USART2, and USART6 peripherals with the following features:

73eb6c283269d3698b418665a84bf3716bb15e61

  • Baud rate configuration
  • Character, integer, float, and string transmission
  • Character reception
  • Data availability checking
  • Blocking (polling) implementations

The implementation uses GPIO alternate functions for UART pins and provides both generic (UART instance parameter) and specific functions.

Note
All functions are blocking and will wait for hardware operations to complete
Default configuration: 8 data bits, no parity, 1 stop bit