当前位置:网站首页>RT thread console device initialization
RT thread console device initialization
2022-06-13 05:02:00 【Snow * sleet * snow】
Today I am studying RT-Thread Log module ulog When I finally found log It is output through the console device , The console device is also a serial port device in nature , So I studied the serial port equipment .
So let's see log Output :
rt_device_t dev = rt_console_get_device();
rt_uint16_t old_flag = dev->open_flag;
dev->open_flag |= RT_DEVICE_FLAG_STREAM;
rt_device_write(dev, 0, log, len);
dev->open_flag = old_flag;
log Get before output console equipment , And then call rt_device_write Output . Then take a look at console Device initialization process .
#ifdef RT_USING_CONSOLE
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
The above code is in rt_hw_board_init() In the middle of . among RT_CONSOLE_DEVICE_NAME The definition is as follows :
#define RT_CONSOLE_DEVICE_NAME “uart1”
It can be seen that it is a serial port device , The specific initialization is as follows :
rt_device_t rt_console_set_device(const char *name)
{
rt_device_t new_device, old_device;
/* save old device */
old_device = _console_device;
/* find new console device */
new_device = rt_device_find(name);
/* check whether it's a same device */
if (new_device == old_device) return RT_NULL;
if (new_device != RT_NULL)
{
if (_console_device != RT_NULL)
{
/* close old console device */
rt_device_close(_console_device);
}
/* set new console device */
rt_device_open(new_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM);
_console_device = new_device;
}
return old_device;
}
RTM_EXPORT(rt_console_set_device);
From here, you can see that the console device is a serial port device .
Look back rt_hw_board_init() function
/* USART driver initialization is open by default */
#ifdef RT_USING_SERIAL
rt_hw_usart_init();
#endif
/* Set the shell console output device */
#ifdef RT_USING_CONSOLE
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
You can see that the serial port driver is initialized before initializing the console device . The specific code is as follows
int rt_hw_usart_init(void)
{
rt_size_t obj_num = sizeof(uart_obj) / sizeof(struct stm32_uart);
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
rt_err_t result = 0;
stm32_uart_get_dma_config();
for (int i = 0; i < obj_num; i++)
{
/* init UART object */
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;
}
Mainly look at this place uart_obj[i].config->name, Let's look for this name Where to define .
“uart_obj[i].config = &uart_config[i]”, From this line of code, we can see that the serial port configuration is in uart_config In this array . His definition is as follows :
tatic struct stm32_uart_config uart_config[] =
{
#ifdef BSP_USING_UART1
UART1_CONFIG,
#endif
#ifdef BSP_USING_UART2
UART2_CONFIG,
#endif
#ifdef BSP_USING_UART3
UART3_CONFIG,
#endif
#ifdef BSP_USING_UART4
UART4_CONFIG,
#endif
#ifdef BSP_USING_UART5
UART5_CONFIG,
#endif
#ifdef BSP_USING_UART6
UART6_CONFIG,
#endif
#ifdef BSP_USING_UART7
UART7_CONFIG,
#endif
#ifdef BSP_USING_UART8
UART8_CONFIG,
#endif
#ifdef BSP_USING_LPUART1
LPUART1_CONFIG,
#endif
};
We're going to use uart1, Then take a look at uart1 The definition of :
#define UART1_CONFIG \ {
\ .name = "uart1", \ .Instance = USART1, \ .irq_type = USART1_IRQn, \ }
The name is uart1, Look back rt_console_set_device(RT_CONSOLE_DEVICE_NAME), It is used to initialize the console device uart1 This serial port device .
边栏推荐
- 【线程/多线程】线程的执行顺序
- QT using layout manager is invalid or abnormal
- CMB written test graphical reasoning
- Kaggle time series tutorial
- josephus problem
- 无限循环滚动代码阿里巴巴国际站店铺装修代码底图滚动黑色半透明显示效果自定义内容装修代码全屏显示
- PostgreSQL Guide: inside exploration (Chapter 10 basic backup and point in time recovery) - Notes
- Luogu p1012 guess
- Little C's Notepad
- Cesium:cesiumlab makes image slices and loads slices
猜你喜欢

Advanced C - Section 2 - pointers

Advanced C - Section 3 - character functions and string functions

metaRTC4.0集成ffmpeg编译

Simple-SR:Best-Buddy GANs for Highly Detailed Image Super-Resolution论文浅析

System file interface open

LeetCode第297场周赛(20220612)

C language learning log 12.14

C language learning log 1.22

CMB's written test -- data analysis

Search DFS and BFS
随机推荐
Clause 26: avoid overloading universal reference types
QT signal is automatically associated with the slot
Chapter 13 abstraction: address space
[leetcode]- binary search
Simple-SR:Best-Buddy GANs for Highly Detailed Image Super-Resolution論文淺析
Mysql8.0.13 installation tutorial (with pictures)
Section 2 - branch and loop statements
Elliptic curve encryption
lookup
C language learning log 10.6
RMQ、LCA
Configuration used by automatic teaching evaluation script
Analysis of scoped attribute principle and depth action selector
Trust programming - linked lists: use struct to implement linked lists, use heap to merge K ascending linked lists, and customize display
[JS solution] leedcode 117 Populate the next right node pointer II for each node
关于匿名内部类
The games that you've tasted
C language learning log 2.6
BM1Z002FJ-EVK-001开机测评
【多线程编程】Future接口获取线程执行结果数据