RT-Thread studio usage (continuous updates)

Article directory


  • Official RT-Thread Studio user manual: (interface introduction, compilation, downloading, debugging, project import and other official documentation instructions)
    RT-Thread Studio user manual

============================================================

1. Download and install RT-Thread studio

1-1. Download the installation package from the official website:

RT-Thread Official Download Center
The Document Center talks about several methods of transplanting the nano version. Open the transplant using RT-Thread_Studio, choose to install RT-Thread_Studio, jump to the official website, scroll to the bottom, click RT-Thread nano, and select download
Insert image description here
Insert image description here
Insert image description here
. Can;

1-2. Installation:

Insert image description here
Check the protocol:
Insert image description here
Select the location you want to install:
Insert image description here
Insert image description here
Start installing
Insert image description here
the v2.2.4 version. The installation prompts that renaming a certain file failed. . . . . , try the next v2.2.3 version: (v2.2.3 version still reports the same error)
Insert image description here
Solution: Finally, it was found that it was an installation path problem. . . It was installed successfully in the default root directory of drive D. I was really speechless! (This phenomenon was installed on my own computer with a customized path, but this error did not occur. I don’t know the reason, but it will be solved)

1-3. Register and log in:

After registering and logging in, you can start using it;
Insert image description here

2. Create a new RT-Thread nano project

2-1. Create a new nano project

2-1-1. Open file -> New -> RT-Thread Nano project:
Insert image description here
2-2-2. New project configuration items:
1>, set project name
2>, project save path
3>, create based on chip, nano Version selection
4>, chip selection
5>, serial console and pin configuration
6>, debugging configuration.
After all configurations are completed, the nano project code is automatically generated;
Note:
1. I chose to run on stm32f103c8t6 first, so the 4th and The 5 configurations should be configured according to the actual situation.
2. Configure the clock. The default is to use the internal HSI clock. You can modify it in the file drv_clk.c
Insert image description here
later. The serial port 1 of stm32f103c8t6 is used as the debugging serial port:
stm32f103c8t6 data manual looks at usart1 as the debug port
2-1-3. After generating the project, as follows: After selecting Xiaomai debug, there are 0 errors and 0 warnings during compilation;

Insert image description here

2-2. Connect the hardware and download it to the board for testing (stm32f103c8t6 is selected)

2-2-1. Download to the stm32f103c8t6 minimum system board.
Insert image description here
A window pops up and the download continues.
Problem solved: Hey, this is the first time I use j-link ob on this computer, but the driver is not installed. After installing the driver, the download is normal;
About For j-link problem solving, check the blog: j-link usage (continuous updates)
Insert image description here
2-2-2. Open the serial port terminal in RT-Thread studio, and you can see the content output to the serial port implemented in the code; the
generated code main The function prints strings to the serial port regularly. Since the serial port number and pin number of the console serial port are configured when configuring the project, the serial port driver and rt_hw_console_output() are automatically implemented in the project, and printing can be performed by default ;
Insert image description here

3. File interpretation of nano projects created with RT-Thread studio

pending upgrade

4. Add Finsh based on RT-Thread nano (to realize command input)

4-1. What is Finsh?

RT-Thread FinSH is the command line component (shell) of RT-Thread. It provides a set of operation interfaces for users to call on the command line. It is mainly used for debugging or viewing system information. It can communicate with PC using serial port/Ethernet/USB, etc.;

4-2. Add FinSH based on Nano (using RT-Thread studio)

4-2-1. Double-click RT-Thread Settings to enter the configuration, open the component, check FinSH Shell, and save the configuration. This operation will add the source code of the FinSH component to the project. Among them, rt_hw_console_getchar() has been implemented in drv_uart.c, and there is no need to implement the code to interface with FinSH.

After opening the component as follows, you can use the FinSH function.
Insert image description here
4-1-2. Link the hardware. When recompiling and downloading, press the tab key in the terminal in the RT-Thread studio software to view the commands in the system:

Under normal circumstances, command line input can be realized, but there is no response after the tab key:
Insert image description here
Problem solution:
Do not block rt_thread_mdelay(1000); (It should be that the program has fallen into an infinite loop, and now RT-Thread is not blocked. Familiar, I will come back later to explain the reasons)

Insert image description here

5. [Question] How to use RT-Thread studio to open the created RT-Thread project;

Problem description:
Insert image description here
Problem solution:
RT-Thread studio [Problem] How to use RT-Thread studio to open the created RT-Thread project;

6. [Question] How to find and open specified content

1. Search:
Insert image description here
2. Open element:
Insert image description here

