How to make printf work on STM32F103?

前端 未结 4 1046
醉话见心
醉话见心 2021-01-16 18:51

I am new to the world of STM32F103. I have a demo code for STM32F103 and I am using arm-none-eabi to compile it.

I tried what I could find on Google, but nothing wor

4条回答
  •  独厮守ぢ
    2021-01-16 19:33

    Look there. This is printf from glib. But you have microcontroller. So you sould write own printf, where vfprintf will return result into buffer and next you will send data from buffer to UART. Kind of

    void printf( const char * format, ... )
    {
      char buffer[256];
      va_list args;
      va_start (args, format);
      vsprintf (buffer,format, args);
      send_via_USART1 (buffer);
      va_end (args);
    }
    

    Also you can write own vsprintf. Standart vsprintf is very heavy. Usually little part of vsprintf features is used.

提交回复
热议问题