cancel
Showing results for 
Search instead for 
Did you mean: 

STM32Cube_FW_H7_V1.3.0: HAL_ADC_ConfigChannel refuses to configure an internal path on ADC3 if ADC1 or ADC2 is already enabled

Lines 2558~ of Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc.c does this.

However, it's not certain if ADC3 belongs to the same group as ADC1 or ADC2. If not, the use of ADC_ANY_OTHER_ENABLED is too restrictive, as we are working here only for internal paths which is available only for ADC3.

Thoughts?

2558         /* Software is allowed to change common parameters only when all ADCs   */
2559         /* of the common group are disabled.                                    */
2560         if ((ADC_IS_ENABLE(hadc) == RESET)   &&
2561            (ADC_ANY_OTHER_ENABLED(hadc) == RESET) )
2562         { 
2563           /* Enable Temperature sensor measurement path (channel 18)            */
2564           /* Note: Temp. sensor internal channels available on ADC3    */
2565           if ((sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) && ((hadc->Instance == ADC3)))
2566           {  
2567              SET_BIT(tmpADC_Common->CCR, ADC_CCR_TSEN);
2568             
2569             /* Wait loop initialization and execution */ 
2570             /* Note: Variable divided by 2 to compensate partially          */
2571             /*       CPU processing cycles.                                 */
2572             wait_loop_index = (ADC_TEMPSENSOR_DELAY_US * (SystemCoreClock / (1000000 * 2)));
2573             while(wait_loop_index != 0)
2574             { 
2575               wait_loop_index--;
2576             }
2577           }
2578           /* If Channel 18 is selected, enable VBAT measurement path.           */
2579           /* Note: VBAT internal internal channels available on ADC1 and ADC3   */ 
2580           else if ((sConfig->Channel == ADC_CHANNEL_VBAT_DIV4) && ((hadc->Instance == ADC3)))
2581           { 
2582             SET_BIT(tmpADC_Common->CCR, ADC_CCR_VBATEN);
2583           }
2584           /* If Channel 19 is selected, enable VREFINT measurement path          */
2585           /* Note: VBAT internal internal channels available on ADC1 only       */ 
2586           else if ((sConfig->Channel == ADC_CHANNEL_VREFINT) && (hadc->Instance == ADC3))
2587           { 
2588             SET_BIT(tmpADC_Common->CCR, ADC_CCR_VREFEN);
2589           }
2590         }
2591         /* If the requested internal measurement path has already been          */
2592         /* enabled and other ADC of the common group are enabled, internal      */
2593         /* measurement paths cannot be enabled.                                 */
2594         else
2595         { 
2596           /* Update ADC state machine to error */
2597           SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
2598           
2599           tmp_hal_status = HAL_ERROR;
2600         }

2 REPLIES 2
S.Ma
Principal

On STM32F437, internal vref, temperature signals are wired only on ADC1. Did you make sure from the datasheet that the attempted channel do exist on the selected ADC?

Yeap.

0690X000006D50SQAS.png