Internal Interface Wrap
API reference
Loading...
Searching...
No Matches
StmUart.h
Go to the documentation of this file.
1
13#pragma once
14
15#include "BaseUart.h"
16#include "StmTypes.h"
17
18#if defined(USE_HAL_DRIVER)
19#include "stm32h7xx_hal_uart.h"
20#else
21struct __UART_HandleTypeDef;
22typedef struct __UART_HandleTypeDef UART_HandleTypeDef;
23#endif
24
36class StmUart : public BaseUart {
37public:
38
44 explicit StmUart(UART_HandleTypeDef* huart,
45 hf_port_num_t port = 0) noexcept;
46
50 explicit StmUart(const hf_stm32_uart_config_t& config) noexcept;
51
52 ~StmUart() noexcept override;
53
54 // Non-copyable
55 StmUart(const StmUart&) = delete;
56 StmUart& operator=(const StmUart&) = delete;
57
58 // ── Pure-virtual overrides (BaseUart) ───────────────────────────────────
59 bool Initialize() noexcept override;
60 bool Deinitialize() noexcept override;
61 hf_uart_err_t Write(const hf_u8_t* data, hf_u16_t length,
62 hf_u32_t timeout_ms = 0) noexcept override;
63 hf_uart_err_t Read(hf_u8_t* data, hf_u16_t length,
64 hf_u32_t timeout_ms = 0) noexcept override;
65 hf_u16_t BytesAvailable() noexcept override;
66 hf_uart_err_t FlushTx() noexcept override;
67 hf_uart_err_t FlushRx() noexcept override;
68 int Printf(const char* format, ...) noexcept override;
69
70 // ── Accessors ───────────────────────────────────────────────────────────
71 UART_HandleTypeDef* GetHalHandle() const noexcept { return huart_; }
72
73 // ── Software RX ring buffer (optional — call EnableRxBuffer) ────────────
83 void EnableRxBuffer(hf_u8_t* buffer, hf_u16_t size) noexcept;
84
88 void FeedRxByte(hf_u8_t byte) noexcept;
89
93 void FeedRxBlock(const hf_u8_t* data, hf_u16_t length) noexcept;
94
95private:
98
99 // Software RX ring buffer
104};
Abstract base class for UART driver implementations in the HardFOC system.
hf_uart_err_t
Definition BaseUart.h:84
uint32_t hf_u32_t
Platform-agnostic 32-bit unsigned integer type.
Definition HardwareTypes.h:52
uint8_t hf_u8_t
Platform-agnostic 8-bit unsigned integer type.
Definition HardwareTypes.h:40
hf_u32_t hf_port_num_t
Platform-agnostic port/controller identifier type.
Definition HardwareTypes.h:120
uint16_t hf_u16_t
Platform-agnostic 16-bit unsigned integer type.
Definition HardwareTypes.h:46
STM32 platform-specific type definitions for hardware abstraction.
struct __UART_HandleTypeDef UART_HandleTypeDef
Definition StmUart.h:22
Abstract base class for UART driver implementations.
Definition BaseUart.h:191
STM32 UART implementation.
Definition StmUart.h:36
void EnableRxBuffer(hf_u8_t *buffer, hf_u16_t size) noexcept
Enable a software RX ring buffer.
Definition StmUart.cpp:259
hf_uart_err_t FlushTx() noexcept override
Flush the transmit buffer.
Definition StmUart.cpp:208
~StmUart() noexcept override
Definition StmUart.cpp:60
hf_uart_err_t FlushRx() noexcept override
Flush the receive buffer.
Definition StmUart.cpp:214
StmUart(const StmUart &)=delete
bool Initialize() noexcept override
Initialize the UART driver.
Definition StmUart.cpp:68
hf_u16_t BytesAvailable() noexcept override
Get the number of bytes available to read.
Definition StmUart.cpp:200
hf_uart_err_t Write(const hf_u8_t *data, hf_u16_t length, hf_u32_t timeout_ms=0) noexcept override
Write data to the UART.
Definition StmUart.cpp:102
hf_u8_t * rx_buf_
Definition StmUart.h:100
UART_HandleTypeDef * huart_
Definition StmUart.h:96
StmUart & operator=(const StmUart &)=delete
hf_u16_t rx_buf_size_
Definition StmUart.h:101
void FeedRxBlock(const hf_u8_t *data, hf_u16_t length) noexcept
Feed a block of bytes into the RX ring buffer (call from ISR/DMA).
Definition StmUart.cpp:278
volatile hf_u16_t rx_tail_
Read index (user reads)
Definition StmUart.h:103
UART_HandleTypeDef * GetHalHandle() const noexcept
Definition StmUart.h:71
volatile hf_u16_t rx_head_
Write index (ISR writes)
Definition StmUart.h:102
int Printf(const char *format,...) noexcept override
Printf-style formatted output.
Definition StmUart.cpp:238
hf_u32_t default_timeout_ms_
Definition StmUart.h:97
void FeedRxByte(hf_u8_t byte) noexcept
Feed a byte into the RX ring buffer (call from ISR).
Definition StmUart.cpp:266
hf_uart_err_t Read(hf_u8_t *data, hf_u16_t length, hf_u32_t timeout_ms=0) noexcept override
Read data from the UART.
Definition StmUart.cpp:125
bool Deinitialize() noexcept override
Deinitialize the UART driver.
Definition StmUart.cpp:91
Platform-agnostic UART configuration for STM32.
Definition StmTypes.h:422