cancel
Showing results for 
Search instead for 
Did you mean: 

unable to receive data on USART3 using DMA

debug
Associate III

Hi,

I need to configure DMA for the Rx path of my USART data. I was able to get the Tx path going correctly following this thread: https://community.st.com/t5/stm32cubeide-mcus/problem-adding-usart3-functionality-to-lwip-http-server-netconn/m-p/668703#M26841

Now for the Rx path, the DMA gets setup in HAL_UART_MspInit() & this was copied as generated by CubeMX, i.e. and it's working on the other project (with CubeMX enabled) fine:

else if(huart->Instance==USART3)
{
/* Peripheral clock enable */
__HAL_RCC_USART3_CLK_ENABLE();

__HAL_RCC_GPIOD_CLK_ENABLE();
/**USART3 GPIO Configuration
PD8 ------> USART3_TX
PD9 ------> USART3_RX
*/
GPIO_InitStruct.Pin = XZaber_TX_Pin|XZaber_RX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

/* USART3 DMA Init */
/* USART3_RX 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_CIRCULAR;
hdma_usart3_rx.Init.Priority = DMA_PRIORITY_LOW;
hdma_usart3_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
if (HAL_DMA_Init(&hdma_usart3_rx) != HAL_OK)
{
Error_Handler();
}

__HAL_LINKDMA(huart,hdmarx,hdma_usart3_rx);

/* USART3 interrupt Init */
HAL_NVIC_SetPriority(USART3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(USART3_IRQn);
}

  Now in my project without CubeMX, I'm explicitly starting the DMA clocks by calling : __HAL_RCC_DMA1_CLK_ENABLE() and also the following lines are called too during init:

 rv = HAL_UART_Receive_DMA(&huart1, OMRxDat, OM20_MEAS_GET_RXLEN);
rv = HAL_UART_Receive_DMA(&huart3, ZabRxDat, sizeof(ZabRxDat));

I can see that data is coming in on the scope (as a reply to what I send out) but none of the callbacks get invoked. I am checking UART_DMAReceiveCplt(), UART_DMARxHalfCplt & UART_DMAError(). What am I missing for the callback in my program void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) to kick in when data is received?

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

Try to inspire from one of examples using DMA like this one: https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM324x9I_EVAL/Examples/UART/UART_Hyperterminal_DMA

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS: This is NOT an online support (https://ols.st.com) but a collaborative space. So please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help/support.

View solution in original post

2 REPLIES 2
SofLit
ST Employee

Try to inspire from one of examples using DMA like this one: https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM324x9I_EVAL/Examples/UART/UART_Hyperterminal_DMA

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS: This is NOT an online support (https://ols.st.com) but a collaborative space. So please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help/support.

Excellent, Thanks with the information found in this link I was able to get it going!