STM32 printf function remapping

Publisher:和谐共融Latest update time:2016-03-01 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
/* 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) == 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.

Keywords:STM32 Reference address:STM32 printf function remapping

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

STM32 BootLoader upgrade
Upgrading firmware via serial port ①Jump_To_Application  = (pFunction)(*(vu32*) (IAPSTART + 4)); __MSR_MSP(*(vu32*) IAPSTART); Jump_To_Application(); Track __MSR_MSP (usually this function is in the library file, if you can't track it, use search to find it) and find the assembly function as __MSR_MSP       MSR
[Microcontroller]
STM32's strip fingerprint collection and splicing system
Introduction As a technology with high reliability, convenience and cost-effectiveness in biometric authentication, fingerprint recognition has been widely used. Fingerprint acquisition is an important component of fingerprint recognition, and its core hardware is the fingerprint sensor. As the size of mobile em
[Microcontroller]
STM32's strip fingerprint collection and splicing system
stm32 standby mode
Low Power Mode Reduce the system clock speed.  When APBx and AHB peripherals are not used, turn off the corresponding peripheral clocks. Sleep mode (Cortex™-M3 core is stopped, all peripherals including the peripherals of the Cortex-M3 core, such as NVIC, system clock (SysTick), etc. are still running)  Stop mode (al
[Microcontroller]
stm32 standby mode
Programming and implementation of a simple oscilloscope based on STM32 built-in ADC
  Making a digital sampling oscilloscope has been my long-standing wish, but after all, this goal is quite difficult, and there are too many aspects involved, such as analog front-end circuit, high-speed ADC, microcontroller, CPLD/FPGA, communication, host computer program, data processing, etc. It is not something th
[Test Measurement]
Programming and implementation of a simple oscilloscope based on STM32 built-in ADC
STC12C5A60S2 uses NRF24L01 and stm32 to communicate
/******************************************/ // // The main frequency of this program is 12MHz, and the microcontroller uses STC12C5A60S2 // /******************************************/ #include "STC12C5A60S2.H" #define uchar unsigned char #define uint  unsigned int /********** NRF24L01 register operation comman
[Microcontroller]
STM32 Series Chapter 29 --DS18B20
Features: The unique single bus interface mode only requires one line when DS18B20 is connected to the microprocessor to achieve two-way communication between the microprocessor and DS18B20, which greatly improves the anti-interference ability of the system. The temperature measurement range is -55℃~+125℃, with an a
[Microcontroller]
STM32 Series Chapter 29 --DS18B20
STM32 Learning Notes (5): General Timer PWM Output
1. Basic concepts of TIMER output PWM   Pulse Width Modulation (PWM), short for "Pulse Width Modulation", is a very effective technology that uses the digital output of a microprocessor to control analog circuits. To put it simply, it is the control of pulse width. It is generally used to control the speed of a step
[Microcontroller]
STM32 serial port knowledge and configuration
1. Serial port knowledge The application of the serial port is that the chip sends data to the computer, the computer downloads the program to the chip, and the chip sends the data in the chip memory back to the computer. For example, when you measure the angle or speed, after the chip measures, you must see that the
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号