7. [Question] How to add your own path and source file header file (SConscript and SConstruct) to the project (not perfect)

See your own blog

8. After creating a new RT-Thread project, use cubemx to reconfigure parameters (clock, serial port, etc.)

Reference blog link:
RT-Thread Studio and CubeMX joint programming (super detailed)

8-1. cubemx configuration:

Open the plug-in in the project (the stm32cubemx software must be installed first) to configure it. For the installation and configuration of the software, see the following blog link:
Insert image description here

stm32cubeMX use

After configuration, close the cubemx software, then enter RT-Thread studio and this window will pop up, prompting that the
original stm32f1xx_hal_conf.h file was generated and renamed, call the file generated by cubemx, and click OK;
Insert image description here
Insert image description here

8-2. After using cubemx to generate the project, you need to close the software;

8-2-1. After opening the cubemx plug-in configuration project in the RT-Thread studio software, you must close the cubemx software so that the RT-Thread studio software can operate normally.
Insert image description here

8-3. Analysis of the files generated after reconfiguring with cubemx:

Insert image description here
As shown in the picture above, cubemx generates the folder cubemx, which contains header files and source files, especially a main.c. So which main.c should we use to execute our user code?

Let’s continue to the next step and perform compilation first;

8-4. Solving errors reported after compilation

After compiling directly, 21 errors are reported. . .
Insert image description here
Solution steps:

8-4-1. You need to use the SConscript file to tell the compiler that the cubemx generated needs to be compiled.

There is a SConscript file generated in the cubumx folder. If you have not created one yourself, the SConscript file you generated has already included the path to the generated file.
Insert image description here

import os   #引入os模块
from building import *    #导入building的所有模块

cwd = GetCurrentDir()	#获取获取当前路径,并保存至变量cwd
src  = Glob('*.c')	#获取当前目录下的所有 C 文件,并保存至src变量

# add cubemx drivers 
#由于RT-Thread工程中存在部分相同函数文件,所以对src重新赋值
#文件中的stm32g4xx_it.c 、 system_stm32g4xx.c不加入构建
#其余文件按相同格式填写到下述括号内

src = Split('''
Src/stm32f1xx_hal_msp.c
Src/main.c
''')

path = [cwd]    #创建路径列表,并保存至path中
path += [cwd + '/Inc']	

group = DefineGroup('cubemx', src, depend = [''], CPPPATH = path)  #这是 RT-Thread 基于 SCons 扩展的一个方法(函数)。

Return('group')

8-4-2. Right-click SConscript to update the software package

Update packages! Very important! Don't miss it
Insert image description here

8-5. Weak the main function generated by cubemx, and then call the function generated by cubemx under applications:

8-5-1. Weak the main function generated by cubemx:

There are people on the Internet who say that you can manually _weak the main function generated by cubemx, but my version automatically generates it;
Insert image description here

8-5-2. Call the hal generation initialization function under the main of the application

Call the hal generated initialization function under the main of the application, as follows, call the hal function generated by cubemx in main.c under applications: (Here I use cubemx to configure very few peripherals, all of which have only one main.h header file )
Insert image description here
and then recompile;

8-6 [Problem] I created the main function generated by the SConscript script and weak cubemx, but still got a compilation error.

Phenomenon:

16:22:09 **** Incremental Build of configuration Debug for project test2 ****
make -j4 all 
arm-none-eabi-gcc "../drivers/drv_usart.c"
../drivers/drv_usart.c:28:8: error: unknown type name 'UART_HandleTypeDef'
 static UART_HandleTypeDef handle;
        ^
../drivers/drv_usart.c:380:30: error: unknown type name 'UART_HandleTypeDef'
 __WEAK void HAL_UART_MspInit(UART_HandleTypeDef *huart)
                              ^
../drivers/drv_usart.c: In function 'stm32_configure':
../drivers/drv_usart.c:393:11: error: request for member 'Instance' in something not a structure or union
     handle.Instance          = config->Instance;
           ^
../drivers/drv_usart.c:394:11: error: request for member 'Init' in something not a structure or union
     handle.Init.BaudRate     = 115200;
           ^
../drivers/drv_usart.c:395:11: error: request for member 'Init' in something not a structure or union
     handle.Init.HwFlowCtl    = UART_HWCONTROL_NONE;
           ^
../drivers/drv_usart.c:395:32: error: 'UART_HWCONTROL_NONE' undeclared (first use in this function)
     handle.Init.HwFlowCtl    = UART_HWCONTROL_NONE;
                                ^
../drivers/drv_usart.c:395:32: note: each undeclared identifier is reported only once for each function it appears in
../drivers/drv_usart.c:396:11: error: request for member 'Init' in something not a structure or union
     handle.Init.Mode         = UART_MODE_TX_RX;
           ^
