When it comes to send data thorough multi-serial port by using printf, how it can be handled? We will have a look at a simple example of it. In this example, we will use USART3, USART6 and send data by using printf method.
Example:
Variables;
1 2 3 4 |
/* Private variables ---------------------------------------------------------*/ UART_HandleTypeDef uart; //define a general serial variable UART_HandleTypeDef huart3; UART_HandleTypeDef huart6; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
/* Private function prototypes -----------------------------------------------*/ ///////////////////////////////////////////////////////////////////////////// //stm32 multiport printf settings #ifdef __GNUC__ #define PUT_CHAR int __io_putchar(int chr) #else #define PUT_CHAR int fputc(int chr, FILE *f) #endif PUT_CHAR { HAL_UART_Transmit(&uart, (uint8_t *)&chr, 1, 1000); return chr; } //////////////////////////////////////////////////////////////////////////////// |
1 2 3 4 5 6 7 8 9 10 |
while (1) { HAL_Delay(500); uart = huart3; printf("send data thorough the usart3\n"); uart = huart6; printf("send data thorough the usart6\n"); } |