cancel
Showing results for 
Search instead for 
Did you mean: 

[HAL Bug Report] STM32G474 Cannot use "HAL_ADC_Start_DMA" with ADC5 when ADC3 and ADC4 configured in dual regular mode

KYin.2
Associate II

Here is the code in question:

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

Since ADC5 shares its multimode configuration register with ADC3 and ADC4, trying to invoke HAL_ADC_Start_DMA with hadc5 when ADC3 and ADC4 are configured for dual regular mode returns HAL error.

I tried modifying the code as shown below and ADC5 works without issues (samples are accurate, DMA callbacks invoked at expected rate).

HAL_StatusTypeDef User_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 ((ADC_IS_INDEPENDENT(hadc))
       || (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

I was wondering if this is going to be addressed in a HAL update?

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Amel NASRI
ST Employee

Hi @KYin.2​ ,

First of all thanks for your interest on STM32 products & mainly the ADC peripheral.

Your feedback is valuable to enhance the provided solutions. I'll share it as well as the solution you are suggesting with our development team.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
Amel NASRI
ST Employee

Hi @KYin.2​ ,

First of all thanks for your interest on STM32 products & mainly the ADC peripheral.

Your feedback is valuable to enhance the provided solutions. I'll share it as well as the solution you are suggesting with our development team.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Amel NASRI
ST Employee

Internal ticket number: 112389 (PS: This is an internal tracking number and is not accessible or usable by customers). 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.