NavHAL 0.1.0
NAVRobotec's architecture-agnostic HAL for embedded systems.
Loading...
Searching...
No Matches
UART HAL API

UART driver API functions. 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)
void uart2_write_float (float num)
void uart2_write_string (const char *s)
void uart6_init (uint32_t baudrate)
 Initialize USART6 peripheral.
void uart6_write_char (char c)
void uart6_write_int (int32_t num)
void uart6_write_float (float num)
void uart6_write_string (const char *s)
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 API functions.

Provides initialization, transmission, and reception functions for UART peripherals. Both generic (UART instance parameter) and specific (UART1/UART2/UART6) functions are provided for flexibility.

Function Documentation

◆ uart1_available()

int uart1_available ( void )

Check if data is available to read from USART1.

<<<<<<< HEAD

Returns
Non-zero if data is available, 0 otherwise

◆ uart1_init()

void uart1_init ( uint32_t baudrate)

Initialize USART1 peripheral.

Parameters
baudrateDesired communication speed in bits per second.
[in]baudrateDesired communication speed in bits per second

Configures:

  • GPIO PA9 (TX) as alternate function 7 (USART1_TX)
  • Baud rate based on APB2 clock
  • Transmitter enable
  • USART enable

◆ uart1_read_char()

char uart1_read_char ( void )

Read a single character from USART1.

<<<<<<< HEAD

Returns
Received character

◆ uart1_write_char()

void uart1_write_char ( char c)

Transmit a single character via USART1.

73eb6c283269d3698b418665a84bf3716bb15e61

Parameters
[in]cCharacter to transmit

Blocks until transmit buffer is empty

◆ uart1_write_float()

void uart1_write_float ( float num)

Transmit a floating-point number via USART1.

◆ uart1_write_int()

void uart1_write_int ( int32_t num)

Transmit a 32-bit signed integer via USART1.

◆ uart1_write_string()

void uart1_write_string ( const char * s)

Transmit a null-terminated string via USART1.

◆ uart2_available()

int uart2_available ( void )

Check if data is available to read from USART2.

Returns
Non-zero if data is available, 0 otherwise

◆ uart2_init()

void uart2_init ( uint32_t baudrate)

Initialize USART2 peripheral.

Configures:

  • GPIO PA2 (TX) and PA3 (RX) as alternate function 7 (USART2)
  • Baud rate based on APB1 clock
  • Transmitter and receiver enable
  • USART enable
Parameters
baudrateDesired communication speed in bits per second

◆ uart2_read_char()

char uart2_read_char ( void )

Read a single character from USART2.

Returns
Received character

◆ uart2_read_until()

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.

Reads characters into the provided buffer until either:

  • The specified delimiter character is received
  • The maximum buffer length is reached
  • A timeout occurs

The delimiter character is not included in the buffer. The buffer is always null-terminated.

Parameters
bufferDestination buffer for received characters.
maxlenMaximum number of characters to read (including null terminator).
delimiterCharacter that terminates the read operation.
Returns
Number of characters read (excluding null terminator).

Read characters into a buffer until a delimiter is found or max length is reached.

73eb6c283269d3698b418665a84bf3716bb15e61

Parameters
[out]bufferDestination buffer
[in]maxlenMaximum number of characters to read (including null terminator)
[in]delimiterCharacter that terminates the read
Returns
Number of characters read (excluding null terminator)
  • Reads characters into buffer until delimiter or max length
  • Always null-terminates the buffer
  • Blocks while waiting for characters

◆ uart2_write_char()

void uart2_write_char ( char c)

Transmit a single character via USART2.

Blocks until transmit buffer is empty

Parameters
cCharacter to transmit

◆ uart2_write_float()

void uart2_write_float ( float num)

◆ uart2_write_int()

void uart2_write_int ( int32_t num)

◆ uart2_write_string()

void uart2_write_string ( const char * s)

◆ uart6_available()

int uart6_available ( void )

Check if data is available to read from USART6.

Returns
Non-zero if data is available, 0 otherwise

◆ uart6_init()

void uart6_init ( uint32_t baudrate)

Initialize USART6 peripheral.

<<<<<<< HEAD

Configures:

  • GPIO PC6 (TX) as alternate function 7 (USART6_TX)
  • Baud rate based on APB2 clock
  • Transmitter enable
  • USART enable
Parameters
baudrateDesired communication speed in bits per second

◆ uart6_read_char()

char uart6_read_char ( void )

Read a single character from USART6.

Returns
Received character

◆ uart6_write_char()

void uart6_write_char ( char c)

◆ uart6_write_float()

void uart6_write_float ( float num)

◆ uart6_write_int()

void uart6_write_int ( int32_t num)

◆ uart6_write_string()

void uart6_write_string ( const char * s)

◆ uart_available()

int uart_available ( hal_uart_t uart)

Check if data is available to read.

Parameters
uartUART instance to check.
Returns
1 if data is available, 0 otherwise.

Check if data is available to read.

73eb6c283269d3698b418665a84bf3716bb15e61

Parameters
[in]uartUART instance to check
Returns
Non-zero if data is available, 0 otherwise

◆ uart_init()

void uart_init ( uint32_t baudrate,
hal_uart_t uart )

Initialize the specified UART peripheral.

Configures the UART peripheral with the specified baud rate and enables both transmitter and receiver. Also enables the peripheral clock.

Parameters
baudrateDesired communication speed in bits per second.
uartUART instance to initialize (UART1, UART2, or UART6).
[in]baudrateDesired communication speed in bits per second
[in]uartUART instance to initialize (UART1, UART2, or UART6)

Routes initialization to the appropriate UART-specific init function

◆ uart_read_char()

char uart_read_char ( hal_uart_t uart)

Read a single character from the specified UART.

Blocks until a character is received.

Parameters
uartUART instance to read from.
Returns
Received character.
Parameters
[in]uartUART instance to read from
Returns
Received character

Blocks until a character is received

◆ uart_write_char()

void uart_write_char ( char c,
hal_uart_t uart )

Transmit a single character via the specified UART.

Blocks until the transmit buffer is empty before sending.

Parameters
cCharacter to transmit.
uartUART instance to use.

Transmit a single character via the specified UART.

Parameters
[in]cCharacter to transmit
[in]uartUART instance to use

Automatically adds carriage return when newline is transmitted

◆ uart_write_float()

void uart_write_float ( float num,
hal_uart_t uart )

Transmit a floating-point number via UART.

Converts the float to its string representation with default formatting and transmits it.

Parameters
numFloating-point number to transmit.
uartUART instance to use.
[in]numFloating-point number to transmit
[in]uartUART instance to use

Converts float to string representation with 5 decimal places

◆ uart_write_int()

void uart_write_int ( int32_t num,
hal_uart_t uart )

Transmit a 32-bit signed integer via UART.

Converts the integer to its string representation and transmits it.

Parameters
numInteger to transmit.
uartUART instance to use.
[in]numInteger to transmit
[in]uartUART instance to use

Converts integer to string representation and transmits it

◆ uart_write_string()

void uart_write_string ( const char * s,
hal_uart_t uart )

Transmit a null-terminated string via UART.

Transmits each character of the string until the null terminator.

Parameters
sNull-terminated string to transmit.
uartUART instance to use.
[in]sNull-terminated string to transmit
[in]uartUART instance to use