../drivers/drv_usart.c:396:32: error: 'UART_MODE_TX_RX' undeclared (first use in this function)
     handle.Init.Mode         = UART_MODE_TX_RX;
                                ^
../drivers/drv_usart.c:397:11: error: request for member 'Init' in something not a structure or union
     handle.Init.OverSampling = UART_OVERSAMPLING_16;
           ^
../drivers/drv_usart.c:397:32: error: 'UART_OVERSAMPLING_16' undeclared (first use in this function)
     handle.Init.OverSampling = UART_OVERSAMPLING_16;
                                ^
../drivers/drv_usart.c:398:11: error: request for member 'Init' in something not a structure or union
     handle.Init.WordLength   = UART_WORDLENGTH_8B;
           ^
../drivers/drv_usart.c:398:32: error: 'UART_WORDLENGTH_8B' undeclared (first use in this function)
     handle.Init.WordLength   = UART_WORDLENGTH_8B;
                                ^
../drivers/drv_usart.c:399:11: error: request for member 'Init' in something not a structure or union
     handle.Init.StopBits     = UART_STOPBITS_1;
           ^
../drivers/drv_usart.c:399:32: error: 'UART_STOPBITS_1' undeclared (first use in this function)
     handle.Init.StopBits     = UART_STOPBITS_1;
                                ^
../drivers/drv_usart.c:400:11: error: request for member 'Init' in something not a structure or union
     handle.Init.Parity       = UART_PARITY_NONE;
           ^
../drivers/drv_usart.c:400:32: error: 'UART_PARITY_NONE' undeclared (first use in this function)
     handle.Init.Parity       = UART_PARITY_NONE;
                                ^
../drivers/drv_usart.c:402:9: warning: implicit declaration of function 'HAL_UART_Init' [-Wimplicit-function-declaration]
     if (HAL_UART_Init(&handle) != HAL_OK)
         ^
../drivers/drv_usart.c: In function 'rt_hw_console_output':
../drivers/drv_usart.c:429:13: warning: implicit declaration of function 'HAL_UART_Transmit' [-Wimplicit-function-declaration]
             HAL_UART_Transmit(&handle, (uint8_t *)&a, 1, 1);
             ^
../drivers/drv_usart.c: In function 'rt_hw_console_getchar':
../drivers/drv_usart.c:440:9: warning: implicit declaration of function '__HAL_UART_GET_FLAG' [-Wimplicit-function-declaration]
     if (__HAL_UART_GET_FLAG(&handle, UART_FLAG_RXNE) != RESET)
         ^
../drivers/drv_usart.c:440:38: error: 'UART_FLAG_RXNE' undeclared (first use in this function)
     if (__HAL_UART_GET_FLAG(&handle, UART_FLAG_RXNE) != RESET)
                                      ^
../drivers/drv_usart.c:447:20: error: request for member 'Instance' in something not a structure or union
         ch = handle.Instance->DR & 0xff;
                    ^
../drivers/drv_usart.c:452:41: error: 'UART_FLAG_ORE' undeclared (first use in this function)
         if(__HAL_UART_GET_FLAG(&handle, UART_FLAG_ORE) != RESET)
                                         ^
../drivers/drv_usart.c:454:13: warning: implicit declaration of function '__HAL_UART_CLEAR_OREFLAG' [-Wimplicit-function-declaration]
             __HAL_UART_CLEAR_OREFLAG(&handle);
             ^
../drivers/drv_usart.c: At top level:
../drivers/drv_usart.c:251:17: warning: 'stm32_gpio_configure' defined but not used [-Wunused-function]
 static rt_err_t stm32_gpio_configure(struct stm32_uart_config *config)
                 ^
make: *** [drivers/subdir.mk:27: drivers/drv_usart.o] Error 1
"make -j4 all" terminated with exit code 2. Build might be incomplete.

16:22:10 Build Failed. 20 errors, 5 warnings. (took 1s.459ms)

Problem solution: Actually, the problem was caused by me not configuring usart1 used as RT-Thread studio terminal when configuring cubemx. The specific operation is as follows in the blog post:

[rtt problem] After RT-Thread studio is configured with cubemx, it prompts a serial port error: error: unknown type name 'UART_HandleTypeDef'

9. [rtt problem] The new project in RT-Thread studio is compiled successfully, but the j-link download fails.

[rtt problem] RT-Thread studio new project is successfully compiled, but j-link download fails

Guess you like

Origin blog.csdn.net/weixin_42640280/article/details/127908226