Library reports error: __use_no_semihosting was requested, but _tty
在向STM32工程中添加文件的時候遇到了報錯 Library reports error: __use_no_semihosting was requested, but _ttywrch was referenced
在網上找了好久終于找到了可行的辦法,終于知道了,出現這樣的錯誤說明你編寫的程序使程序進入了半主機模式
半主機模式的解釋如下:
半主機是這么一種機制,它使得在ARM目標上跑的代碼,如果主機電腦運行了調試器,那么該代碼可以使用該主機電腦的輸入輸出設備。
這點非常重要,因為開發初期,可能開發者根本不知道該 ARM 器件上有什么輸入輸出設備,而半主基機制使得你不用知道ARM器件的外設,利用主機電腦的外設就可以實現輸入輸出調試。
所以要利用目標 ARM器件的輸入輸出設備,首先要關掉半主機機制。然后再將輸入輸出重定向到 ARM 器件上,如 printf 和 scanf,你需要重寫 fputc和 fgetc 函數。下面就是將 scanf 和 printf 重定向到 uart 的代碼。
/**
* @brief Retargets the C library printf function to the USART.
* @param ch: the char to be send.
* @param *f:
* @retval the char that send out.
*/
int fputc(int ch, FILE *f)
{
/* lace your implementation of fputc here */
/* e.g. write a character to the USART */
}
/**
* @brief Retargets the C library printf function to the USART.
* @param *f
* @retval the char that received.
*/
int fgetc(FILE *f)
{
int ch;
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET)
{
}
ch = USART_ReceiveData(USART1);
}
解決辦法在usart.c文件大約50行左右加入一個函數
//__use_no_semihosting was requested, but _ttywrch was
_ttywrch(int ch)
{
ch = ch;
}
或者勾選微庫就可以解決上述問題
主要的原因可能是輸出函數的重定向引起的,具體的原因不是很確定。
下面的這幾句話是KEIL官網上給出的解釋
Defined in rt_sys.h, the _ttywrch() function writes a character to the console.
The console might have been redirected. You can use this function as a last resort error handling routine.
總結
以上是生活随笔為你收集整理的Library reports error: __use_no_semihosting was requested, but _tty的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【2017年第4期】工业大数据技术与架构
- 下一篇: 新工科背景下的计算机类专业人才培养探讨