当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Analyze 菜单分析
Web security SQL injection vulnerability (1)
Performance analysis of user login TPS low and CPU full
Princeton University, Peking University & UIUC | offline reinforcement learning with realizability and single strategy concentration
canvas切积木小游戏代码
Linear programming matlab
Era5 reanalysis data download strategy
IPv6 comprehensive experiment
I sorted out a classic interview question for my job hopping friends
My C language learning record (blue bridge) -- on the pointer
随机推荐
What are the principles of software design (OCP)
Detailed use of dbutils # yyds dry goods inventory #
Performance analysis of user login TPS low and CPU full
[unity3d] GUI control
Codeworks 5 questions per day (1700 average) - day 6
Idea push rejected solution
Data and Introspection__ dict__ Attributes and__ slots__ attribute
MySQL Server层四个日志
Analyze 菜单分析
StrError & PERROR use yyds dry inventory
Polymorphic day02
3857 Mercator coordinate system converted to 4326 (WGS84) longitude and latitude coordinates
MySQL advanced notes
Redo file corruption repair
Leetcode problem solving -- 173 Binary search tree iterator
Mysql database operation
February 14, 2022 Daily: Google long article summarizes the experience of building four generations of TPU
Deno介绍
Image super-resolution using deep convolutional networks(SRCNN)解读与实现
Prototype design