Reputation: 125
I am trying to use UART and DMA. When I insert a call to HAL_Delay() in the USART3_IRQHandler(), the program hang in the HAL_Delay(). The SysTick interrupt is not called anymore. I don't understand?
int main(void)
{
...
MX_DMA_Init();
MX_USART3_UART_Init();
uint32_t nextCall = uwTick;
while (1)
{
if (nextCall < uwTick) {
__HAL_UART_ENABLE_IT(&huart3, UART_IT_IDLE);
HAL_UART_Transmit_DMA( &huart3, dataTx, sizeof( dataTx ) );
nextCall = uwTick + 1000;
}
}
}
void USART3_IRQHandler(void)
{
HAL_UART_IRQHandler(&huart3);
if (( USART3->SR & UART_IT_IDLE) != 0 )
{
__HAL_UART_CLEAR_IDLEFLAG( &huart3 );
HAL_UART_DMAStop(&huart3);
uint8_t data_length = sizeof( dataRx ) - __HAL_DMA_GET_COUNTER(&hdma_usart3_rx);
memset( dataRx,0,sizeof( dataRx ));
HAL_UART_Receive_DMA(&huart3, (uint8_t*)dataRx, sizeof( dataRx ));
HAL_Delay( 1 );
// Delay() does not return
}
}
Upvotes: 0
Views: 641
Reputation: 67820
Abstracting from the completely wrong impossible to repair UART code HAL_Delay to work in the interrupt context requires SYSTICK interrupt priority to be higher than the UART interrupt. Otherwise it is not invoked and the internal counter does not increase and the function ends in the dead loop.
Upvotes: 1