Created
May 17, 2018 13:48
-
-
Save mnemocron/46e0466637a6610026edb4e915c53e2e to your computer and use it in GitHub Desktop.
Redirect printf() to UART on STM32 microcontroller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* USER CODE BEGIN Includes */ | |
#include <stdio.h> | |
/* USER CODE BEGIN 0 */ | |
/* PRINTF REDIRECT to UART BEGIN */ | |
// @see http://www.keil.com/forum/60531/ | |
// @see https://stackoverflow.com/questions/45535126/stm32-printf-redirect | |
struct __FILE{ | |
int handle; | |
/* Whatever you require here. If the only file you are using is */ | |
/* standard output using printf() for debugging, no file handling */ | |
/* is required. */ | |
}; | |
FILE __stdout; | |
int fputc(int ch, FILE *f){ | |
HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 0xFFFF); | |
return ch; | |
} | |
int ferror(FILE *f){ | |
/* Your implementation of ferror(). */ | |
return 0; | |
} | |
/* PRINTF REDIRECT to UART END */ | |
/* USER CODE END 0 */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How it is works?