当前位置:网站首页>3.1 detailed explanation of rtthread serial port device (V1)
3.1 detailed explanation of rtthread serial port device (V1)
2022-07-06 03:25:00 【rou252051452】
1、 A serial port (UART) Equipment description
rtthread adopt serial.c and serial.h Two files are used to manage serial port devices . adopt serial.h Structural body in rt_serial_device Define serial port equipment , The serial port device inherits from the device base class rt_device,rt_device Inherited from rt_object Base class , The inheritance relationship is as follows

The serial port device realizes the function of rt_device Inheritance of device base class , The private member of the structure determines the relevant operations of the serial port 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、 Initialization and registration of serial port devices

Start-up phase rtthread It will be based on whether RT_USING_SERIAL Definition , stay hw_board_init Function to initialize the serial port device , stay rt_hw_usart_init In function DMA And serial port related configuration parameters , Finally call the function rt_hw_serial_register To achieve STM32 Serial port device association and device mounting .
int rt_hw_usart_init(void)
{
/*
Calculate the number of serial port devices
1、drv_uasrt.c The document went on struct stm32_uart Type array uart_obj The definition of ,
The number of arrays has macro definitions BSP_USING_UARTx It's the number of .
*/
rt_size_t obj_num = sizeof(uart_obj) / sizeof(struct stm32_uart);
/*
Assign the default value to the configuration information ,115200-8-n-1
*/
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
rt_err_t result = 0;
/*
According to macro definition DMA Initialization of relevant configuration information
*/
stm32_uart_get_dma_config();
/*
Mount the corresponding serial port peripherals according to the number of serial ports
*/
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 menu analysis
- 电机控制反Park变换和反Clarke变换公式推导
- Leetcode problem solving -- 98 Validate binary search tree
- MADDPG的pythorch实现——(1)OpenAI MADDPG环境配置
- Tomb. Weekly update of Finance (February 7 - February 13)
- 施努卡:视觉定位系统 视觉定位系统的工作原理
- SWC introduction
- SAP ALV颜色代码对应颜色(整理)
- BUUCTF刷题笔记——[极客大挑战 2019]EasySQL 1
- SAP ALV cell level set color
猜你喜欢

2.2 STM32 GPIO操作

2022工作中遇到的问题四

Performance test method of bank core business system

深入探究指针及指针类型
![[Li Kou] the second set of the 280 Li Kou weekly match](/img/8a/9718c38242f6f6f9637123dc4f3d8a.jpg)
[Li Kou] the second set of the 280 Li Kou weekly match

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

ESBuild & SWC浅谈: 新一代构建工具

Pytorch load data

2.2 fonctionnement stm32 GPIO

Eight super classic pointer interview questions (3000 words in detail)
随机推荐
Advanced learning of MySQL -- Fundamentals -- isolation level of transactions
MPLS experiment
Pointer written test questions ~ approaching Dachang
2.1 rtthread pin设备详解
Force buckle 1189 Maximum number of "balloons"
resulttype和resultmap的区别和应用场景
Tidb ecological tools (backup, migration, import / export) collation
下一个行业风口:NFT 数字藏品,是机遇还是泡沫?
jsscript
继承day01
适合程序员学习的国外网站推荐
three. JS page background animation liquid JS special effect
3.1 rtthread 串口设备(V1)详解
Audio-AudioRecord Binder通信机制
Item 10: Prefer scoped enums to unscoped enums.
Performance analysis of user login TPS low and CPU full
Pytorch基础——(2)张量(tensor)的数学运算
施努卡:什么是视觉定位系统 视觉系统如何定位
3.2 rtthread 串口设备(V2)详解
mysqldump数据备份