Arm_ serial--printf re-mapping

Source: Internet
Author: User

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

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.