cancel
Showing results for 
Search instead for 
Did you mean: 

In STM32F091RBT6, 8MHz clock is not getting configured to 48MHz

Mgawa.1
Associate II

I am using STM32F091RBT6, in which I have 8Mhz internal clock and I have to configured it to the 48Mhz. I have selected PLL as a System clock source but its not getting configured to 48MHz. As I have debugged it, its getting configured to only up to 44MHz. If I try to configure it to 48MHz, code gets stuck.

Below is my configuration.

void fnSystemClockInit(void)
{
    RCC_ClocksTypeDef pointer;
 
    RCC_PCLKConfig(RCC_HCLK_Div1);   // PCLK prescaler
    RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK prescaler
 
    RCC_DeInit();                              // Internal 8 Mhz clock
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Set PLL as system clock
    RCC_ITConfig(RCC_IT_PLLRDY, ENABLE); // Enable PLL flag
 
    RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_CFGR_PLLMUL11); // Config PLL params
    RCC_PLLCmd(ENABLE);                                      // Enable PLL
    while ((RCC_GetFlagStatus(RCC_FLAG_PLLRDY)) != SET) ;     // wait while PLL is stable
 
    RCC_ClearITPendingBit(RCC_IT_PLLRDY); // Clear the PLL flag
 
    SystemCoreClockUpdate(); //update core clock freq
    RCC_GetSYSCLKSource(); // Get the system clock source
 
    RCC_GetClocksFreq(&pointer); // Get all the Clock frequencies
}

Can anybody help me to get out of this?

Thanks in advance...!

9 REPLIES 9
TDK
Guru

> RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_CFGR_PLLMUL11); // Config PLL params

8 MHZ / 2 * 4 * 11 = 44 MHz.

You want:

> RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_CFGR_PLLMUL12); // Config PLL params

8 MHZ / 2 * 4 * 12 = 48 MHz.

> code gets stuck

You also need 1 wait state. I don't see you doing that anywhere.

If you feel a post has answered your question, please click "Accept as Solution".

Look to be doing things out of order

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

Hi @Mgawa.1​ ,

You can use STM32CubeMx software which is freely downloadable from ST official website.

Here is the code generated by CubeMX:

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 
  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
  RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
  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_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  {
    Error_Handler();
  }
}

Best Regards,

Ons.

Thanks for the reply!!

Can you please tell, which wait state I need?

Thanks for the reply ..!

Can you please suggest the correct order?

Thanks for the reply.. !

As my project is already ready according to the application so I cant do it in CubeMx. Can you please tell me just here how can I resolve my issue without using CubeMx?

Hi @Mgawa.1​ ,

I meant you can use Mx for generating the Clock config only, and replace the generated code by Mx in your project.

This is how I did it:

  • I created a new project with STM32F091RBTx
  • I go to clock configuration tab and configured the clock as you suggested: HCLK = 48 MHz, SYSCLK source is PLL, and PLL source is HSI.

0693W00000AQ9K2QAL.png

  • Finally I generate the project and copy the generated SystemClock_Config() function into my project.

This is really a simple and clean way to have a "correct" clock config that fits your preferences.

Best Regards,

Ons.

I tried with the above configuration but still it's not working, After using your configuration methodology. garbage data is printing on UART. Not able to understand the reason.

Hi @Mgawa.1​ ,

Please verify that the UART configuration used in your code is the same as the one set on your terminal.

Best Regards,

Ons.