2024-05-01 11:57 AM
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?
Solved! Go to Solution.
2024-05-01 12:13 PM
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
2024-05-01 12:13 PM
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
2024-05-01 02:32 PM
Excellent, Thanks with the information found in this link I was able to get it going!