cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UARTEx_ReceiveToIdle_DMA() => No reaction on IDLE event

Markus Spiekermann
Associate III

I'm trying to make use of the HAL_UARTEx_ReceiveToIdle_DMA() functionality.

So far no reaction on an IDLE event. The corresponding HAL_UARTEx_RxEventCallback

gets called when a certain amount of bytes has been received, but not on an IDLE event.

The development board I use: NUCLEO-L031K6

The UART of interest:USART2

So here's my setup:

0693W00000bhDtDQAU.jpg0693W00000bhDtIQAU.jpg0693W00000bhDtNQAU.jpg0693W00000bhDtSQAU.jpg0693W00000bhDtcQAE.jpgI added the following code:

...

/* USER CODE BEGIN PFP */

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t size);

/* USER CODE END PFP */

...

/* USER CODE BEGIN 2 */

HAL_UARTEx_ReceiveToIdle_DMA(&huart2, rx_buf_usart2, rx_buf_size);

__HAL_DMA_DISABLE_IT(&hdma_usart2_rx, DMA_IT_HT);

/* USER CODE END 2 */

...

/* USER CODE BEGIN 4 */

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t size)

{

if (huart->Instance == USART2)

{

HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);

HAL_UARTEx_ReceiveToIdle_DMA(&huart2, rx_buf_usart2, rx_buf_size);

__HAL_DMA_DISABLE_IT(&hdma_usart2_rx, DMA_IT_HT);

}

}

/* USER CODE BEGIN 4 */

...

rx_buf_size is set to 16. And exactly after 16 bytes the RxEventCallback gets executed.

What am I missing?

As you can see in my setup, the USART2 global interrupt ist set.

Could somebody point me in the right direction to look for the problem?

Thanks.

12 REPLIES 12

That is good to hear and that I was able to help get you in the right direction.

If you find my answers useful, click the accept button so that way others can see the solution.

Hi @Community member​ ,

I'm experiencing sort of the same problem, on STM32G041.

If lots of bits is received, the DMA sometimes stops receiving. When I then try to call "HAL_UARTEx_ReceiveToIdle_DMA" again to restart it, I get HAL_ERROR (line 783 in your picture). Afterwards data is received, but the idle interrupt no longer works.

What do I do when "HAL_UARTEx_ReceiveToIdle_DMA" returns HAL_ERROR?

Markus Spiekermann
Associate III

Hi MClau.1,

well it would probably help in your situation if you would show us some portions of the code that you use to handle DMA transfers.

In general the ReceiveToIdle call activates three kind of interrupts:

IDLE => Reacts on IDLE events and the IDLE duration to react on depends on your configuration

HC => Reacts on DMA transfers when half of the data to receive or to send has been handled

TC => Reacts on DMA transfers when the entire amount of data to receive or to send has been handled

If the DMA request has been set to normal mode, then subsequently performed DMA transfers have

to be reinitiated by calling the ReceiveToIdle function again in case of an IDLE ot TC event.

And I think it is good practice to call HAL_DMA_GetState for the DMA channel of interest before

calling ReceiveToIdle. This way you ensure that all related DMA processes are done.