当前位置:网站首页>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;
}
边栏推荐
- Python implementation of maddpg - (1) openai maddpg environment configuration
- Inherit day01
- 【paddle】加载模型权重后预测报错AttributeError: ‘Model‘ object has no attribute ‘_place‘
- 深度解析指针与数组笔试题
- jsscript
- Derivation of anti Park transform and anti Clarke transform formulas for motor control
- SAP ALV单元格级别设置颜色
- Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
- 2022工作中遇到的问题四
- 银行核心业务系统性能测试方法
猜你喜欢
适合程序员学习的国外网站推荐
【SLAM】lidar-camera外参标定(港大MarsLab)无需二维码标定板
OCR文字识别方法综述
Eight super classic pointer interview questions (3000 words in detail)
Analyze 菜单分析
XSS challenges bypass the protection strategy for XSS injection
ASU & OSU | model based regularized off-line meta reinforcement learning
Force buckle 1189 Maximum number of "balloons"
I sorted out a classic interview question for my job hopping friends
Analyze menu analysis
随机推荐
Performance test method of bank core business system
SD卡报错“error -110 whilst initialising SD card
NR modulation 1
What is the investment value of iFLYTEK, which does not make money?
ASU & OSU | model based regularized off-line meta reinforcement learning
1.16 - 校验码
Idea push rejected solution
codeforces每日5題(均1700)-第六天
Inherit day01
Buuctf question brushing notes - [geek challenge 2019] easysql 1
Deep parsing pointer and array written test questions
Descriptor implements ORM model
js凡客banner轮播图js特效
Analyze menu analysis
pytorch加载数据
SWC介绍
Derivation of anti Park transform and anti Clarke transform formulas for motor control
February 14, 2022 Daily: Google long article summarizes the experience of building four generations of TPU
Pytorch load data
[ruoyi] set theme style