Source: http://blog.163.com/qiu_zhi2008/blog/static/6014097720111110710738/STM32 printf function remapping
#ifdef __gnuc__/* with gcc/raisonance, small printf (option LD linker->libraries->small printf set to ' Yes ') cal LS __io_putchar () */#define PUTCHAR_PROTOTYPE int __io_putchar (int ch) #else # define Putchar_prototype int FPUTC (int ch, FI LE *f) #endif/* __gnuc__ */
Based on Stm32cube library: stm32cube_fw_l1_v1.2.0
/** * @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 serial 2 and Loop until the end of transmission * /Hal_uart_transmit (&huart2, (uint8_t *) &ch, 1, 0xFFFF); 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 to say:
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 display,
STM32 Of course there is no display, so the UART output char type variable to the PC, by the PC's HyperTerminal to display, plainly,
is the original display data sent to the display, now sent to the STM32 serial port;
If the adjustment is not over, you should 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 on the super terminal, see the printed things, 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.
For free to send a note, of course, the above is also free, hehe
1.stm32 peripheral Output pin can be remapped, such as USART2, pay attention to the board, is the original pin connected, or remap, if it is remapped, please refer to the 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.
Arm_ serial--printf re-mapping