Skip to main content
Explorer
October 29, 2024
Solved

STM32H743VIT6 SystemClock_Config ends in Error_Handler...

  • October 29, 2024
  • 10 replies
  • 7731 views

Hey Guys,

I have problems about configure my STM32H743VIT SysClock.

On my own PCB, i have a Crystal with 8 MHZ, and a LSE of 32.768 khz.

Settings are in my Screenshots, now if i debug my application, it ends in a Error Handler.. but why?

BTW: UART4,5,7 and USART1,2 enabled, and USB_DEVICE + USB_HOST is enabled.

 

 

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler(); /** JUMPS TO ERROR_HANDLER **/
 }

 

 

my complete SystemClockConfig:

 

 

void SystemClock_Config(void)
{
 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 /** Supply configuration update enable
 */
 HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);

 /** Configure the main internal regulator output voltage
 */
 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);

 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}

 /** Initializes the RCC Oscillators according to the specified parameters
 * in the RCC_OscInitTypeDef structure.
 */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;
 RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
 RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
 RCC_OscInitStruct.PLL.PLLM = 1;
 RCC_OscInitStruct.PLL.PLLN = 24;
 RCC_OscInitStruct.PLL.PLLP = 2;
 RCC_OscInitStruct.PLL.PLLQ = 4;
 RCC_OscInitStruct.PLL.PLLR = 2;
 RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
 RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
 RCC_OscInitStruct.PLL.PLLFRACN = 0;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler(); /** JUMPS TO ERROR_HANDLER **/
 }

 /** Initializes the CPU, AHB and APB buses clocks
 */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
 |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
 RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
 RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
 RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
 {
 Error_Handler();
 }
}

 

 

 Thank you :)

    This topic has been closed for replies.
    Best answer by mƎALLEm

    Hello @Sany ,

    your attached ioc file is setting the system clock to 64Mhz with HSI.

    I'm very confused. We need to converge.

    So to conclude: if you have

    Rev Y: Max system clock is 400MHz at VOS1.

    Rev V: Max system clock is 480MHz at VOS0.

    I'm attaching your ioc file with some modifications I did to set the crystal at 8MHz and system clock at 400MHz at VOS1 (this is working on rev Y and Rev V) / with:

     RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
     RCC_OscInitStruct.HSEState = RCC_HSE_ON;
     RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
     RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

    If this config doesn't work:

    - You need first to add CL capacitors (even I'm not sure this is the issue).

    - Replace your crystal. It could be something related to the crystal.

    Hope it helps.

     

     

     

    10 replies

    Super User
    October 29, 2024

    @Sany wrote:

    i debug my application, it ends in a Error Handler.. but why? :)


    Find out how it gets there!

    What error code does HAL_RCC_OscConfig() return?

    Where, exactly, does it return this?

    Graduate II
    October 29, 2024

    You have ALL the source code, debug the issue, understand why the library returned an error. Work backward to the point the error is initially flagged.

    You have a CRYSTAL or an XO (CRYSTAL OSCILATOR) ?

    The BYPASS is for the HSE Input from a TCXO, VCXO, OCXO type clock.

    If the clocks are not working, it's not going to be able to clock the processor, or the PLL, or for that to lock.

    Technical Moderator
    October 29, 2024

    Hello,

    You said:


    @Sany wrote:

    On my own PCB, i have a Crystal with 8 MHZ, and a LSE of 32.768 khz.

     

     And in your code you set HSE in Bypass mode:

     RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;

    Are you sure you are using a Crystal  and not a Crystal oscillator

    Because in case of Crystal/resonator you need to set the HSE source as the following:

    RCC_OscInitStruct.HSEState = RCC_HSE_ON;

    Hope it helps.

     

    Technical Moderator
    October 29, 2024

    Note that the screenshots you shared are not inline with the code:

    Here you set HSI as System clock source:

    SofLit_0-1730219762871.png

    In your code:

     

     RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
     RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

     

     So need to clarify what you are really testing!

    SanyAuthor
    Explorer
    October 29, 2024

    Hello,

     

    Sorry, I have a XO with 8 MHZ and 2 Pins, the Code jumps to the Error_Handler while Waiting for HSE has been ready. I checked with my osci, and i get a 8 MHZ signal from the XO.

     

     /* Wait till HSE is ready */
     while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == 0U)
     {
     if ((uint32_t)(HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE)
     {
     return HAL_TIMEOUT;
     }
     }
     }

     (Error Code is HAL_TIMEOUT)

     

    Technical Moderator
    October 29, 2024

    @Sany wrote:

    Sorry, I have a XO with 8 MHZ and 2 Pins,


    Need to check again if you are using a crystal or crystal oscillator:

    SofLit_0-1730219932794.png

    At the left is a Crystal and at the right it's a crystal oscillator. The latter needs to be powered.

    Could you please share your schematics?

     

     

    Technical Moderator
    October 29, 2024
    SanyAuthor
    Explorer
    October 29, 2024

    Hello,

    Sorry for my confusion, the day is long...

    i have only a crystal on my pcb with 2 pins (not a crystal oscillator, with 3.3V supply), the crystal swings with 7.99997 MHZ on my oscilloscope.

     

    i check my schematic, and i  found a big problem, i have a crystal with 8mhz on 2 pins, but i forgot the decoupling condensators on the side to ground... :(

     

    i think, that was the problem..?

    Technical Moderator
    October 29, 2024

    @Sany wrote:

    the crystal swings with 7.99997 MHZ on my oscilloscope.

     


    Sorry I didn't undrstand, but you got the oscillation and 7.99997MHz is a good value. What's the problem then?

    I don't think CL could induce the described issue at the beginning.

    The CL are responsible to fine tune the frequency of the crystal:

    From AN2867 "Guidelines for oscillator design on STM8AF/AL/S and STM32 MCUs/MPUs":

    SofLit_0-1730234342075.png

    And you still didn't answer my question regarding what the exact config you are really using?

    Please answer the question from my previous comment:

    SofLit_1-1730234565987.png

    Bypass or not? you should not use Bypass in your case as you are using a Crystal.

    SanyAuthor
    Explorer
    October 30, 2024

    Hello,

    my configuration with crystal (no XO) 8 MHZ is this:

    void SystemClock_Config(void)
    {
     RCC_OscInitTypeDef RCC_OscInitStruct = {0};
     RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
    
     /** Supply configuration update enable
     */
     HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
    
     /** Configure the main internal regulator output voltage
     */
     __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
    
     while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
    
     /** Initializes the RCC Oscillators according to the specified parameters
     * in the RCC_OscInitTypeDef structure.
     */
     RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE;
     RCC_OscInitStruct.HSEState = RCC_HSE_ON;
     RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
     RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
     RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
     RCC_OscInitStruct.PLL.PLLM = 4;
     RCC_OscInitStruct.PLL.PLLN = 75;
     RCC_OscInitStruct.PLL.PLLP = 2;
     RCC_OscInitStruct.PLL.PLLQ = 8;
     RCC_OscInitStruct.PLL.PLLR = 2;
     RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_1;
     RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOMEDIUM;
     RCC_OscInitStruct.PLL.PLLFRACN = 0;
     if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
     {
     Error_Handler();
     }
    
     /** Initializes the CPU, AHB and APB buses clocks
     */
     RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
     |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
     |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
     RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
     RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
     RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
     RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
     RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
     RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
     RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
    
     if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
     {
     Error_Handler();
     }
    }

    Error_Handler is called by this function with HAL_TIMEOUT:

    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

     

     /* Check the HSE State */
     if (RCC_OscInitStruct->HSEState != RCC_HSE_OFF)
     {
     /* Get Start Tick*/
     tickstart = HAL_GetTick();
    
     /* Wait till HSE is ready */
     while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == 0U)
     {
     if ((uint32_t)(HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE)
     {
     return HAL_TIMEOUT;
     }
     }
     }

     i dont understand the problem, why the error is HAL_TIMEOUT.

    Super User
    October 30, 2024

    @Sany wrote:

     i dont understand the problem, why the error is HAL_TIMEOUT.


    It's waiting for the HSE to become ready - that is taking too long, so you get a timeout.

    So look at what might prevent the HSE from starting; eg, shorting both OSC_IN and OSC_out to ground would be a pretty effective way:

    AndrewNeil_0-1730276470166.png

     

    Technical Moderator
    October 30, 2024

    1- Did you solder CL load capacitors? 

    2- Please attach your ioc file.

    SanyAuthor
    Explorer
    October 30, 2024

    1. No, i can solder it tomorrow.

    2. my ioc in attached.

    Okay, it's the forgotten CL load capacitor, i tested my config with disabled HSE and enabled LSE, and it worked.
    *** it... this errors costs a little bit of time... thank you for help me!

    Technical Moderator
    October 30, 2024

    Hello,

    Just a question: your system clock is set to 75MHz, and the VOS is set to VOS2 while it needs to be set to VOS3:

    SofLit_1-1730282528082.png

    Did you set it manually or it was set automatically by CubeMx?

     

     

    SanyAuthor
    Explorer
    October 30, 2024

    Hey,

    I enabled only the HSE and LSE and changed my system clock to 160 MHZ in CubeMX.
    After i disabled my wrong soldered HSE, the system clock is changed to 75mhz after i clicked "resolve clock issues"
    CubeMX sets automatically the VOS2, i changed the VOS2 now to VOS3 manually.

    i created a new project, and CubeMX sets VOS to VOS0 and Product Revision to "Y". When i change the Product Revision to "V" then sets CubeMX VOS2.

    That's a good hint, i wouldn't have noticed it, because my code runs, after disabling the HSE.

    here is my corrected config, with VOS3, 160mhz, and disabled HSE.

    mƎALLEmAnswer
    Technical Moderator
    October 30, 2024

    Hello @Sany ,

    your attached ioc file is setting the system clock to 64Mhz with HSI.

    I'm very confused. We need to converge.

    So to conclude: if you have

    Rev Y: Max system clock is 400MHz at VOS1.

    Rev V: Max system clock is 480MHz at VOS0.

    I'm attaching your ioc file with some modifications I did to set the crystal at 8MHz and system clock at 400MHz at VOS1 (this is working on rev Y and Rev V) / with:

     RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
     RCC_OscInitStruct.HSEState = RCC_HSE_ON;
     RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
     RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

    If this config doesn't work:

    - You need first to add CL capacitors (even I'm not sure this is the issue).

    - Replace your crystal. It could be something related to the crystal.

    Hope it helps.

     

     

     

    Graduate II
    October 30, 2024

    If HSE doesn't start, perhaps use HSI (64 MHz) and gear *that* into the PLL.

    Get some mileage there whilst you figure out how to redesign the board with the right crystal and components to oscilate within a short/defined period.

    To monitor the crystal, don't clamp probes to it, you'll change the circuit characteristics, output the internal clocking via the MCO / PA8 pin option, where you're not loading the circuit.

    Super User
    October 30, 2024

    @Tesla DeLorean wrote:

    figure out how to redesign the board with the right crystal and components to oscilate within a short/defined period.


    @Sany After carefully studying the  AN2867 already mentioned by @mƎALLEm 

    Also AN4938Getting started with STM32H74xI/G and STM32H75xI/G MCU hardware development:

    https://www.st.com/resource/en/application_note/an4938-getting-started-with-stm32h74xig-and-stm32h75xig-mcu-hardware-development-stmicroelectronics.pdf

     

    You might also consider whether you'd be better off just using an oscillator ...

    AndrewNeil_0-1730306161151.png