cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] Why does my external clock (HSE) configuration not work?

NGros
Associate III

Hi all!

I got something new for you. We have a pcb with an STM32f446re chip on it. For stability reason, we put an 20Mhz external clock on it, but the problem is, we are still running on 16Mhz (measured it with a toggled gpio on the oscilloscope.) The pulse should be 500ms long but results in 625ms.

Now, here is the system clock init function which is calles FIRST in the main:

void system_clock_config()

{

    RCC_OscInitTypeDef rcc_osc_init {};

    RCC_ClkInitTypeDef rcc_clk_init {};

    __HAL_RCC_PWR_CLK_ENABLE();

    __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

    rcc_osc_init.OscillatorType = RCC_OSCILLATORTYPE_HSE;

    rcc_osc_init.HSIState = RCC_HSI_OFF;

    rcc_osc_init.HSEState = RCC_HSE_ON;

    rcc_osc_init.PLL.PLLState = RCC_PLL_ON;

    rcc_osc_init.PLL.PLLSource = RCC_PLLSOURCE_HSE;

    rcc_osc_init.PLL.PLLM = 10;

    rcc_osc_init.PLL.PLLN = 100;

    rcc_osc_init.PLL.PLLP = RCC_PLLP_DIV2;

    rcc_osc_init.PLL.PLLQ = 2;

    rcc_osc_init.PLL.PLLR = 2;

    if (HAL_RCC_OscConfig(&rcc_osc_init) != HAL_OK)

    {

        while (true) {}

    }

    rcc_clk_init.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

                                |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

    rcc_clk_init.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

    rcc_clk_init.AHBCLKDivider = RCC_SYSCLK_DIV1;

    rcc_clk_init.APB1CLKDivider = RCC_HCLK_DIV4;

    rcc_clk_init.APB2CLKDivider = RCC_HCLK_DIV2;

    if (HAL_RCC_ClockConfig(&rcc_clk_init, FLASH_LATENCY_3) != HAL_OK)

    {

        while (true) {}

    }

}

I created these configurations with help of cubeMX clock_configuration tool, it's all calculated for an 20Mhz HSE oscillator input.

EDIT: We unmounted the 20mhz oscillator and the programm did not start, so i guess HSE is working, but still, on 16Mhz. Why could that be?

Strongly appreciate your suggestions,

NG

1 ACCEPTED SOLUTION

Accepted Solutions

An external *clock source* would want to be using HSE BYPASS mode

Check definition of HSE-VALUE, typically in stm32fxxx_hal_conf,h

Measure internal clock nodes via MCO / PA8 pin, route signals there to scope.

Unpack RCC CLK/PLL settings to get understanding of what chip thinks it's doing. Start with printing AHB, APB1, APB2 clocks

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

View solution in original post

3 REPLIES 3

First try only to enable HSE (without changing system clock source) and output it to an MCO pin, to observe.

JW

An external *clock source* would want to be using HSE BYPASS mode

Check definition of HSE-VALUE, typically in stm32fxxx_hal_conf,h

Measure internal clock nodes via MCO / PA8 pin, route signals there to scope.

Unpack RCC CLK/PLL settings to get understanding of what chip thinks it's doing. Start with printing AHB, APB1, APB2 clocks

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

Thanks @Community member​ , your advice with the stm32fxxx_hal_conf,h HSE definition was correct, it was defined as 25MHz instead of 20Mhz.