2019-12-03 04:00 AM
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.
Solved! Go to Solution.
2019-12-03 05:13 AM
I don't know what include files you have. I think the current standard to access e.g. the CR register of the RCC peripheral is to use
RCC->CR
not
RCC_CR
I think most people don't memorise the individual bits in e.g. RCC->CR. I don't know which bit is e.g. (1 << 16).
My include files define all the bits in the form (e.g.) RCC_CR_HSEON
How many flashes of LED2 do you see in the 60 seconds? Is the rate roughly 1 a second?
If you're stuck around lines 6 - 9 the you are waiting for RCC_CR_HSERDY.
Are you sure RCC_CR_HSEON is being set?
If so, that means the crystal is not oscillating. This could be a broken crystal or broken pcb tracks leading to it, or the capacitors associated with the crystal.
Note that the power in the crystal oscillator is very low, so you cannot hang a x1 or x10 oscilloscope probe on the crystal and expect things to work. (You might get away with a x100 probe).
Hope this helps,
Danish
2019-12-03 05:13 AM
I don't know what include files you have. I think the current standard to access e.g. the CR register of the RCC peripheral is to use
RCC->CR
not
RCC_CR
I think most people don't memorise the individual bits in e.g. RCC->CR. I don't know which bit is e.g. (1 << 16).
My include files define all the bits in the form (e.g.) RCC_CR_HSEON
How many flashes of LED2 do you see in the 60 seconds? Is the rate roughly 1 a second?
If you're stuck around lines 6 - 9 the you are waiting for RCC_CR_HSERDY.
Are you sure RCC_CR_HSEON is being set?
If so, that means the crystal is not oscillating. This could be a broken crystal or broken pcb tracks leading to it, or the capacitors associated with the crystal.
Note that the power in the crystal oscillator is very low, so you cannot hang a x1 or x10 oscilloscope probe on the crystal and expect things to work. (You might get away with a x100 probe).
Hope this helps,
Danish
2019-12-03 05:18 AM
But does it actually start?
The 8 MHz generated by the ST-LINK would likely want to use BYPASS mode. If you add components make sure you disconnect the MCO clock from the ST-LINK, and they have the right characteristics.
2019-12-03 06:04 AM
> The nucleo board has an external crystal of 8 MHz.
How external? Post foto (and read Danish's and Clive's Avogadro's post).
Danish,
> RCC->CR
> not
> RCC_CR
Our OP here probably uses some non-standard defines/headers ("obtained from university", "using microE stuff").
JW
PS. And change your username to a normal nick.
2019-12-13 05:37 AM
Thank you for replying.
I could observe that the 8 MHz crystal oscillates but it doesn't reach OSC_IN pin of MCU. Maybe because of broken PCB tracks as you mentioned. I'm not sure though.
So I decided to use the High Speed Internal(16 MHz) clock as the input for PLL instead of HSE. Now, the execution gets out of the first loop but is stuck in the second loop suggesting that the PLL output is not getting locked.
I also tried to configure the system clock using STM32CubeMX and MDK-ARM v5 (Keil) but in vain.
Why is that the PLL inside the MCU is not functioning properly?