stm32 serial port printf function redirection

Publisher:ping777Latest update time:2019-03-09 Source: eefocusKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The printf function redirection of the serial port is divided into two cases: using the MicroLIB library and not using the MicroLIB library. The specific implementation code is as follows:


#if 1

 

/*****************If you don't use MicroLIB library, you need to add this part********************************/

//Cancel ARM's semi-host working mode

//#pragma import(__use_no_semihosting) // Make sure no functions using semihosting are linked from the C library          

//              

//struct __FILE // Support functions required by the standard library

//{ 

// int handle; 

//}; 

 

//FILE __stdout; // FILE is typedef'd in stdio.h

//   

//void _sys_exit(int x) // Define _sys_exit() to avoid using semihost mode

//{ 

// x = x; 

//} 

/****************************************************** *********************/

int fputc(int ch, FILE *f)

{

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1,GPIO_PIN_SET); 

HAL_UART_Transmit(&huart2,(uint8_t*) &ch, 1, 1);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1,GPIO_PIN_RESET); 

return ch;

}

#endif



Keywords:stm32 Reference address:stm32 serial port printf function redirection

Previous article:STM32 - the difference between advanced timer, general timer and basic timer
Next article:STM32 printf semihost mode

Recommended ReadingLatest update time:2024-11-16 17:33

stm32 common IO port captures PWM high level
Idea: Configure the rising and falling edges of the common IO port to trigger the interrupt, then configure a timer (the period is greater than or equal to the PWM period), and read the timer count in the IO port interrupt. The timer does not need to configure an interrupt void TIM3_Configuration(void) { TIM_TimeBaseI
[Microcontroller]
How does STM32 enter the interrupt service function xxx_IRQHandler
Today I was looking at the interrupt of stm32. For a moment, I didn't understand how the stm32 main function entered the interrupt function. According to the understanding of C programming, there would be a specific entry or something like that, but I didn't find the entry during the demo. Taking the serial port int
[Microcontroller]
STM32 IIC Difficulties and Errors
Let's go off topic first~ It's said on the Internet that the IIC of STM32F103 has defects! Just treat it as some shortcomings. Personally, I think it's definitely fine to use, but it's just not easy to use. People say that ST company considered patent issues and did not follow Philips' standards. As a result, the IIC
[Microcontroller]
STM32 IIC Difficulties and Errors
STM32 single-line serial port control of bus servo
1 Introduction to bus servos Bus servo servos are serial bus intelligent servos, which can actually be understood as derivatives of digital servos . Compared with analog servos , digital servos are a subversion of control system design, while bus servo servos are a subversion of servos in terms of function and applic
[Microcontroller]
STM32 single-line serial port control of bus servo
STM32 - SystemInit trap during simulation debugging
STM32 - SystemInit trap during simulation debugging When I started the simulation debugging of STM32, I encountered a problem. During debugging, the program kept stopping in the waiting crystal oscillator in SystemInit() and could not get out. The code in the first part of SystemInit() can be executed, but the pr
[Microcontroller]
STM32 - SystemInit trap during simulation debugging
STM32 general timer input capture mode
#include "stm32f10x.h" /*RCC clock configuration*/ void RCC_config() {   ErrorStatus HSEStartUpStatus;  /* RCC registers are set to default configuration */  RCC_DeInit();  /* Turn on external high speed clock */  RCC_HSEConfig(RCC_HSE_ON);  /* Wait for the external high-speed clock to stabilize*/  HSEStartUpStatu
[Microcontroller]
STMicroelectronics launches long-range wireless microcontroller to improve connectivity energy efficiency in smart metering, smart buildings and industrial monitoring
The new STM32 system chip has low power consumption and supports multiple wireless communication protocols, simplifying the design of wireless systems for various purposes. China, November 24, 2023 - STMicroelectronics (ST;), a world-leading semiconductor company serving multiple electronic applications, has releas
[Embedded]
STMicroelectronics launches long-range wireless microcontroller to improve connectivity energy efficiency in smart metering, smart buildings and industrial monitoring
Using STM32 encoder to determine arbitrary position
Determining the wheel position is an essential component in the process of making a car. Fortunately, STM32 includes a hardware encoder. However, there are many inconveniences in the process of using it. Let me explain one by one:       1. Encoder principle        What is orthogonality? If the two signals differ in ph
[Microcontroller]
Using STM32 encoder to determine arbitrary position
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号