cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G4xx HAL Driver V1.2.5 Issue with DMAMUX

Penguins
Associate

Hello ST,

I would like to report a bug in the <stm32g4xx_hal_dma.c> file (V1.2.5). In the function DMA_CalcDMAMUXChannelBaseAndMask(DMA_HandleTypeDef *hdma), there's an error in calculating hdma->DMAmuxChannelStatusMask. For DMA2 channels, the channel_number should be adjusted by adding 8, 6, or 7 according to the MCU category. Otherwise, it will NOT be able to correctly determine and clear the synchronization overrun interrupt of the corresponding channel.

To give you a better understanding of the issue, I've included some relevant code snippets with comments at Line 32 below:

/**
  * @brief  Updates the DMA handle with the DMAMUX  channel and status mask depending on stream number
  * @PAram  hdma        pointer to a DMA_HandleTypeDef structure that contains
  *                     the configuration information for the specified DMA Stream.
  * @retval None
  */
static void DMA_CalcDMAMUXChannelBaseAndMask(DMA_HandleTypeDef *hdma)
{
  uint32_t dmamux_base_addr;
  uint32_t channel_number;
  DMAMUX_Channel_TypeDef *DMAMUX1_ChannelBase;

  /* check if instance is not outside the DMA channel range */
  if ((uint32_t)hdma->Instance < (uint32_t)DMA2_Channel1)
  {
    /* DMA1 */
    DMAMUX1_ChannelBase = DMAMUX1_Channel0;
  }
  else
  {
    /* DMA2 */
#if defined (STM32G471xx) || defined (STM32G473xx) || defined (STM32G474xx) || defined (STM32G414xx) || defined (STM32G483xx) || defined (STM32G484xx) || defined (STM32G491xx) || defined (STM32G4A1xx) || defined (STM32G411xC)
    DMAMUX1_ChannelBase = DMAMUX1_Channel8;
#elif defined (STM32G411xB) || defined (STM32G431xx) || defined (STM32G441xx) || defined (STM32GBK1CB)
    DMAMUX1_ChannelBase = DMAMUX1_Channel6;
#else
    DMAMUX1_ChannelBase = DMAMUX1_Channel7;
#endif /* STM32G4x1xx) */
  }
  dmamux_base_addr = (uint32_t)DMAMUX1_ChannelBase;
  channel_number = (((uint32_t)hdma->Instance & 0xFFU) - 8U) / 20U;
  /** Code should be added here to distinguish DMA2 channels from DMA1 ones. **/
  hdma->DMAmuxChannel = (DMAMUX_Channel_TypeDef *)(uint32_t)(dmamux_base_addr + ((hdma->ChannelIndex >> 2U) * ((uint32_t)DMAMUX1_Channel1 - (uint32_t)DMAMUX1_Channel0)));
  hdma->DMAmuxChannelStatus = DMAMUX1_ChannelStatus;
  hdma->DMAmuxChannelStatusMask = 1UL << (channel_number & 0x1FU);
}

Best regards,
Penguins

0 REPLIES 0