libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
stm32_uart.hpp
1#pragma once
2
3#include "main.h"
4
5#ifdef HAL_UART_MODULE_ENABLED
6
7#ifdef UART
8#undef UART
9#endif
10
11#include "double_buffer.hpp"
12#include "flag.hpp"
13#include "libxr_def.hpp"
14#include "libxr_rw.hpp"
15#include "uart.hpp"
16
17typedef enum : uint8_t
18{
19#ifdef USART1
20 STM32_USART1,
21#endif
22#ifdef USART2
23 STM32_USART2,
24#endif
25#ifdef USART3
26 STM32_USART3,
27#endif
28#ifdef USART4
29 STM32_USART4,
30#endif
31#ifdef USART5
32 STM32_USART5,
33#endif
34#ifdef USART6
35 STM32_USART6,
36#endif
37#ifdef USART7
38 STM32_USART7,
39#endif
40#ifdef USART8
41 STM32_USART8,
42#endif
43#ifdef USART9
44 STM32_USART9,
45#endif
46#ifdef USART10
47 STM32_USART10,
48#endif
49#ifdef USART11
50 STM32_USART11,
51#endif
52#ifdef USART12
53 STM32_USART12,
54#endif
55#ifdef USART13
56 STM32_USART13,
57#endif
58#ifdef UART1
59 STM32_UART1,
60#endif
61#ifdef UART2
62 STM32_UART2,
63#endif
64#ifdef UART3
65 STM32_UART3,
66#endif
67#ifdef UART4
68 STM32_UART4,
69#endif
70#ifdef UART5
71 STM32_UART5,
72#endif
73#ifdef UART6
74 STM32_UART6,
75#endif
76#ifdef UART7
77 STM32_UART7,
78#endif
79#ifdef UART8
80 STM32_UART8,
81#endif
82#ifdef UART9
83 STM32_UART9,
84#endif
85#ifdef UART10
86 STM32_UART10,
87#endif
88#ifdef UART11
89 STM32_UART11,
90#endif
91#ifdef UART12
92 STM32_UART12,
93#endif
94#ifdef UART13
95 STM32_UART13,
96#endif
97#ifdef LPUART1
98 STM32_LPUART1,
99#endif
100#ifdef LPUART2
101 STM32_LPUART2,
102#endif
103#ifdef LPUART3
104 STM32_LPUART3,
105#endif
106 STM32_UART_NUMBER,
107 STM32_UART_ID_ERROR
108} stm32_uart_id_t;
109
110stm32_uart_id_t stm32_uart_get_id(USART_TypeDef* addr);
111
112namespace LibXR
113{
117class STM32UART : public UART
118{
119 public:
120 static ErrorCode WriteFun(WritePort& port, bool in_isr);
121
122 static ErrorCode ReadFun(ReadPort& port, bool in_isr);
123
127 STM32UART(UART_HandleTypeDef* uart_handle, RawData dma_buff_rx, RawData dma_buff_tx,
128 uint32_t tx_queue_size = 5);
129
130 ErrorCode SetConfig(UART::Configuration config);
131
132 void SetRxDMA();
133
134 ReadPort _read_port;
135 WritePort _write_port;
136
137 RawData dma_buff_rx_;
138 DoubleBuffer dma_buff_tx_;
139 WriteInfoBlock write_info_active_;
140
141 size_t last_rx_pos_ = 0;
142
143 UART_HandleTypeDef* uart_handle_;
144
145 Flag::Plain in_tx_isr, tx_busy_;
146
147 stm32_uart_id_t id_ = STM32_UART_ID_ERROR;
148
149 static STM32UART* map[STM32_UART_NUMBER]; // NOLINT
150};
151
152} // namespace LibXR
153
154#endif
双缓冲区管理类 / Double buffer manager class
普通标志位(非原子)/ Non-atomic flag
Definition flag.hpp:115
原始数据封装类。 A class for encapsulating raw data.
ReadPort class for handling read operations.
Definition libxr_rw.hpp:272
STM32 UART 驱动实现 / STM32 UART driver implementation.
STM32UART(UART_HandleTypeDef *uart_handle, RawData dma_buff_rx, RawData dma_buff_tx, uint32_t tx_queue_size=5)
构造 UART 对象 / Construct UART object
ErrorCode SetConfig(UART::Configuration config)
设置 UART 配置 / Sets the UART configuration
通用异步收发传输(UART)基类 / Abstract base class for Universal Asynchronous Receiver-Transmitter (UART)
Definition uart.hpp:19
WritePort class for handling write operations.
Definition libxr_rw.hpp:413
LibXR 命名空间
Definition ch32_can.hpp:14
ErrorCode(* ReadFun)(ReadPort &port, bool in_isr)
Function pointer type for read operations.
Definition libxr_rw.hpp:249
ErrorCode(* WriteFun)(WritePort &port, bool in_isr)
Function pointer type for write operations.
Definition libxr_rw.hpp:245
UART 配置结构体 / UART configuration structure.
Definition uart.hpp:44