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.