当前位置:网站首页>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;
}
边栏推荐
- Derivation of anti Park transform and anti Clarke transform formulas for motor control
- Deno介绍
- 1.16 - 校验码
- My C language learning records (blue bridge) -- files and file input and output
- SAP ALV单元格级别设置颜色
- Mysql database operation
- Custom attribute access__ getattribute__/ Settings__ setattr__/ Delete__ delattr__ method
- svg拖动点裁剪图片js特效
- [risc-v] external interrupt
- Precautions for single chip microcomputer anti reverse connection circuit
猜你喜欢

OCR文字识别方法综述

My C language learning records (blue bridge) -- files and file input and output

Linear regression and logistic regression

OCR文字識別方法綜述

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

mysqldump数据备份

Mysql database operation

1.16 - 校验码
![[risc-v] external interrupt](/img/9d/eb1c27e14045d9f1f690f4a7f5c596.jpg)
[risc-v] external interrupt

MySQL advanced notes
随机推荐
Jenkins basic knowledge ----- detailed explanation of 03pipeline code
记录一下逆向任务管理器的过程
ASU & OSU | model based regularized off-line meta reinforcement learning
1003 emergency (25 points), "DIJ deformation"
The next industry outlet: NFT digital collection, is it an opportunity or a foam?
Modeling specifications: naming conventions
Research on cooperative control of industrial robots
JS音乐在线播放插件vsPlayAudio.js
深入刨析的指针(题解)
Derivation of anti Park transform and anti Clarke transform formulas for motor control
Pelosi: Congress will soon have legislation against members' stock speculation
Prototype design
Who is the winner of PTA
[padding] an error is reported in the prediction after loading the model weight attributeerror: 'model' object has no attribute '_ place‘
【RISC-V】外部中断
遥感图像超分辨率论文推荐
Explore pointers and pointer types in depth
Leetcode problem solving -- 98 Validate binary search tree
C language judgment, ternary operation and switch statement usage
Force buckle 1189 Maximum number of "balloons"