zoukankan      html  css  js  c++  java
  • STM32 printf 函数原型

    在STM32工程中调用printf函数,需要加入如下代码:

    #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 PCHAR_PROTOTYPE int fputc(int ch, FILE *f)
    #endif /* __GNUC__ UT*/
     

    void Printf_Init(void)
    {
      /*!< At this stage the microcontroller clock setting is already configured,
           this is done through SystemInit() function which is called from startup
           file (startup_stm32f10x_xx.s) before to branch to application main.
           To reconfigure the default setting of SystemInit() function, refer to
           system_stm32f10x.c file
         */     
           
      /* USARTx configured as follow:
            - BaudRate = 115200 baud  
            - Word Length = 8 Bits
            - One Stop Bit
            - No parity
            - Hardware flow control disabled (RTS and CTS signals)
            - Receive and transmit enabled
      */
      USART_InitStructure.USART_BaudRate = 115200;
      USART_InitStructure.USART_WordLength = USART_WordLength_8b;
      USART_InitStructure.USART_StopBits = USART_StopBits_1;
      USART_InitStructure.USART_Parity = USART_Parity_No;
      USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
      USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

      STM_EVAL_COMInit(COM1, &USART_InitStructure);

      /* Output a message on Hyperterminal using printf function */
      //printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r");
    //  printf("\r\n\n\n WWW.ARMJISHU.COM  %s configured....", EVAL_COM1_STR);
    //  printf("\n\r ############ WWW.ARMJISHU.COM! ############ ("__DATE__ " - " __TIME__ ")\n\r");
    }

    /**
      * @brief  Retargets the C library printf function to the USART.
      * @param  None
      * @retval None
      */
    PUTCHAR_PROTOTYPE
    {
      /* Place your implementation of fputc here */
      /* e.g. write a character to the USART */
      USART_SendData(EVAL_COM1, (uint8_t) ch);

      /* Loop until the end of transmission */
      while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
      {}

      return ch;
    }

  • 相关阅读:
    jython resources
    Installing a Library of Jython ScriptsPart of the WebSphere Application Server v7.x Administration Series Series
    jython好资料
    ulipad install on 64bit win7 has issue
    an oracle article in high level to descibe how to archtichre operator JAVA relevet project
    table的宽度,单元格内换行问题
    Linux常用命令大全
    dedecms系统后台登陆提示用户名密码不存在
    登录织梦后台提示用户名不存在的解决方法介绍
    Shell常用命令整理
  • 原文地址:https://www.cnblogs.com/glguan/p/2500785.html
Copyright © 2011-2022 走看看