当前位置:网站首页>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;
}
边栏推荐
- 3857墨卡托坐标系转换为4326 (WGS84)经纬度坐标
- Python implementation of maddpg - (1) openai maddpg environment configuration
- Résumé des méthodes de reconnaissance des caractères ocr
- Getting started with applet cloud development - getting user search content
- svg拖动点裁剪图片js特效
- MySQL Server层四个日志
- Advanced learning of MySQL -- Fundamentals -- isolation level of transactions
- Four logs of MySQL server layer
- Polymorphic day02
- MySQL advanced notes
猜你喜欢
[concept] Web basic concept cognition
下一个行业风口:NFT 数字藏品,是机遇还是泡沫?
C # create self host webservice
My C language learning record (blue bridge) -- on the pointer
How to choose PLC and MCU?
Buuctf question brushing notes - [geek challenge 2019] easysql 1
指针笔试题~走近大厂
Web security SQL injection vulnerability (1)
Recommended foreign websites for programmers to learn
真机无法访问虚拟机的靶场,真机无法ping通虚拟机
随机推荐
深入探究指针及指针类型
Analyze 菜单分析
遥感图像超分辨率论文推荐
建模规范:命名规范
2022工作中遇到的问题四
教你用Pytorch搭建一个自己的简单的BP神经网络( 以iris数据集为例 )
暑期刷题-Day3
EDCircles: A real-time circle detector with a false detection control 翻译
Force buckle 1189 Maximum number of "balloons"
These are not very good
Computer graduation project asp Net fitness management system VS development SQLSERVER database web structure c programming computer web page source code project
Erreur de la carte SD "erreur - 110 whilst initialisation de la carte SD
ERA5再分析资料下载攻略
Linear programming matlab
Who is the winner of PTA
Exness foreign exchange: the governor of the Bank of Canada said that the interest rate hike would be more moderate, and the United States and Canada fell slightly to maintain range volatility
XSS challenges绕过防护策略进行 XSS 注入
Analyze menu analysis
Selenium share
NR modulation 1