cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743VIT6 SystemClock_Config ends in Error_Handler...

Sany
Associate III

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 :)

21 REPLIES 21
Andrew Neil
Evangelist III

@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?

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
SofLit
ST Employee

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.

 

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.

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!

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.
Sany
Associate III

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)

 


@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?

 

 

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.

@Sany wrote:

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


Nope: with only 2 pins, it can't be an XO (Crystal Oscillator).

A crystal oscillator is an active circuit - it requires power - so will need at least 3 pins (supply, ground, output).

 

Difference between just a crystal, and a crystal oscillator:

https://community.st.com/t5/stm32-mcus-products/stm32f4-osc-problem/m-p/664136/highlight/true#M241592

 

SofLit
ST Employee

+

https://www.sitime.com/company/newsroom/articles/do-you-know-when-use-crystal-or-oscillator-wrong-answer-can-cost-you

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.

If you are using TWO pins OSC_IN/OSC_OUT you are using a CRYSTAL

RCC_OscInitStruct.HSEState = RCC_HSE_ON;

 

For an XO you'd need ONE pin OSC_IN (4-25 MHz) and BYPASS mode, ie the STM32 is NOT simulating the crystal

RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; // Clock on OSC_IN, and OSC_OUT NOT VIABLE

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..