cancel
Showing results for 
Search instead for 
Did you mean: 

System Clock Mux HSE doesn't work

gordon2399
Associate II
Posted on June 04, 2014 at 02:51

Hi,

I am using the STM32F415RGT.  A 50MHz oscillator is connected to the HSE input.  In the STM32CubeMX Clock Configuration tab, I selected HSE for the System Clock Mux.  Supposedly the system clock should be driven directly by the oscillator.

But when I run the code, the system appears to run at 16MHz, that is the speed of the HSI.

I thought my oscillator is bad, but when I enable the PLL and choose PLLCLK on the system clock mux, the code runs at the expected SYSCLK rate.  So that means the oscillator is good and is connected to the system correctly.

Does anybody know why the system selects to use the HSI as the input clock instead of the HSE as I selected in the STM32CubeMX?

The system clock configuration code looks like this:

static void SystemClock_Config(void)

{

  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  RCC_OscInitTypeDef RCC_OscInitStruct;

  __PWR_CLK_ENABLE();

  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;

  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;

  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;

  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;

  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);

}

thanks,

Gordon

#hse-config
3 REPLIES 3
Posted on June 04, 2014 at 03:44

Isn't fOSC_IN (max) 26 MHz? I seem to recall on of the other parts spec'd out to 32 MHz

I know it mentions this in a crystal context, but I don't recall seeing it specified anywhere else. Yes, TCXO/OCXO type clock sources would need to be used in BYPASS mode.

I think you should be able to route HSE via the MCO (PA8) pin, so it might be worth observing that at the 50 MHz rate.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 04, 2014 at 03:52

I might try with the Standard Library, and depending on the operating voltage, a flash wait state of 2

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mda2376
Associate II
Posted on June 04, 2014 at 18:06

Since you're not using the PLL, be sure to set:

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

In your sample code PLLState is uninitialized and may be causing HAL_RCC_OscConfig() to do something you don't expect.