hal
Hardware Abstraction Layer
stm32f4_uart2.h File Reference

Provides serial communication over UART2. More...

#include "uart.h"
Include dependency graph for stm32f4_uart2.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

hal_status_t stm32f4_uart2_init ()
 Initialize UART channel 2. Must be called prior to using the channel. More...
 
hal_status_t stm32f4_uart2_deinit ()
 Deinitialize UART channel 2. More...
 
hal_status_t stm32f4_uart2_read (uint8_t *data, size_t len, size_t *bytes_read)
 Read an incoming byte stream from UART channel 2. More...
 
hal_status_t stm32f4_uart2_write (const uint8_t *data, size_t len, size_t *bytes_written)
 Write an outgoing byte stream to UART channel 2. More...
 

Detailed Description

Provides serial communication over UART2.

Copyright (c) 2025 Cory McKiel. Licensed under the MIT License. See LICENSE file in the project root.

Function Documentation

◆ stm32f4_uart2_deinit()

hal_status_t stm32f4_uart2_deinit ( )

Deinitialize UART channel 2.

The channel can only be deinitialized if it has previously been initialized.

Returns
HAL_STATUS_OK on successful deinitialization, HAL_STATUS_ERROR otherwise.
Note
Brings down the peripheral, but not the gpio port that was initialized. This is because gpio ports are shared and unexpected deinits could disrupt other drivers without coordination.

◆ stm32f4_uart2_init()

hal_status_t stm32f4_uart2_init ( )

Initialize UART channel 2. Must be called prior to using the channel.

Returns
HAL_STATUS_OK on successful initialization, HAL_STATUS_ERROR otherwise.

Initialize UART channel 2. Must be called prior to using the channel.

◆ stm32f4_uart2_read()

hal_status_t stm32f4_uart2_read ( uint8_t *  data,
size_t  len,
size_t *  bytes_read 
)

Read an incoming byte stream from UART channel 2.

Data is placed into the buffer in the same order it was received on the UART channel. There is no way to partition it using this API. Any processing (i.e. parsing for the start of a command) needs to happen at a higher level.

Parameters
dataA buffer to return read data to client.
lenThe max number of bytes to read into buffer. Should not exceed buffer size.
bytes_readReturn the actual number of bytes that were successfully read.
Returns
HAL_STATUS_OK on success, HAL_STATUS_ERROR otherwise.

Read an incoming byte stream from UART channel 2.

◆ stm32f4_uart2_write()

hal_status_t stm32f4_uart2_write ( const uint8_t *  data,
size_t  len,
size_t *  bytes_written 
)

Write an outgoing byte stream to UART channel 2.

Parameters
dataA buffer filled with data to send.
lenThe number of bytes to send. Should not exceed buffer size.
bytes_writtenReturn the actual number of bytes that were successfully written.
Returns
HAL_STATUS_OK on success, HAL_STATUS_ERROR otherwise.

Write an outgoing byte stream to UART channel 2.