STM32 in printf redirected to the serial port

  STM32 learning process, often dealing than the serial port, you can be anything, of course, it is important to print debug information to the serial output, always use a string of bytes sent or function send function

  Some will always hold before programming familiar than printf, the following will print with printf given to the serial port of the program, of course, more than one program, for reference purposes only.

  1, add headers #include printf

  2, rewriting int fputc (int ch, FILE * f) function

  int fputc(int ch, FILE *f);

 

  function

 

 int fputc(int ch, FILE *f)

  {

  USART_SendData(USART1, (uint8_t) ch);

  while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);

  return ch;

  }

 

  3, modify select Use MicroLIB Target - Code Generation-- select Use MicroLI

  So that you can use as printf as before.

 

Guess you like

Origin www.cnblogs.com/QianD/p/11327721.html