日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Library reports error: __use_no_semihosting was requested, but _tty

發布時間:2025/3/15 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 */

/* Loop until the end of transmission */ while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) { } USART_SendData(USART1, (uint8_t) ch); return ch;

}

/**
* @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);

while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) { } USART_SendData(USART1, (uint8_t) ch); return ch;

}

解決辦法在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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。