2021-05-26 04:57 AM
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...!
2021-05-26 06:24 AM
> 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.
2021-05-26 06:29 AM
Look to be doing things out of order
2021-05-27 08:32 AM
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.
2021-05-27 10:40 AM
Thanks for the reply!!
Can you please tell, which wait state I need?
2021-05-27 10:41 AM
Thanks for the reply ..!
Can you please suggest the correct order?
2021-05-27 10:43 AM
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?
2021-05-28 01:44 AM
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:
This is really a simple and clean way to have a "correct" clock config that fits your preferences.
Best Regards,
Ons.
2021-05-28 01:13 PM
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.
2021-05-31 01:34 AM
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.