当前位置:网站首页>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 .
边栏推荐
- Configuration used by automatic teaching evaluation script
- Article 29: assuming that the mobile operation does not exist, is expensive, and is not used
- QT interface rendering style
- metaRTC4.0稳定版发布
- Must know must know -c language keywords
- MySQL8.0.13安装教程(有图)
- C language learning log 1.2
- RuoYi-Cloud启动教程(手把手图文)
- Solution to sudden font change in word document editing
- Analysis of the principle of V-model and its application in user defined components
猜你喜欢
Explain the role of key attribute in V-for
Bm1z002fj-evk-001 startup evaluation
OpenCV中的saturate操作(饱和操作)究竟是怎么回事
Article 29: assuming that the mobile operation does not exist, is expensive, and is not used
QT brushes and brushes
C language learning log 1.24
Stepping on a horse (one stroke)
QT signal is automatically associated with the slot
QT client development -- driver loading problem of connecting to MySQL database
Must know must know -c language keywords
随机推荐
All blog navigation
2021tami/ image processing: exploiting deep generative priority for versatile image restoration and manipulation
QT signal is automatically associated with the slot
Win8.1和Win10各自的优势
Simple sr: Best Buddy Gans for highly detailed image super resolution Paper Analysis
【线程/多线程】线程的执行顺序
Flex布局自适应失效的问题
About mission planning and improving execution
Spice story
External sort
Recursion and recursion
PostgreSQL Guide: Insider exploration (Chapter 7 heap tuples and index only scanning) - Notes
Several methods of identifying equivalent circuit of circuit drawing
[JS solution] leedcode 117 Populate the next right node pointer II for each node
Advantages of win8.1 and win10
Avantages de win8.1 et win10
Explain the differences and usage scenarios between created and mounted
Embedded hardware - read schematic
C # get all callable methods of WebService interface [webmethod]
Violence enumeration~