STM32 printf function Remapping

Source: Internet
Author: User
Tags printf
STM32 printf function remapping

/* Private function Prototypes-----------------------------------------------*/

#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__

 

* */**
  * @brief  retargets the C library printf function to the USART.
  * @param  None
  * @retval None * * Putchar_prototype {/* place
  your implementation of FPUTC here */
  * Loop until the end of transmission * *
  while (Usart_getflagstatus (eval_com1, usart_flag_tc) = = R ESET)
  {}
  
  /* Write a character
  to the USART */Usart_senddata (EVAL_COM1, (uint8_t) ch);

  return ch;
}

SB's explanation:

This code means the C language library function printf Redirect, or remap, the word is a bit too professional, simple:
is the C language library in the printf function will call Putchar_prototype This hardware interface function, output char type variable to the display , to show that the
STM32 of course is no display, so the UART output char type variable to the PC, by the PC's Super terminal to display, plainly,
is the original display data sent to the display, now sent to the STM32 serial;
If the adjustment is not over, You have to pay attention to two points:
1. Your board is used is not USART1, if it is, that even to the PC's serial port, you can see the print out of the Super terminal, if not, please refer to the 2nd.
2. First initialize the Usart on your board and replace the USART1 in the Putchar_prototype function body with the usart you are using now.
in free to send a note, of course, the above is free, hehe
1.stm32 peripheral output pin can be remapped, such as USART2, to pay attention to the board, is the original pin-connected, or remap, if the remap, please refer to 2nd.
2. If the connection is a remap pin, before the original initialization, add a remap function, of course, the St routine also has this part of the code, you can refer to.  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.