rtthread uses uart peripherals (bsp and env tools are not required)

This exercise is to use rttthread studio to write the uart peripheral driver. At the end of the article, there is a link to a routine that does not require integration. The SDK version of f103 is 0.1.9 (check it in the studio's package manager). To import my routines, please refer to how to import Engineering , I wish you success.
Insert picture description here
The console in the picture is the terminal for debugging. The MCU debugging is usually printf(), and rt_kprintf() is used in rtthread. After configuring the interface in the above picture, you can use the serial port of PA9 and PA10 to see the following debugging information:
1 , Rt_kprint() debugging information
2. LOG log information
You can also execute the finsh command. The rtt studio has a putty terminal, as follows. The terminal is
Insert picture description here
introduced for a while, let’s get back to business, how to use uart peripherals?
There is the hardware uart initialization function rt_hw_usart_init() in drv_common.c, enter the function definition, you will see all uart peripherals registered in the
Insert picture description here
for loop , the number of uart is calculated by sizeof(uart_obj)/sizeof(struct stm32_uart). Direct operation method Add the pin definition of uart2 and #define BSP_USING_UART2 in the board.h file, just compile it, and the iic and spi peripherals have not been tried. This time learning the process of registering equipment is also rewarding.
Insert picture description here

Insert picture description here

I have limited energy and did not do the flowchart. Hope you Haihan, comment in the comment area if you have any questions, I will reply when I see it, and learn and make progress together.
Update 2021/2/10 I
spent a day researching the driver development method of rtthread, and went back to look at the development documentation of rtthread. My above approach can be successful, as mentioned in the manual. If developers want to learn rtthread, they should visit the rtt documentation center more. Now
start to redo it again using a scientific method, and finally find that learning should start with the manual, without talking nonsense, just start.
There are only two steps

  1. New rtthread full version project
  2. Add the macro #define BSP_USING_UART1 and the input and output pins TX/RX to open the uart peripheral in board.c, see the figure below to
    Insert picture description here
    compile and download, you can verify it, let me summarize: the automatic implementation mechanism of rtthread is the same as the standard library configuration of stm32 stm32_xxxx_hal_config Like the .h file, you can enable the corresponding macro for whatever function is needed. The method used in this example is the macro #define BSP_USING_UART2, and there are two more TX/RX pin configuration macros and you are done.
    The effect is as follows. I typed the example code of uart peripherals in the rttread programming manual into the main.c file, and PA2\PA3 connects to the serial port to USB. The effect is as follows:
    Insert picture description here
    routine link

Guess you like

Origin blog.csdn.net/weixin_43810563/article/details/113765406