Skip to main content
Visitor II
August 26, 2021
Solved

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

  • August 26, 2021
  • 2 replies
  • 1175 views

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.

    This topic has been closed for replies.
    Best answer by Amel NASRI

    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

    2 replies

    Technical Moderator
    August 26, 2021

    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

    Technical Moderator
    August 26, 2021

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