cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407VET PLL problem

kareemkna
Associate II
Posted on July 07, 2015 at 17:00

I used STM32 cube for the PLL configuration

// Enable HSE Oscillator and activate PLL with HSE as source
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
// This assumes the HSE_VALUE is a multiple of 1MHz. If this is not
// your case, you have to recompute these PLL constants.
RCC_OscInitStruct.PLL.PLLM = (HSE_VALUE/1000000u);
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
// Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
// clocks dividers
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
And used this function to get the system clock
Sys_Freq=HAL_RCC_GetSysClockFreq();
Sys_Freq after calling this function = 168, so the initialization is correct

used this function to rout system clock on MCO1,,, the GPIO also made with STM32Cube
HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_PLLCLK, RCC_MCODIV_2);

the logic analyser shows only 9 Mhz on MCO1 where it should be 84Mhz.. So my Question is, WHAT I AM MISSING ??????

I would very much appreciate any help or suggestion, its been 3 days and didnt have any luck solving this problem :(

11 REPLIES 11
Posted on July 07, 2015 at 17:22

What is HSE_VALUE defined at, and what's the crystal on the board? What board are you using? The math is predicated on HSE_VALUE, it has no outside reference to compare or measure against.

Is the crystal starting properly? Can you probe it directly, or via MCO?

Is your scope/probe rated for 84 MHz? Use a 10x probe (in 10x mode) and consider increasing the MCO divider to cross check.

Does the PLL start? What are the PLL_x parameters programmed into it?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on July 07, 2015 at 17:51

The clock machine is relatively simple and straightforward to be debugged by direct writing to registers in the debugger, without writing a single line of code. There are only three registers concerned - RCC_CFGR, RCC_CR and RCC_PLLCFGR - plus you need to enable GPIO in RCC_AHB1ENR and set the respective GPIOx_MODER bits for the MCO pins to AF (i.e. set the respective MODERy[1:0] couple of bits to 0b10 = 2).

With the LA/scope connected to MCO1, run the debugger, halt and reset the processor in it, then try first set up MCO1 as outlined above and it should output HSI's 16MHz as that's where the default for MCO1 is set. Then set it to output HSE and enable HSE - this checks whether the crystal is willing to oscillate. Then set it to output PLL and start PLL. Finally, if you can connect to MCO2, set MCO2 to output the system clock, and try to switch it to PLL (and for extra fun, to HSE).

Try it, it's fun.

JW

kareemkna
Associate II
Posted on July 07, 2015 at 18:09

Ok I checked the crystal, its not generating clock, so i switched to HSI and routed now to MCO, I should measure 16MHz, Right ?? but the scope is showing  9 MHz o.O 

I am using STM32F407VET in a board assembled in my company as a part of a product

 

and thanks for your quick reply 

kareemkna
Associate II
Posted on July 07, 2015 at 18:12

MCO2 is not an option ......

Posted on July 07, 2015 at 18:14

If the HSE is failing to start, the chip is using the HSI as a source, and yes it should be 16 MHz

Make sure

RCC_OscInitStruct.PLL.PLLM = 16; // If HSI is the source

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on July 07, 2015 at 18:23

You still can do most of what I wrote, on MCO1.

Btw., isn't there some external signal source or load on MCO1, fighting with the STM32's output?

Btw.2, don't you have a divider set for MCO1?

JW

kareemkna
Associate II
Posted on July 07, 2015 at 18:28

Nothing is working, I am going crazy,, Now the MCO1 shows 6 MHz if PLL is source, and 9 Mhz if HSI is source,, 

Posted on July 07, 2015 at 18:31

Get an 100 MHz oscilloscope with probes you trust....

Start by gating HSI to MCO/DIV1 and confirm that

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kareemkna
Associate II
Posted on July 07, 2015 at 18:33

MCO1 is connected to nothing a Test Point in air

MCO1 divider Set to 2 , i measure the half, 4 Mhz. when 1 i mesaure 8 to 9 Mhz