The main reference of the article: https://blog.csdn.net/killercode11/article/details/104290949, which refers to
rt_hw_console_getchar()
the definition.
Article directory
This article does not introduce the serial port configuration of RT-Thread. If necessary, you can refer to: Remap serial port to rt_kprintf function
Add the FinSH source code to the project
The FinSH source code is in the directory of the RT-Thread source code components\finsh\
directory ,
Import it into the project, the specific operation will not be introduced here, remember to include the header file,
Enable FinSH
Modify rtconfig.h
, open finsh config
, the following is the graphical configuration using the Configuration Wizard
wizard ,
In fact, it is to include the finsh_fonfig.h
header file into the project. This header file contains the basic parameter configuration of FisSH.
Define the terminal read function
After porting the FinSH source code, an error will usually be reported during the initial compilation, and the #error line rt_hw_console_getchar()
in blocked (remember to turn off the read-only attribute of the file first)
Then board.c
we manually redefine rt_hw_console_getchar()
the function in the file. The content of the function is as follows. This is the standard library version. If you need the HAL library version, you can refer to the link at the top of the article.
char rt_hw_console_getchar(void)
{
/* Note: the initial value of ch must < 0 */
int ch = -1;
if(USART_GetFlagStatus(DEBUG_USARTx, USART_FLAG_RXNE) != RESET)
{
//USART_ClearITPendingBit(USART_DEBUG, USART_FLAG_RXNE);
ch = USART_ReceiveData(DEBUG_USARTx) & 0xFF;
}
else
{
if(USART_GetFlagStatus(DEBUG_USARTx, USART_FLAG_ORE) != RESET)
{
USART_ClearITPendingBit(DEBUG_USARTx, USART_FLAG_ORE);
}
rt_thread_mdelay(10);
}
return ch;
}
Experience FinSH
I use SSCOM as the terminal, the effect is not bad, the command is entered directly in the display window.
Some people may ask why I don't use common terminal software such as PuTTy and XShell. I also want to use it, but after connecting such terminal software, the development board will not run.
problems encountered
1. Segmentation fault
There are many reasons for this error, such as is RT_MAIN_THREAD_STACK_SIZE
too small , and I RT_THREAD_PRIORITY_MAX
set it too small (only set to 8), which is less than FINSH_THREAD_PRIORITY
the default value of 21, so the solution is to change the thread priority (value) of FINSH to a smaller value Or change the maximum value (value range) of the system priority to a larger value.
2. Terminal tools cannot print
With PuTTy, XShell, the terminal does not respond and the board gets stuck. The reason for the preliminary analysis is "the conflict between the punctual atomic one-key download circuit and the terminal tool" (the conclusion of others on the Internet), so the serial debugging assistant can only be used to operate Finsh.
3. The program does not run
There are many possible reasons for this problem, but it should be noted that if you want to use FinSH, you cannot open the serial port interrupt. As for why, I have not yet understood.