Skip to main content
Explorer II
May 26, 2025
Solved

adc fails to initialize

  • May 26, 2025
  • 14 replies
  • 1445 views

Board: stm32h753zi nucleo

Firmware & CubeMX: latest version

I have configured the adc to continous conversion and DMA output. The initialization fails in main.c in HAL_ADC_INIT. I stepped through the HAL lib and saw that LL_ADC_IsInternalRegulatorEnabled returns the HAL_ERROR.

The docstring of this function says

 /* Verification that ADC voltage regulator is correctly enabled, whether */
 /* or not ADC is coming from state reset (if any potential problem of */
 /* clocking, voltage regulator would not be enabled). */
 if (LL_ADC_IsInternalRegulatorEnabled(hadc->Instance) == 0UL)

I do not find any documents online which describe how the clock frequency of the adc should be set up. Could you please give me a hint.

    This topic has been closed for replies.
    Best answer by mo_krauti

    I discovered my error. I have built some cpp classes as abstractions for io functionality. There is also an analog class in which I started the analog DMA transfer in the constructor. Then I created an global instances of this class so the constructor interfered with the ADC startup logic in main. I was sure that the error could not originate from my abstraction code because the fault already occurred in the CubeMX generated main.c, but I did not think of the constructor of the global variable also being called at startup.

    Thank you very much for your help.

    14 replies

    Super User
    May 26, 2025

    You set the adc clock in clock tree ->

    AScha3_0-1748274126240.png

    and then choose in adc settings...

    AScha3_1-1748274217362.png

    + in ds see the limits :

    AScha3_2-1748274380844.png

     

     

    mo_krautiAuthor
    Explorer II
    May 27, 2025

    Thank you for your answer.

    In which document is this ADC table? I looked into the RM, PM and Nucleo 144 UM.

    Also I tried different clock inputs (80, 64, 32, 16 MHz) but the error still occors.

    Super User
    May 27, 2025

    >In which document is this ADC table?

    in ds , as i wrote. 

    AScha3_0-1748329732868.png

     

    +

    >but the error still occors.

    To be true: i never seen this problem...but i dont have the H753 , i use H743 ; ( but its same chip , DIE450 );

    So : if you get no warnings, when you  "generate code" , then maybe a problem with the Cube/lib version;

    i run IDE1.18.1 , +  STM32CubeH7 Firmware Package V1.12.1 / 06-December-2024

    Try update, if yours is old.

    mo_krautiAuthor
    Explorer II
    May 28, 2025

    I also use STM32CubeH7 Firmware Package V1.12.1 and CubeMX v6.14.1

    I do not get any warnings. I tried lowering the clock speed to 4MHz, but the error still occurs.

    Super User
    May 28, 2025

    Did you any tests for ADC ok or not?

    I would try: 

    Set in Cube ADC for a simple conversion: just one rank, on a channel, no dma, no oversampling, no continuous mode, just plain basic default settings.

    Set ADC clock to any medium frequency for your vos range and core speed, maybe 20 MHz.

    After init call ADC calibration,

    Then call Hal ADC conversion in blocking mode...and tell , what comes out.

    mo_krautiAuthor
    Explorer II
    June 10, 2025

    I was able to setup the adc in a separate project, but I am still unable to reproduce it in the original one.

    The HAL ADC State reports as

    272 = 0x110

    which correspondents to 

    #define HAL_ADC_STATE_ERROR_INTERNAL (0x00000010UL) /*!< Internal error occurrence */
    // and
    #define HAL_ADC_STATE_REG_BUSY (0x00000100UL) /*!< A conversion on ADC group regular is ongoing or can occur (either by continuous mode,
     external trigger, low power auto power-on (if feature available), multimode ADC master control (if feature available)) */

     What could cause the internal error?

    Super User
    June 10, 2025

    Probably just wrong setting.

    mo_krautiAuthor
    Explorer II
    June 10, 2025

    In addition all adc1 registers are set to 0.

    Super User
    June 10, 2025

    > all adc1 registers are set to 0

    That usually means, that the ADC AHB clock is not enabled (ADC is a dual-clock peripheral, AHB clock allows to access the registers and kernel clock controls the converter itself). Check RCC_AHB1ENR.ADC12EN.

    JW

    mo_krautiAuthor
    Explorer II
    June 10, 2025

    Thank you, in fact it really is disabled:

    ADC12EN: 0 ADC1/2 Peripheral Clocks Enable

    Do I have to enable it manually in CubeMX. I do not remember doing it in the other working CubeMX project.

    Super User
    June 10, 2025

    I don't know, I don't use CubeMX, sorry. I would assume it gets set automatically once you start using that peripheral in CubeMX.

    But you can check the other working CubeMX project, there should be some macro enabling that clock, and then try to find it in the non-working CubeMX project.

    JW

    mo_krautiAuthor
    Explorer II
    June 11, 2025

    I stepped through the adc initialization using the debugger once again.

    In /Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc.c:

     /* Actions performed only if ADC is coming from state reset: */
     /* - Initialization of ADC MSP */
     if (hadc->State == HAL_ADC_STATE_RESET)
     {
    #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
     // not set, left it out for better readability
    #else
     /* Init the low level hardware */
     HAL_ADC_MspInit(hadc);
    #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
    
     /* Set ADC error code to none */
     ADC_CLEAR_ERRORCODE(hadc);
    
     /* Initialize Lock */
     hadc->Lock = HAL_UNLOCKED;
     }

    But the hadc1 state is 0x100, so HAL_ADC_MspInit is never called. This is the method enabling the ADC clock, so it is never enabled.
    I tried manually calling this method before the generated ADC setup method, but this still resulted in a hardfault. When I just added a call to the  __HAL_RCC_ADC12_CLK_ENABLE(); macro, the hardfault disappeared. But I do not think that the adc will work because the adc clock, the gpio channels and the dma are also configured in HAL_ADC_MspInit.

    Super User
    June 11, 2025

    > But the hadc1 state is 0x100

    Why? Where is it set so (data breakpoint a.k.a. watchpoint on that variable may reveal this)? What does that mean? And what's the value of HAL_ADC_STATE_RESET?

    JW

    mo_krautiAuthor
    Explorer II
    June 12, 2025

    HAL_ADC_STATE_RESET is 0x00000000UL

    I used a write memory breakpoint to watch hadc1.State. After resetting the board the State variable is already set to 0x00000100UL HAL_ADC_STATE_REG_BUSY on the first breakpoint.
    Then the failed LL_ADC_IsInternalRegulatorEnabled function called mentioned in my original post cause the State to change to 0x00000110UL, so HAL_ADC_STATE_ERROR_INTERNAL is also set.