2017-01-24 02:07 AM
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 transmitterBut 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 receiverDMA 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 #stm32f7672017-01-24 02:14 AM
Hello
I have moved your post to the
‌ where someone should be able to assist you.Thanks
Oli
2017-01-25 02:52 AM
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
2017-01-25 03:58 AM
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
2017-01-26 02:43 AM
Hi Mikolaj Z,
Refer to the
'Description of STM32F7xx HAL drivers', this will help you with more information about using DMA oninterrupt mode.
Regards
Imen
2017-01-26 06:02 AM
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