当前位置:网站首页>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;
}
边栏推荐
- [Li Kou] the second set of the 280 Li Kou weekly match
- 出现Permission denied的解决办法(750权限谨慎使用)
- 3857墨卡托坐标系转换为4326 (WGS84)经纬度坐标
- Distributed service framework dobbo
- . Net 6 and Net core learning notes: Important issues of net core
- Map sorts according to the key value (ascending plus descending)
- 【SLAM】ORB-SLAM3解析——跟踪Track()(3)
- Redis SDS principle
- IPv6 comprehensive experiment
- three.js网页背景动画液态js特效
猜你喜欢

【SLAM】lidar-camera外参标定(港大MarsLab)无需二维码标定板

Tomb. Weekly update of Finance (February 7 - February 13)

Idea push rejected solution

Sign SSL certificate as Ca
![[pointer training - eight questions]](/img/fd/1aa3937548a04078c4d7e08198c3a8.png)
[pointer training - eight questions]

IPv6 jobs

适合程序员学习的国外网站推荐

MySQL advanced notes

Microsoft Research, UIUC & Google research | antagonistic training actor critic based on offline training reinforcement learning

Recommended foreign websites for programmers to learn
随机推荐
Pytorch基础——(1)张量(tensor)的初始化
SD card reports an error "error -110 whilst initializing SD card
Computer graduation project asp Net fitness management system VS development SQLSERVER database web structure c programming computer web page source code project
Redis SDS principle
Codeworks 5 questions per day (1700 average) - day 6
Map sorts according to the key value (ascending plus descending)
canvas切积木小游戏代码
手写数据库客户端
JS regular filtering and adding image prefixes in rich text
XSS challenges bypass the protection strategy for XSS injection
[risc-v] external interrupt
Web security SQL injection vulnerability (1)
下一个行业风口:NFT 数字藏品,是机遇还是泡沫?
Descriptor implements ORM model
Huawei, H3C, Cisco command comparison, mind map form from the basic, switching, routing three directions [transferred from wechat official account network technology alliance station]
Getting started with applet cloud development - getting user search content
IPv6 jobs
指针笔试题~走近大厂
Buuctf question brushing notes - [geek challenge 2019] easysql 1
Tomb. Weekly update of Finance (February 7 - February 13)