Hi @Birdym
Your HAL_UART_RxCpltCallback() will apply for both UART handles (huart2 and huart5) (is it what it intended ?).
So, what I expect your code will do, is :
- on each char received on COM on huart2 (stored in rx_buffer_uart2[0]), rx_buffer_uart5[0] is transmitted on huart2 . Reception on huart2 is re-started.
- on each char received on COM on huart5 (stored in rx_buffer_uart5[0]), rx_buffer_uart5[0] is transmitted on huart2 . Reception on huart5 is re-started.
Is it really tour use case ?
Regarding loss of chars, as mentioned by @Ozone , reason might be that you spent too much time in RX interrupt handler.
When calling HAL_UART_Receive_IT(&huartx, rx_buffer_uartx, 1), on each char received a RXNE will be raised, as and expected length is 1, the reception will be considered as complete, and then callback will be executed in IT context.
Please note that HAL_UART_Transmit() is a "polling based" function : char will be transmitted, and function exits only when transmission is completed (this is detetced by polling flags in UART registers). So this function will at least last for a char transmission time. If another character is received during this period, IT will be delayed ...
So calling HAL_UART_Transmit() in your Rx complete callback is too time consuming.
Could you try to perform transmission also in Interrupt mode ? => using HAL_UART_Transmit_IT()
This will generate more interrupts, but depending of used baudrate, it could work ...