2025-12-05 4:35 AM
Hi, everyone
I recently encountered a strange phenomenon. I opened three DMA channels on the STM32G474RBT6.
The first one is Channel 1 of DMA1 (circular mode), which is used for automatically collecting the data converted by ADC.
The second one is channel 8 of DMA2 (normal mode), which is used to transfer the calculated data to the timer for updating the PWM.
The third one is Channel 1 of DMA2, which (normal mode) is used to send serial port data of variable length. The first two did not enable the interrupt service function.
But if the DMA in the third case does not enable the interrupt, the serial port sending process will be stuck (the HAL library shows that the DMA2channel1 is in the “BUSY" state). If the interrupt is enabled, this situation will not occur.
However, the interrupt service of the first two I didn't enable DMA can still run normally. The data of the ADC can be automatically transmitted, and the timer can also send out the correct PWM signal. The priority of DMA has already been allocated and there should be no conflict issue. How did this situation occur?
2025-12-05 5:51 AM
Show your code.
DMA will generally need interrupts enabled to progress away from the BUSY state. There are examples for DMA-based UART you can follow.
2025-12-05 11:04 PM
HAL routines for communication interfaces use DMA interrupt AND the comm peripheral interrupt. Both must be enabled for UART, I2C, probably also others (I don't use HAL, so I am not sure).
2025-12-06 3:07 AM
Here is my DMA's configuration
ADC and TIM8 are normal but USART3 transmission fail when DMA2 channel1's interrupt is disable. Here is the code which generate by CubeMX.
void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMAMUX1_CLK_ENABLE();
__HAL_RCC_DMA2_CLK_ENABLE();
__HAL_RCC_DMA1_CLK_ENABLE();
/* DMA interrupt init */
/* DMA2_Channel1_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Channel1_IRQn, 2, 2);
HAL_NVIC_EnableIRQ(DMA2_Channel1_IRQn);
}ADC runs under the scan mode with the circular mode in DMA,TIM8 runs under the auto-reload disable with the normal mode in DMA, TIM8 only work when software is called.
2025-12-06 3:21 AM
I think ur right, it's strange that some DMA channels can still run when the DMA interrupt is disable. Maybe the Flag is cleared by the hardware automatically in some situations, so ADC and TIM8 can still run normally. Maybe this is caused by the variable-length data which the USART transmit, so the DMA need the interrupt function(created by HAL) to clear the flag by software.