2025-04-21 3:01 AM
Hello,
I am using STM32F769 microcontroller. I have used Cube MX to configure USART1 for Tx and Rx and DMA channels 2 and 7. I have started a data transmission using HAL_DMA_Start function but noting is happening. Using debugger I have found that in USART1 CR3 the DMAT and DMAR are reset. When I put a break point at the point where HAL_DMA_Start is called and manually set DMAT in CR3 the data is transmitted. Have I missed something in the configuration of USART1 and DMA or do I need to write some code to set these bits after the MX generated initialisation code has finished?
Thanks
2025-04-21 3:11 AM - edited 2025-04-21 4:57 AM
Hello @chris239955_stm1_stmicro_com
First let me thank you for posting.
Based on your description, let's try to add the following line of code :
USART1->CR3 |= UART_DMA_RX_ENABLE | UART_DMA_TX_ENABLE;
Consider using the functions
The HAL_UART_Receive_DMA function is used to start receiving data via DMA.
The HAL_UART_Transmit_DMA function is used to start transmitting data via DMA.
Could you please provide your IOC.
THX
Ghofrane
2025-04-21 4:44 AM
HAL_UART_Start_DMA should be used to initiate sending data, not HAL_DMA_Start.
2025-04-21 8:08 AM
Hi Ghofrane,
I had already tried the code setting CR3 and that works but I am surprised I have to do that. I was expecting the MX system to have done that as part of the configuration. I wasted time having to track down why the configuration did not work. The examples on line showing how to use the USART in conjunction with the DMA do not show the need to set CR3 in this way.
MX calls MX_DMA_Init(); and MX_USART1_UART_Init();
/**
* Enable DMA controller clock
*/
static void MX_DMA_Init(void)
{
/**
* @brief USART1 Initialization Function
* @param None
* @retval None
*/
static void MX_USART1_UART_Init(void)
{
/* USER CODE BEGIN USART1_Init 0 */
/* USER CODE END USART1_Init 0 */
/* USER CODE BEGIN USART1_Init 1 */
/* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_DMADISABLEONERROR_INIT;
huart1.AdvancedInit.DMADisableonRxError = UART_ADVFEATURE_DMA_DISABLEONRXERROR;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */
/* USER CODE END USART1_Init 2 */
}
/* DMA controller clock enable */
__HAL_RCC_DMA1_CLK_ENABLE();
__HAL_RCC_DMA2_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Stream5_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn);
/* DMA2_Stream2_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);
/* DMA2_Stream7_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Stream7_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream7_IRQn);
}
There is no inversion control. The software starts the USART DMA transmission using the call
HAL_DMA_Start(&hdma_usart1_tx, (uint32_t)StartupMessage, (uint32_t)(&huart1.Instance->TDR), StartupMesageLength);
then the transfer finished flag is polled in the state-machine until the transfer is finished then the state-machine advances.
Thanks,
Chris
2025-04-21 8:37 AM
2025-04-21 9:16 AM
What is my IOC?
2025-04-22 12:46 AM - edited 2025-04-22 2:44 AM
Hello @chris239955_stm1_stmicro_com
Go to your project folder and upload the file with the extension .ioc as shown in the screenshot.(example)
A ticket has been raised to the development team to further investigate this behavior.
Internal ticket number 208271 .
THX
Ghofrane