简体   繁体   中英

Hang up with UART and DMA

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
    }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM