当前位置:网站首页>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;
}
边栏推荐
- Prototype design
- Deep parsing pointer and array written test questions
- Audio audiorecord binder communication mechanism
- resulttype和resultmap的区别和应用场景
- Sign SSL certificate as Ca
- 如何做好功能测试
- My C language learning record (blue bridge) -- on the pointer
- Linear programming matlab
- EDCircles: A real-time circle detector with a false detection control 翻译
- Mysqldump data backup
猜你喜欢

Derivation of anti Park transform and anti Clarke transform formulas for motor control

What is the investment value of iFLYTEK, which does not make money?

深入探究指针及指针类型

Linear regression and logistic regression

StrError & PERROR use yyds dry inventory

Mysqldump data backup

2022工作中遇到的问题四

SAP ALV单元格级别设置颜色

codeforces每日5题(均1700)-第六天

XSS challenges bypass the protection strategy for XSS injection
随机推荐
JS regular filtering and adding image prefixes in rich text
深入刨析的指针(题解)
February 14, 2022 Daily: Google long article summarizes the experience of building four generations of TPU
继承day01
Eight super classic pointer interview questions (3000 words in detail)
Tomb. Weekly update of Finance (February 7 - February 13)
Tidb ecological tools (backup, migration, import / export) collation
ERA5再分析资料下载攻略
Getting started with applet cloud development - getting user search content
SD card reports an error "error -110 whilst initializing SD card
Modeling specifications: naming conventions
Some problem records of AGP gradle
JS音乐在线播放插件vsPlayAudio.js
Arabellacpc 2019 (supplementary question)
Cross origin cross domain request
建模规范:命名规范
EDCircles: A real-time circle detector with a false detection control 翻译
遥感图像超分辨率论文推荐
如何做好功能测试
Pelosi: Congress will soon have legislation against members' stock speculation