<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          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://www.ex-cimer.com/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)庫會導(dǎo)致程序無法運(yùn)行,以下是解決方法:

          方法1.使用微庫,因?yàn)槭褂梦斓脑?不會使用半主機(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)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();