cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to set PLL as main clock derived from the HSI

glenn0010
Associate III

Hi All,

I am working with the STM32F302R8. I want to set the system clock as the PLL through derived from the HSI. I want a clock of 64MHz which I should have set through the appropriate registers.

I think I have set all I need however, after the RCC configration is done, the system clock switch status (SWS) in the RCC->CFGR register still indicates 0x00, initiating that the HSI is used as a clock directly.

I have a blinky at the end which currently the LED stays on while the code is running and never turns on when I am debugging.

#include "stm32f302x8.h"
int x =0;
 
void Delay (uint32_t nTime);
uint16_t ADC1ConvertedValue = 0;
uint16_t ADC1ConvertedVoltage = 0;
uint16_t calibration_value = 0;
volatile uint32_t TimingDelay = 0;
 
int init ()
	
{
	//RCC->CR = 0x1; //HSI on
	RCC->CFGR = 0x003C0002; //PLLSCr = HSI/2 , PLLMUL = x116 (62Mhz), PLL = sys clock
	RCC->CR |= 0x01000000; //PLL on
	RCC->AHBENR |= (1<<18); //Enabling AHB GPIOB
	//RCC->AHBENR |= (1<<28); //Enabling ADC Clocks
	// At this stage the microcontroller clock tree is already configured
//  RCC->CFGR2 &= 0x00000013; //ADC12 clock diveded by 6
 
	 
  GPIOB->MODER |= 0x00000010; // PB2 Output
	GPIOB->OSPEEDR |= 0x0; //Low speed output on all of port B
  GPIOB->PUPDR |= 0x30; // PB2 pull down
  GPIOB->MODER |=	0x0000000C; // GPIOB PB1 set to Analog Mode
  GPIOB->PUPDR |= 0x0000000B; // GPIOB PB1 set to Pull dowm
 
	return(0);
	
}
int main()
{
 
	init();
 
	while (1)
	{
 
	GPIOB->BSRR = (1<<2) ;
	for ( x = 0; x<500000; x++);
	GPIOB->BSRR = (1<<(2+16));
	for ( x = 0; x<500000; x++);
 
 
	}
	
}
 
 

1 ACCEPTED SOLUTION

Accepted Solutions

So I "fixed" it.

I set the data bits on the PC side to 7 bits and it works. However my STM is clearly set to 8 bits as shown below.

The datasheet clearly shows that bits 28 and 12, M1 and M0 respectively, set the word length. So when they are set to 00 the data bits are 8 bits.

0690X000008vtDNQAY.png

So I debugged the code and check it. Below it shows clearly that the register value indicates that both of them are 0. However as shown in the debugger view while the register value reflects this, there is only one "M" bit set and it is bit 12. Bit 28 is not show there at all. So basically in 7 bit mode it works flawlessly however in 8 bit mode it doesn't work at all despite the reference manual saying otherwise.

Can anyone shed some light on this?

0690X000008vtEVQAY.png

0690X000008vtEaQAI.png

View solution in original post

3 REPLIES 3

You have to stage the configuration, where you get the PLL running, wait for it to lock, and then select it as a source for the micro-controller, and wait for that to select. The flash wait states would also need to accommodate the faster clock, ie above 24 MHz, and need to be set before the clock switches.

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

HI Thanks so much for your help. I got it working thanks to you. Is there any way that I can confirm that the system clock is infact now 64Mhz? I can tell the frequency has changed cause the blink is faster but can I confirm the correct number?

Below is the code I used for setting it as you suggested.

	RCC->CR = 0x1; //HSI on
	while((RCC->CR & RCC_CR_HSIRDY) != RCC_CR_HSIRDY);
	RCC->CR &= ~RCC_CR_PLLON; //Disable PLL
	while((RCC->CR & RCC_CR_PLLRDY)== RCC_CR_PLLRDY); // wait for pll to turn off
	RCC->CFGR = RCC_CFGR_PLLSRC_HSI_DIV2 | RCC_CFGR_PLLMUL16 ; //PLLSCr = HSI/2 , PLLMUL = x6 (62Mhz),
	RCC->CR |= 0x01000000; //PLL on
	while((RCC->CR & RCC_CR_PLLRDY) != RCC_CR_PLLRDY); // wait for PLL to be ready
	RCC->CFGR = RCC_CFGR_SW_1; //PLL as system clock
	while((RCC->CFGR & RCC_CFGR_SWS_1) != RCC_CFGR_SWS_1); //wait fpr pll to be used as syste, clock

Thanks

So I "fixed" it.

I set the data bits on the PC side to 7 bits and it works. However my STM is clearly set to 8 bits as shown below.

The datasheet clearly shows that bits 28 and 12, M1 and M0 respectively, set the word length. So when they are set to 00 the data bits are 8 bits.

0690X000008vtDNQAY.png

So I debugged the code and check it. Below it shows clearly that the register value indicates that both of them are 0. However as shown in the debugger view while the register value reflects this, there is only one "M" bit set and it is bit 12. Bit 28 is not show there at all. So basically in 7 bit mode it works flawlessly however in 8 bit mode it doesn't work at all despite the reference manual saying otherwise.

Can anyone shed some light on this?

0690X000008vtEVQAY.png

0690X000008vtEaQAI.png