#include "stm32g474xx.h"
Go to the source code of this file.
|
| bool | PHAL_USART_init (PHAL_USART_Idx_t periph_idx, uint32_t baud_rate, const uint32_t clock_rate) |
| | Initialize a USART peripheral for DMA-driven communication.
|
| |
| bool | PHAL_USART_tx (PHAL_USART_Idx_t periph_idx, uint8_t *data, uint16_t len) |
| | Start a transmission using DMA.
|
| |
| void | PHAL_USART_rx (PHAL_USART_Idx_t periph_idx, uint8_t *data, uint16_t len, bool cont) |
| | Start a reception using DMA of a specific length.
|
| |
| bool | PHAL_USART_txBusy (PHAL_USART_Idx_t periph_idx) |
| | Returns whether the USART peripheral is currently transmitting data.
|
| |
| uint16_t | PHAL_USART_rxCount (PHAL_USART_Idx_t periph_idx) |
| | Number of bytes received in the last completed frame.
|
| |
| bool | PHAL_USART_txBlocking (PHAL_USART_Idx_t periph_idx, uint8_t *data, uint16_t len) |
| | Transmit data, blocking until the transfer completes.
|
| |
| void | PHAL_USART_rxBlocking (PHAL_USART_Idx_t periph_idx, uint8_t *data, uint16_t len) |
| | Receive data, blocking until a one-shot reception completes.
|
| |
| void | PHAL_USART_rxCallback (PHAL_USART_Idx_t periph_idx, uint16_t len) |
| | Weak callback invoked when a full RX frame is received. Override in application code. Runs in ISR context, so keep it light.
|
| |
◆ PHAL_USART_Idx_t
| Enumerator |
|---|
| USART1_IDX | |
| USART2_IDX | |
| USART3_IDX | |
| NUM_USART | |
◆ PHAL_USART_init()
| bool PHAL_USART_init |
( |
PHAL_USART_Idx_t | periph_idx, |
|
|
uint32_t | baud_rate, |
|
|
const uint32_t | clock_rate ) |
Initialize a USART peripheral for DMA-driven communication.
Enables the peripheral clock and applies a fixed frame format:
- 8 data bits, no parity, 1 stop bit (8N1)
- 16x oversampling
- no hardware flow control Derives the baud-rate divisor from clock_rate, enables the IDLE-line interrupt (RX frame completion) and the TX DMA transfer-complete interrupt, then initializes the TX and RX DMA channels.
Call once per USART before any tx/rx. The USART GPIO pins must already be configured by the caller.
- Parameters
-
| periph_idx | Which USART peripheral to initialize |
| baud_rate | Desired baud rate |
| clock_rate | Frequency (Hz) of the bus clock feeding this USART (APBx) |
- Returns
- true on success, false if DMA init failed
- Parameters
-
| periph_idx | Which USART peripheral to initialize |
| baud_rate | Desired baud rate |
| clock_rate | Frequency (Hz) of the bus clock feeding this USART (APB1/APB2) |
- Returns
- true on success, false if DMA init failed
◆ PHAL_USART_rx()
| void PHAL_USART_rx |
( |
PHAL_USART_Idx_t | periph_idx, |
|
|
uint8_t * | data, |
|
|
uint16_t | len, |
|
|
bool | cont ) |
Start a reception using DMA of a specific length.
- Parameters
-
| periph_idx | Which USART peripheral to receive on |
| data | The address to put the received data |
| len | Maximum number of bytes (the buffer size). A frame shorter than this still completes on the IDLE line; the actual count is reported to PHAL_USART_rxCallback. uint16_t because that is the DMA's transfer counter width. |
| cont | Enable continuous RX using the IDLE-line interrupt. When set, call this function once and the HAL keeps receiving frames of the same maximum length, invoking PHAL_USART_rxCallback after each. |
Start a reception using DMA of a specific length.
- Parameters
-
| periph_idx | Which USART peripheral to receive on |
| data | Buffer to receive into |
| len | Maximum number of bytes to receive (buffer size) |
| cont | Enable continuous RX. When set, call this once and the HAL keeps receiving frames of the same maximum length, invoking PHAL_USART_rxCallback after each. |
◆ PHAL_USART_rxBlocking()
| void PHAL_USART_rxBlocking |
( |
PHAL_USART_Idx_t | periph_idx, |
|
|
uint8_t * | data, |
|
|
uint16_t | len ) |
Receive data, blocking until a one-shot reception completes.
Starts a one-shot DMA reception (see PHAL_USART_rx) and busy-waits until the IDLE-line ISR signals the frame is complete. Call PHAL_USART_rxCount() afterwards for the byte count. Do not call from an ISR.
- Parameters
-
| periph_idx | Which USART peripheral to receive on |
| data | Buffer to receive into |
| len | Maximum number of bytes to receive |
| periph_idx | Which USART peripheral to receive on |
| data | Buffer to receive into |
| len | Number of bytes to receive |
◆ PHAL_USART_rxCallback()
Weak callback invoked when a full RX frame is received. Override in application code. Runs in ISR context, so keep it light.
- Parameters
-
| periph_idx | Which USART peripheral received the frame |
| len | Number of bytes in this frame. Bytes past this offset in the buffer are stale and must not be decoded. |
◆ PHAL_USART_rxCount()
Number of bytes received in the last completed frame.
The IDLE line ends a frame whenever the sender stops, which may be short of the length passed to PHAL_USART_rx. Anything past this count in the buffer is leftover from an earlier frame.
- Parameters
-
| periph_idx | Which USART peripheral to query |
- Returns
- byte count, valid once PHAL_USART_rxCallback has fired (or PHAL_USART_rxBlocking has returned)
- Parameters
-
| periph_idx | Which USART peripheral to query |
- Returns
- byte count, valid once PHAL_USART_rxCallback has fired
◆ PHAL_USART_tx()
| bool PHAL_USART_tx |
( |
PHAL_USART_Idx_t | periph_idx, |
|
|
uint8_t * | data, |
|
|
uint16_t | len ) |
Start a transmission using DMA.
Fails rather than truncating a transfer already in flight - poll PHAL_USART_txBusy() (or use PHAL_USART_txBlocking) before calling again.
- Parameters
-
| periph_idx | Which USART peripheral to transmit on |
| data | The address of the data to send |
| len | Number of bytes. |
- Returns
- true if every DMA reconfiguration step succeeded, false if a transmission is already in flight or a step failed
Start a transmission using DMA.
- Parameters
-
| periph_idx | Which USART peripheral to transmit on |
| data | Buffer to send |
| len | Number of bytes to send |
- Returns
- true if every DMA reconfiguration step succeeded, false if a transmission is already in flight or a step failed
◆ PHAL_USART_txBlocking()
| bool PHAL_USART_txBlocking |
( |
PHAL_USART_Idx_t | periph_idx, |
|
|
uint8_t * | data, |
|
|
uint16_t | len ) |
Transmit data, blocking until the transfer completes.
Starts a DMA transmission (see PHAL_USART_tx) and busy-waits until the USART reports the frame fully shifted out. Do not call from an ISR.
- Parameters
-
| periph_idx | Which USART peripheral to transmit on |
| data | Buffer to send |
| len | Number of bytes to send |
- Returns
- true if the transfer completed, false if it failed to start
- Parameters
-
| periph_idx | Which USART peripheral to transmit on |
| data | Buffer to send |
| len | Number of bytes to send |
- Returns
- true if the transfer completed, false if it failed to start
◆ PHAL_USART_txBusy()
Returns whether the USART peripheral is currently transmitting data.
Tracks the USART's own transmission-complete flag, so it stays true until the last bit has left the wire - not merely until the DMA has finished writing to the data register.
- Parameters
-
| periph_idx | Which USART peripheral to check |
- Returns
- true if the peripheral is currently sending a message, false otherwise
Returns whether the USART peripheral is currently transmitting data.
- Parameters
-
| periph_idx | Which USART peripheral to check |
- Returns
- true if a transmission is in flight, false otherwise