cancel
Showing results for 
Search instead for 
Did you mean: 

Can I use ADC5 in standalone mode when ADC34 are in Dual Mode ? Code fail to start ADC5 . Documentation missing data.

MMatj.1
Associate II

Hello ST community,

I use ADC3, 4 and 5 of STM32G474 and configure them to ADC3/4 dual mode, ADC5 standalone (no other option in CubeMx).

HAL function HAL_ADC_Start_DMA fail for ADC5 , because it check if it is in correct mode of ADC3 master.

So there is many questions:

  • is ADC5 part of ADC345 dual mode block? (in documentation and code it is so, ADC345_Common is such register block) .
  • How to use triple ADC in Dual mode ? Documentation missing ?
  • Can ADC5 stand alone be used same time with ADC34 Dual mode ? I tried to initialize ADC5 and start it manually with ADC34 dual, looks like it works, but what regression can I await.

I hope it's just HAL code fix and hardware work as needed (ADC1/2 dual , ADC3/4 dual, ADC5 stand alone).

Code related to problem from stm32g4xx_hal_adc.c :

HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length)
{
  HAL_StatusTypeDef tmp_hal_status;
#if defined(ADC_MULTIMODE_SUPPORT)
  uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
#endif
 
  /* Check the parameters */
  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
 
  /* Perform ADC enable and conversion start if no conversion is on going */
  if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
  {
    /* Process locked */
    __HAL_LOCK(hadc);
 
#if defined(ADC_MULTIMODE_SUPPORT)
    /* Ensure that multimode regular conversions are not enabled.   */
    /* Otherwise, dedicated API HAL_ADCEx_MultiModeStart_DMA() must be used.  */
    if ((tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
        || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT)
        || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN)
       )
#endif
    {
      ...................................
    }
#if defined(ADC_MULTIMODE_SUPPORT)
    else
    {
      tmp_hal_status = HAL_ERROR;
      /* Process unlocked */
      __HAL_UNLOCK(hadc);
    }
#endif
  }
  else
  {
    tmp_hal_status = HAL_BUSY;
  }
 
  /* Return function status */
  return tmp_hal_status;
}

ADC3/4 is configured for Dual regular simultaneous mode only,

so why ADC5 check this mode?

ADC345_common not configured to any of "if" condition and function return HAL_ERROR for ADC5 , I hope such behavior is buggy.

Best regards,

Maksims M.

2 REPLIES 2
MMatj.1
Associate II

BUG ,

Will this be solved in future HAL library ?

KYin.2
Associate II

This is in fact a bug in the HAL and I have also run into this issue when configuring ADC3 and ADC4 for dual mode.

I've tried working around it by enabling ADC5 before configuring ADC3 and ADC4, but this does not seem to work, and ADC4 does not start properly.

The other workaround I tried that did work was modifying the HAL function to check if the ADC instance is ADC5 at line 23. ADC5 works properly when ADC3 and ADC4 are configured for dual mode. However, this workaround is not possible if using STM32CubeIDE as the cubemx plugin regenerates the HAL each time code is generated.

This bug is still present in the most recent G4 firmware package.

This bug stems from the fact that ADC5 shares its multimode configuration registers with ADC3 and ADC4, which doesn't make sense, whatever saves silicon I guess?

It seems that the other workaround would be to copy the HAL function and create a user function that does the same thing or start the ADC with DMA using the LL drivers rather than the HAL.

I hope that ST fixes this bug soon.