当前位置:网站首页>3.1 rtthread 串口设备(V1)详解
3.1 rtthread 串口设备(V1)详解
2022-07-06 03:20:00 【rou252051452】
1、串口(UART)设备说明
rtthread通过serial.c和serial.h两个文件进行串口设备的管理。通过serial.h中的结构体rt_serial_device进行串口设备的定义,串口设备继承自设备基类rt_device,rt_device继承自rt_object基类,继承关系如下

串口设备通过结构体的定义实现了对rt_device设备基类的继承,结构体的私有成员据定了串口设备的相关操作。
struct rt_serial_device
{
struct rt_device parent;
const struct rt_uart_ops *ops;
struct serial_configure config;
void *serial_rx;
void *serial_tx;
};
typedef struct rt_serial_device rt_serial_t;2、串口设备的初始化及注册

启动阶段rtthread会根据是否进行了RT_USING_SERIAL定义,在hw_board_init函数中进行串口设备的初始化,在rt_hw_usart_init函数中进行DMA和串口的相关配置参数,最终调用函数rt_hw_serial_register来实现STM32的串口设备的关联及设备的挂载。
int rt_hw_usart_init(void)
{
/*
进行串口设备数量计算
1、drv_uasrt.c文件进行了struct stm32_uart类型数组uart_obj的定义,
数组的个数有宏定义BSP_USING_UARTx的数量决定。
*/
rt_size_t obj_num = sizeof(uart_obj) / sizeof(struct stm32_uart);
/*
配置信息进行默认值赋值,115200-8-n-1
*/
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
rt_err_t result = 0;
/*
根据宏定义进行DMA的相关配置信息初始化
*/
stm32_uart_get_dma_config();
/*
根据串口数量进行相应串口外设的挂载
*/
for (int i = 0; i < obj_num; i++)
{
uart_obj[i].config = &uart_config[i];
uart_obj[i].serial.ops = &stm32_uart_ops;
uart_obj[i].serial.config = config;
/* register UART device */
result = rt_hw_serial_register(&uart_obj[i].serial, uart_obj[i].config->name,
RT_DEVICE_FLAG_RDWR
| RT_DEVICE_FLAG_INT_RX
| RT_DEVICE_FLAG_INT_TX
| uart_obj[i].uart_dma_flag
, NULL);
RT_ASSERT(result == RT_EOK);
}
return result;
}
边栏推荐
- 深度解析指针与数组笔试题
- 【SLAM】ORB-SLAM3解析——跟踪Track()(3)
- StrError & PERROR use yyds dry inventory
- Four logs of MySQL server layer
- jsscript
- Redis SDS principle
- MADDPG的pythorch实现——(1)OpenAI MADDPG环境配置
- 【SLAM】lidar-camera外参标定(港大MarsLab)无需二维码标定板
- Precautions for single chip microcomputer anti reverse connection circuit
- Leetcode problem solving -- 99 Restore binary search tree
猜你喜欢
随机推荐
JS音乐在线播放插件vsPlayAudio.js
MySQL Server层四个日志
Recommended foreign websites for programmers to learn
Arabellacpc 2019 (supplementary question)
OCR文字识别方法综述
【paddle】加载模型权重后预测报错AttributeError: ‘Model‘ object has no attribute ‘_place‘
mysqldump数据备份
SD卡报错“error -110 whilst initialising SD card
Web security SQL injection vulnerability (1)
适合程序员学习的国外网站推荐
银行核心业务系统性能测试方法
3857墨卡托坐标系转换为4326 (WGS84)经纬度坐标
jsscript
深度解析指针与数组笔试题
Descriptor implements ORM model
蓝色样式商城网站页脚代码
SD卡報錯“error -110 whilst initialising SD card
1.16 - 校验码
Pytorch基础——(1)张量(tensor)的初始化
Inherit day01
![BUUCTF刷题笔记——[极客大挑战 2019]EasySQL 1](/img/37/c38a933ce7fa5d2b8fa597965ffcb2.png)








