cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f767 and UART DMA IT (interrupts)

embvis
Associate III
Posted on January 24, 2017 at 11:07

Hi,

How to use UART in DMA mode with interrupts IT.

I use the next code to transmit, and it works perfect. 

HAL_DMA_Start_IT(&hdma_usart3_tx, (uint32_t)msg, (uint32_t)&huart3.Instance->TDR, strlen(msg));

huart3.Instance->CR3 |= USART_CR3_DMAT; // DMAT: DMA enable transmitter

But receive Rx doesnt work

:(

HAL_DMA_Start_IT(&hdma_usart3_rx, (uint32_t)&huart3.Instance->RDR, (uint32_t)uRxBuff, 8);

huart3.Instance->CR3 |= USART_CR3_DMAR; // DMA enable receiver

DMA config:

/* Peripheral DMA init*/

hdma_usart3_rx.Instance = DMA1_Stream1;

hdma_usart3_rx.Init.Channel = DMA_CHANNEL_4;

hdma_usart3_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;

hdma_usart3_rx.Init.PeriphInc = DMA_PINC_DISABLE;

hdma_usart3_rx.Init.MemInc = DMA_MINC_ENABLE;

hdma_usart3_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

hdma_usart3_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;

hdma_usart3_rx.Init.Mode = DMA_NORMAL;

hdma_usart3_rx.Init.Priority = DMA_PRIORITY_LOW;

hdma_usart3_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

hdma_usart3_rx.XferCpltCallback = &DMAReceiveComplete;

if (HAL_DMA_Init(&hdma_usart3_rx) != HAL_OK)

{

Error_Handler();

}

__HAL_LINKDMA(huart,hdmarx,hdma_usart3_rx);

hdma_usart3_tx.Instance = DMA1_Stream3;

hdma_usart3_tx.Init.Channel = DMA_CHANNEL_4;

hdma_usart3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;

hdma_usart3_tx.Init.PeriphInc = DMA_PINC_DISABLE;

hdma_usart3_tx.Init.MemInc = DMA_MINC_ENABLE;

hdma_usart3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

hdma_usart3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;

hdma_usart3_tx.Init.Mode = DMA_NORMAL;

hdma_usart3_tx.Init.Priority = DMA_PRIORITY_LOW;

hdma_usart3_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

hdma_usart3_tx.XferCpltCallback = &DMATransferComplete;

if (HAL_DMA_Init(&hdma_usart3_tx) != HAL_OK)

{

Error_Handler();

}

__HAL_LINKDMA(huart,hdmatx,hdma_usart3_tx);

#stm32f7 #hal_uart_transmit_dma #interrupt #dma #stm32f767
5 REPLIES 5
Oliver Beirne
Senior
Posted on January 24, 2017 at 11:14

Hello

I have moved your post to the

https://community.st.com/community/stm32-community/stm32-forum?sr=search&searchId=0445f8b7-528c-419e-8c3d-1fe561f8525f&searchIndex=0

‌ where someone should be able to assist you.

Thanks

Oli

Imen.D
ST Employee
Posted on January 25, 2017 at 11:52

Hello

Zarzycki.Mikolaj.002

,

I suggest that you run and test the UARTexample withinthe last version of STM32CubeF7 firmware package relevant to the STM32 device you are using. This will help you on UARTconfiguration and identify

the root cause of reception error.

You may review the UART example using DMA under this path: STM32Cube_FW_F7_V1.6.0\Projects\STM32F769I_EVAL\Examples\UART

Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on January 25, 2017 at 11:58

Hi,

But there is no information how to use IT (interrupt) mode of DMA. I have problem with it, no with other modes

:(

I want use 

HAL_DMA_Start_IT, not HAL_UART_Receive_DMA or  HAL_UART_Transmit_DMA.

Thank you

Regards

Mikołaj

Posted on January 26, 2017 at 10:43

Hi Mikolaj Z,

Refer to the

http://www.st.com/content/ccc/resource/technical/document/user_manual/45/27/9c/32/76/57/48/b9/DM00189702.pdf/files/DM00189702.pdf/jcr:content/translations/en.DM00189702.pdf

 'Description of STM32F7xx HAL drivers', this will help you with more information about using DMA on 

interrupt mode.

Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on January 26, 2017 at 14:02

Hi

Zarzycki.Mikolaj.002

‌,

My 2 cents, just a few ideas I would check, hope it could help :

- Ensure your USART is properly configured in both TXRX, not TX only (If I dare suggesting this check, it is because I already did fail on similar easy traps 😉 )

- When you mentioned it is working perfectly in Tx direction, it means if you set breakpoint in DMATransferComplete() callback, then you reach it, right ? But when doing same on RX, DMAReceiveComplete() is never called ?

- Did you try to 'validate' the Rx path by executing a reception procedure in polling mode for example (to ensure characters are properly received on USART level.

- Could you check if at time of starting reception (or after reception expected to be completed), RX is not blocked due to previous errors as Overrun (if so, further bytes reception might not be handled till error flags are cleared in ICR) ?

- when breaking after reception is expected to be completed, if you dump your Rx buffer (uRxBuff), is there any received bytes in it (empty or only some missing bytes preventing to complete Rx) ?

- Please try to initialize the XferErrorCallback field of your Rx DMA to an error callback you create, and check if it is called.

Regards

Guenael