Why I need to add delay after HAL_UART_Transmit_DMA and before memset at IRQ call back function
void vcom_IRQHandler(void) // external interrupt for USART2_IRQHandler
{
HAL_UART_IRQHandler(&UartHandle);
USER_UART_IRQHandler(&UartHandle);
}
void USER_UART_IRQHandler(UART_HandleTypeDef *huart)
{
if(USART2 == UartHandle.Instance) //Determine whether it is serial port
{
if(RESET != __HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_IDLE))
{
__HAL_UART_CLEAR_IDLEFLAG(&UartHandle);
USAR_UART_IDLECallback(huart);
}
}
}
void USAR_UART_IDLECallback(UART_HandleTypeDef *huart)
{
HAL_UART_DMAStop(&UartHandle);
uint8_t data_length = BUFFER_SIZE - __HAL_DMA_GET_COUNTER(&hdma_usart2_rx);
HAL_UART_Transmit_DMA(&UartHandle,(uint8_t *)&aRx2Buffer, data_length);
DelayMs(100); // why need this delay
memset(aRx2Buffer,0,data_length);
data_length = 0;
HAL_UART_Receive_DMA(&UartHandle, (uint8_t*)aRx2Buffer, 25);
}Scenario : After I call HAL_UART_Transmit_DMA, if I didn't put a delay at there, I monitor at serial terminal like docklight/putty, I won't see a full data.
And then I use JTAG to debug, step one by one, found out that I can receive actual data. (I think because of stepping is not run time anymore, and it indirectly perform an delay(s) at there)
So I add delay after that function, I can solve the problem. But I want to know the reason and also the drawback if I add the delay. To be honest I think a delay like that will halt the CPU for so long.
