Problem in setting the system clock of STM32F446RE (on a Nucleo - F446RE board) to 180 MHz using the Phase Locked Loop(PLL)
The maximum allowed internal clock for the device STM32F446RE is 180 MHz. The nucleo board has an external crystal of 8 MHz. Using this and a code I obtained from a university website, I attempted to change the system clock to 180 MHz using the PLL.
(I use MikroC PRO for ARM v4.7.1)
Here is the code.
void InitializeClock()
{RCC_CFGR = 0x00000000; //Reset Clock Configuration Register
RCC_CR &= 0xFEF6FFFF; //Reset HSEON, CSSON and PLLON Bits
RCC_CR |= (1 << 16); //Turn on HSE clock
while((RCC_CR & (1 << 17)) == 0)
{
GPIOA_BASE.B5 = ~GPIOA_BASE.B5; // Toggle PIN A5 which is the LED(LD2) so as to know if the execution is still in the loop
Delay_ms(500);
} //Wait until High Speed External(HSE) Oscillator(8 MHz) is ready
RCC_CR |= (1 << 19);
RCC_PLLCFGR = 0x27405A08; //Set PLLP = 0, PLLN = 360, PLLM = 8,
//PLLQ = 7, PLL Src = HSE
RCC_CR |= (1 << 24); //Enable PLL on
while((RCC_CR & (1 << 25)) == 0)
{
GPIOA_BASE.B5 = ~GPIOA_BASE.B5; // Toggle PIN A5 which is the LED(LD2) so as to know if
the execution is still in the loop
Delay_ms(1000);
} //Wait for PLL to lock on
RCC_CFGR = 0x9402; // APB2/2, APB1/4, AHB/1
FLASH_ACR &= 0xFFFFFFF8; //Set flash wait states to 5
FLASH_ACR |= 0x5;
}
void InitMain()
{
SPI1_Init_Advanced(_SPI_FPCLK_DIV64, _SPI_MASTER | _SPI_8_BIT | _SPI_CLK_IDLE_LOW | _SPI_FIRST_CLK_EDGE_TRANSITION | _SPI_MSB_FIRST | _SPI_SS_DISABLE | _SPI_SSM_ENABLE | _SPI_SSI_1, &_GPIO_MODULE_SPI1_PB345);
}
void main()
{
unsigned int buffer=10;
Delay_us(100);
GPIO_Digital_Output(&GPIOA_BASE, _GPIO_PINMASK_5);
InitializeClock();
Delay_ms(1000);
InitMain();
Delay_us(10);
while (1)
{ // Endless loop
SPI_Write(buffer);
Delay_ms(200);
}
}On debugging, I found that the execution gets stuck in the first while loop of the InitializeClock() function which means that the HSE has not become stable. I waited for 60 seconds but the execution doesnot come out of that loop suggesting that the HSE clock is not stable. All the connections and the crystal are in place perfectly. What could be the problem? I would really be grateful if someone could help me out.
