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)
 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 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.

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.

Configures:

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

◆ uart1_read_char()

char uart1_read_char ( void )

Read a single character from USART1.

Returns
Received character

◆ uart1_write_char()

void uart1_write_char ( char c)

Transmit a single character via USART1.

Parameters
cCharacter to transmit

◆ uart1_write_float()

void uart1_write_float ( float num)

Transmit a floating-point number via USART1.

Parameters
numFloating-point number to transmit

◆ uart1_write_int()

void uart1_write_int ( int32_t num)

Transmit a 32-bit signed integer via USART1.

Parameters
numInteger to transmit

◆ uart1_write_string()

void uart1_write_string ( const char * s)

Transmit a null-terminated string via USART1.

Parameters
sNull-terminated string to transmit

◆ 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.

Reads characters into buffer until:

  • Delimiter character is received
  • Max length is reached Always null-terminates the buffer
Parameters
bufferDestination buffer
maxlenMaximum number of characters to read (including null terminator)
delimiterCharacter that terminates the read
Returns
Number of characters read (excluding null terminator)

◆ 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)

Transmit a floating-point number via USART2.

Converts float to string representation with 5 decimal places Handles negative numbers

Parameters
numFloating-point number to transmit

◆ uart2_write_int()

void uart2_write_int ( int32_t num)

Transmit a 32-bit signed integer via USART2.

Converts integer to string representation and transmits it Handles negative numbers and zero

Parameters
numInteger to transmit

◆ uart2_write_string()

void uart2_write_string ( const char * s)

Transmit a null-terminated string via USART2.

Parameters
sNull-terminated string to transmit

◆ 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.

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)

Transmit a single character via USART6.

Parameters
cCharacter to transmit

◆ uart6_write_float()

void uart6_write_float ( float num)

Transmit a floating-point number via USART6.

Parameters
numFloating-point number to transmit

◆ uart6_write_int()

void uart6_write_int ( int32_t num)

Transmit a 32-bit signed integer via USART6.

Parameters
numInteger to transmit

◆ uart6_write_string()

void uart6_write_string ( const char * s)

Transmit a null-terminated string via USART6.

Parameters
sNull-terminated string to transmit

◆ 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.

Parameters
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).

Routes initialization to the appropriate UART-specific init function

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

◆ 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.

Blocks until a character is received

Parameters
uartUART instance to read from
Returns
Received character

◆ 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.
cCharacter to transmit
uartUART instance to use

◆ 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.

Converts float to string representation with 5 decimal places

Parameters
numFloating-point number to transmit
uartUART instance to use

◆ 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.

Converts integer to string representation and transmits it

Parameters
numInteger to transmit
uartUART instance to use

◆ 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.
sNull-terminated string to transmit
uartUART instance to use