I would like to receive any length of data from USART2 DMA circular mode, then transmit the identical data via USART1 DMA normal mode.
However, I found that there is a probability that even USART2 receives the full data, USART1 will miss to transmit some bytes.
volatile uint8_t RxMsg_USART2_temp[1];
volatile uint8_t RxMsg_USART2[120];
HAL_UART_Receive_DMA(&huart2, RxMsg_USART2_temp, sizeof(RxMsg_USART2_temp));
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
if(huart->Instance == USART2){
if( RxMsg_USART2_temp[0] != 'n' ){
RxMsg_USART2[idx] = RxMsg_USART2_temp[0];
idx++;
}else{
RxMsg_USART2[idx] = RxMsg_USART2_temp[0];
HAL_UART_Transmit_DMA(&huart1, RxMsg_USART2, idx+1);
}
}
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart){
if(huart->Instance == USART1){
memset(RxMsg_USART2_temp, 0, sizeof(RxMsg_USART2_temp));
memset(RxMsg_USART2, 0, sizeof(RxMsg_USART2));
idx = 0;
}
}