hal
Hardware Abstraction Layer
stm32f4_uart2.c File Reference

Implements serial communication over UART2. More...

#include "stm32f4xx.h"
#include "stm32f4_hal.h"
#include "stm32f4_uart_util.h"
#include "stm32f4_uart2.h"
#include "circular_buffer.h"
Include dependency graph for stm32f4_uart2.c:

Macros

#define UART_BAUDRATE   115200
 
#define UART_BUFFER_RX_SIZE   CIRCULAR_BUFFER_MAX_SIZE
 
#define UART_BUFFER_TX_SIZE   CIRCULAR_BUFFER_MAX_SIZE
 

Functions

void USART2_IRQHandler (void)
 
hal_status_t stm32f4_uart2_init ()
 Initialize the UART2. (Connected to the USB) 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)
 Reads data from UART2 register. More...
 
hal_status_t stm32f4_uart2_write (const uint8_t *data, size_t len, size_t *bytes_written)
 Writes data to UART2 register. More...
 

Detailed Description

Implements 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 the UART2. (Connected to the USB)

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 
)

Reads data from UART2 register.

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 
)

Writes data to UART2 register.

Write an outgoing byte stream to UART channel 2.