Skip to main content
FIann.2
Associate II
September 14, 2020
Question

DMA transfer in interrupt mode

Hi, in the book i am reading there is an example about UART DMA trasnfer in interrupt mode. In this example i don t understand why the author enables the UART related interrupt.

I mean it is not the UART to generate the interrupt but the DMA when trasfer is completed, so why he needs to enable UART interrupts?

Another question:

if i want perform a DMA transfer in interrupt mode when a Timer expires, so i have to enable the timere interrupts also?

Many thanks

This topic has been closed for replies.

9 replies

Pavel A.
September 14, 2020

The book? which book?

Please see these good examples for UARTs with DMA.

https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx/

FIann.2
FIann.2Author
Associate II
September 15, 2020

Carmine Noviello book "Mastering STM32"

Do you know why he enables UART interruput when performing a DMA trasfer in interrupt mode?

He specially say not to forget to do it.

Ozone
Principal
September 15, 2020

You would need to tell a bit more about the example.

There are several UART-related interrupts, for transmission (TxE), reception (RxNE), and errors.

Or perhaps he used an interrupt to manage DMA-based transmission for varying string length.

FIann.2
FIann.2Author
Associate II
September 15, 2020

maybe he enables UART interrupt just for error menagement?

FIann.2
FIann.2Author
Associate II
September 15, 2020

no, i think its becouse HAL_UART_RxCpltCallback is defined weak inside HAL_UART_IRQHandler

void USART2_IRQHandler(void)

{

 /* USER CODE BEGIN USART2_IRQn 0 */

 /* USER CODE END USART2_IRQn 0 */

 HAL_UART_IRQHandler(&huart2);

 /* USER CODE BEGIN USART2_IRQn 1 */

 /* USER CODE END USART2_IRQn 1 */

}

void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)

{

………….

__weak void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

 /* Prevent unused argument(s) compilation warning */

 UNUSED(huart);

 /* NOTE: This function Should not be modified, when the callback is needed,

          the HAL_UART_TxCpltCallback could be implemented in the user file

  */

}

………..

}

FIann.2
FIann.2Author
Associate II
March 24, 2021

no, you was right first:

The reason is that the HAL assumes that the “HAL_UART_IRQHandler()�? routine is properly called to setup internal HAL states. They are mostly related to UART error states (overrun, parity error, etc).

FIann.2
FIann.2Author
Associate II
March 24, 2021

in HAL_UART_Receive_DMA:

/* Enable the UART Parity Error Interrupt */

SET_BIT(huart->Instance->CR1, USART_CR1_PEIE);

/* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */

SET_BIT(huart->Instance->CR3, USART_CR3_EIE);