优化实现串口驱动,SPI驱动 W25QXX还需要初始化验证修复

This commit is contained in:
冯佳
2026-01-23 09:59:43 +08:00
parent 51e8d79f78
commit b166bee1a9
69 changed files with 6253 additions and 1178 deletions

View File

@ -8,12 +8,57 @@ UART模块用于实现串口通信功能支持数据发送和接收提供
## 接口说明
### 枚举类型
#### hal_uart_parity_t
UART校验位枚举
```c
typedef enum {
HAL_UART_PARITY_NONE = 0U, /*!< 无奇偶校验 */
HAL_UART_PARITY_ODD = 1U, /*!< 奇校验 */
HAL_UART_PARITY_EVEN = 2U /*!< 偶校验 */
} hal_uart_parity_t;
```
#### hal_uart_stopbits_t
UART停止位枚举
```c
typedef enum {
HAL_UART_STOPBITS_1 = 0U, /*!< 1位停止位 */
HAL_UART_STOPBITS_2 = 1U /*!< 2位停止位 */
} hal_uart_stopbits_t;
```
#### hal_uart_databits_t
UART数据位枚举
```c
typedef enum {
HAL_UART_DATABITS_8 = 0U, /*!< 8位数据位 */
HAL_UART_DATABITS_9 = 1U /*!< 9位数据位 */
} hal_uart_databits_t;
```
#### hal_uart_instance_t
UART实例枚举
```c
typedef enum {
HAL_UART_INSTANCE_1 = 0U, /*!< UART1实例 */
HAL_UART_INSTANCE_2, /*!< UART2实例 */
HAL_UART_INSTANCE_3, /*!< UART3实例 */
HAL_UART_INSTANCE_4, /*!< UART4实例 */
HAL_UART_INSTANCE_5, /*!< UART5实例 */
HAL_UART_INSTANCE_6, /*!< UART6实例 */
HAL_UART_INSTANCE_MAX /*!< 实例数量最大值 */
} hal_uart_instance_t;
```
### 数据结构
#### uart_config_t
UART配置结构体用于初始化UART模块
```c
typedef struct {
hal_uart_instance_t instance; /*!< UART实例 */
uint32_t baudrate; /*!< 波特率 */
hal_uart_parity_t parity; /*!< 校验位 */
hal_uart_stopbits_t stopbits; /*!< 停止位 */
@ -36,12 +81,19 @@ typedef struct {
```c
void uart_init(void);
```
初始化UART模块
初始化UART模块,设置默认配置
**参数**:无
**返回值**:无
**默认配置**
- 实例HAL_UART_INSTANCE_1
- 波特率115200
- 校验位HAL_UART_PARITY_NONE
- 停止位HAL_UART_STOPBITS_1
- 数据位HAL_UART_DATABITS_8
#### uart_config
```c
void uart_config(const uart_config_t *config);
@ -118,6 +170,16 @@ uint8_t uart_is_rx_ready(void);
/* 初始化UART模块 */
uart_init();
/* 配置UART参数 */
uart_config_t config = {
.instance = HAL_UART_INSTANCE_1,
.baudrate = 115200,
.parity = HAL_UART_PARITY_NONE,
.stopbits = HAL_UART_STOPBITS_1,
.databits = HAL_UART_DATABITS_8
};
uart_config(&config);
/* 发送字符串 */
uart_send_string("Hello, UART!\r\n");