/**
* @file usart2.c
* @author zhaoguangxin (zhaoguangxin@qq.com)
* @brief
* @version 0.1
* @date 2022-08-25
*
* @copyright Copyright (c) 2022
*
*/
#include <rtthread.h>
#include <string.h>
#include <serial.h>
/* 设备句柄 */
#define UART_NAME "uart2"
static rt_device_t serial;
/* 消息传递队列 */
#define USART2_QUE_NUM (10)
static struct rt_messagequeue rx_que;
typedef struct{
rt_uint32_t p_read; //开始读取地址
rt_uint32_t p_end; //读取的结束地址
}Rx_Index_t;
static rt_uint8_t msg_pool[sizeof(Rx_Index_t) * USART2_QUE_NUM];
/* FIFO */
#define USART2_RX_MAX (1024UL)
typedef struct{
rt_uint32_t wIndex;
rt_uint32_t rIndex;
rt_uint8_t overFlag;
rt_uint8_t *fifo;
}Rx_FIFO_t;
static Rx_FIFO_t usart2FIFO;
/* 分帧定时器 */
static struct rt_timer firTimer;
static rt_uint8_t timerStatus = 0; //0未启动 1:启动
/**
* @name: firTimer_timeout
* @func: 分帧定时器回调函数
* @input:
* parameter:参数
* @output: none
STM32+RTThread串口不定长接收
最新推荐文章于 2025-09-17 12:21:47 发布
本文介绍了一个基于RT-Thread系统的UART2模块实现细节,包括串口接收、数据处理和分帧定时等功能。通过使用消息队列、FIFO缓冲区和定时器等机制实现了可靠的数据收发。

最低0.47元/天 解锁文章
834

被折叠的 条评论
为什么被折叠?



