From d06c63fa5c9c4ca1e0e82062f75140b34de7d576 Mon Sep 17 00:00:00 2001 From: unicod Date: Sat, 14 Feb 2026 10:41:30 +0100 Subject: [PATCH] printf targeted to UART5 --- Core/Src/main.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index 63a0e1c..6961e43 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -21,6 +21,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include #include #include "disp7seg.h" @@ -82,6 +83,18 @@ static inline uint32_t TickChk(uint32_t *tref, int_fast16_t tcycle) { return 0; } +/***************************************************************************//** + * @brief Retargets the C library printf function to the USART. + * @param file: The file handle (not used, can be ignored). + * @param ptr: Pointer to the data buffer to be transmitted. + * @param len: Length of the data buffer. + * @retval The number of bytes transmitted. + *******************************************************************************/ +int _write(int file, char *ptr, int len) { + Uart5_PutData(ptr, len); + return len; +} + /* USER CODE END 0 */ @@ -142,8 +155,7 @@ int main(void) ShiftReg_Update(); Uart5_Init(); - char* s = "Hello, world!\r\n"; - Uart5_PutData(s, strlen(s)); + printf("Hello printf\n"); /* USER CODE END 2 */ @@ -163,7 +175,11 @@ int main(void) DispPutDigit(1, 'a'+cnt, 1); DispPutDigit(2, 'A'+cnt, 0); cnt = (cnt + 1) % 16; - Uart5_PutByte('0' + cnt); + static uint32_t Trefus = 0; + uint32_t t = usTimerGetAbs(); + uint32_t tdif = t - Trefus; + printf("%6luus\n", tdif); + Trefus = t; } static uint32_t Tick100msRef = 0;