当前位置:网站首页>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;
}
边栏推荐
- Pytorch基础——(2)张量(tensor)的数学运算
- [rust notes] 18 macro
- Python implementation of maddpg - (1) openai maddpg environment configuration
- These are not very good
- 深入探究指针及指针类型
- Who is the winner of PTA
- 3857 Mercator coordinate system converted to 4326 (WGS84) longitude and latitude coordinates
- 数据分析——seaborn可视化(笔记自用)
- C language judgment, ternary operation and switch statement usage
- Handwriting database client
猜你喜欢

Era5 reanalysis data download strategy

Tomb. Weekly update of Finance (February 7 - February 13)

Overview of OCR character recognition methods

2.1 rtthread pin设备详解
![Buuctf question brushing notes - [geek challenge 2019] easysql 1](/img/37/c38a933ce7fa5d2b8fa597965ffcb2.png)
Buuctf question brushing notes - [geek challenge 2019] easysql 1

Eight super classic pointer interview questions (3000 words in detail)

Princeton University, Peking University & UIUC | offline reinforcement learning with realizability and single strategy concentration

Pytorch基础——(1)张量(tensor)的初始化

11. Container with the most water

MADDPG的pythorch实现——(1)OpenAI MADDPG环境配置
随机推荐
Overview of OCR character recognition methods
Record the process of reverse task manager
js凡客banner轮播图js特效
电机控制反Park变换和反Clarke变换公式推导
SAP ALV color code corresponding color (finishing)
Data and Introspection__ dict__ Attributes and__ slots__ attribute
IPv6 comprehensive experiment
Python implementation of maddpg - (1) openai maddpg environment configuration
Deno介绍
施努卡:3d视觉检测应用行业 机器视觉3d检测
Canvas cut blocks game code
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
Differences and application scenarios between resulttype and resultmap
NR modulation 1
three.js网页背景动画液态js特效
Precautions for single chip microcomputer anti reverse connection circuit
Leetcode problem solving -- 98 Validate binary search tree
. Net 6 and Net core learning notes: Important issues of net core
Pointer for in-depth analysis (problem solution)
Pytorch基础——(1)张量(tensor)的初始化