#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) == RESET)
{}
/* write a character to the USART */
USART_SendData(EVAL_COM1, (uint8_t) ch);
return ch;
}
Someone's explanation:
This code means redirecting or remapping the C language library function printf. This term is a bit too professional. To put it simply,
the printf function in the C language library will call the hardware interface function PUTCHAR_PROTOTYPE to output a char type variable to the display for display.
Of course, STM32 does not have a display, so it uses UART to output a char type variable to the PC, which is displayed by the PC's hyperterminal. To put it bluntly,
the display data originally sent to the monitor is now sent to the STM32 serial port.
If it cannot be transferred, you need to pay attention to two points:
1. Is your board using USART1? If so, then connect it to the PC's serial port and you can see the printed content on the hyperterminal. If not, please refer to point 2.
2. Initialize the USART on your board first, and then replace the USART1 in the PUTCHAR_PROTOTYPE function body with the USART you are using now. Here is
a note for free, of course, the above are also free, haha
1. The peripheral output pins of STM32 can be remapped, such as USART2. Pay attention to whether the board is connected according to the original pins or remapped. If it is remapped, please refer to point 2.
2. If the connection is a remapped pin, please add a remapping function before the original initialization. Of course, there is also this part of code in the ST routine, which can be referred to.
Previous article:A brief understanding of S3C2440 on-chip bus (AMBA)
Next article:Memory expansion test
Recommended ReadingLatest update time:2024-11-16 23:58
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- EEWORLD University ---- Micro bit introductory application video tutorial
- Electrical knowledge encyclopedia
- C6678 Learning - Interrupt Nesting
- RSL10 low power mode
- Exploring the Mystery of Millimeter Wave RADAR and LIDAR
- A detailed introduction to the Chroma 8000 power supply automatic test system;
- [Project source code] Mif wizard/mif (coe) file generator based on FPGA
- Controlling Hardware with Python - Measuring the Resonant Frequency of an Object Using the ADXL335 Accelerometer
- Useful Tips | Don’t throw away your old phone, here’s a step-by-step guide to DIY a server
- How to measure load impedance, current & voltage signals?