国产肉体XXXX裸体137大胆,国产成人久久精品流白浆,国产乱子伦视频在线观看,无码中文字幕免费一区二区三区 国产成人手机在线-午夜国产精品无套-swag国产精品-国产毛片久久国产

新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > STM32程序添加printf后無法運(yùn)行的解決方法

STM32程序添加printf后無法運(yùn)行的解決方法

作者: 時(shí)間:2016-11-11 來源:網(wǎng)絡(luò) 收藏
標(biāo)準(zhǔn)庫函數(shù)的默認(rèn)輸出設(shè)備是顯示器,要實(shí)現(xiàn)在串口或LCD輸出,必須重定義標(biāo)準(zhǔn)庫函數(shù)里調(diào)用的與輸出設(shè)備相關(guān)的函數(shù).

例如:printf輸出到串口,需要將fputc里面的輸出指向串口(重定向),方法如下:

本文引用地址:http://m.ptau.cn/article/201611/316689.htm

#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to Yes) calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */

PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(USART1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
return ch;
}

因printf()之類的函數(shù),使用了半主機(jī)模式。使用標(biāo)準(zhǔn)庫會(huì)導(dǎo)致程序無法運(yùn)行,以下是解決方法:

方法1.使用微庫,因?yàn)槭褂梦斓脑?不會(huì)使用半主機(jī)模式.

方法2.仍然使用標(biāo)準(zhǔn)庫,在主程序添加下面代碼:

#pragmaimport(__use_no_semihosting)
_sys_exit(intx)
{
x=x;
}
struct__FILE
{
inthandle;
/*Whateveryourequirehere.Iftheonlyfileyouareusingis*/
/*standardoutputusingprintf()fordebugging,nofilehandling*/
/*isrequired.*/
};
/*FILEistypedef’dinstdio.h.*/
FILE__stdout;



評論


技術(shù)專區(qū)

關(guān)閉