Hello, I have STM32F103 with three active USART + one SWO port. I need to single UART send different data, ideally using printf, but I do not know how to redirect flow from print to a specific USART you do? I would welcome an application example with more UART communication.
The second query. Looking for example of how to redirect printf to SWO, for STM32F103 too.
I thing all function from printf famili need implement lowlwvel function fputc etc.
Retargeting printf()
#include <stdio.h> 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 is typedef’d in stdio.h. */ FILE __stdout; int fputc(int ch, FILE *f) { /* Your implementation of fputc(). */ return ch; } int ferror(FILE *f) { /* Your implementation of ferror(). */ return 0; } void test(void) { printf("Hello world\n"); }
more precise reimplemrntation fputc for UART
int fputc(int ch, FILE *f) { /* Place your implementation of fputc here */ /* e.g. write a character to the USART1 and Loop until the end of transmission */ HAL_UART_Transmit(&UartHandle, (uint8_t *)&ch, 1, 0xFFFF); return ch; }