2015-07-07 08:00 AM
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 :(
2015-07-07 08:22 AM
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?2015-07-07 08:51 AM
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. JW2015-07-07 09:09 AM
2015-07-07 09:12 AM
MCO2 is not an option ......
2015-07-07 09:14 AM
If the HSE is failing to start, the chip is using the HSI as a source, and yes it should be 16 MHz
Make sureRCC_OscInitStruct.PLL.PLLM = 16; // If HSI is the sourceRCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;2015-07-07 09:23 AM
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? JW2015-07-07 09:28 AM
2015-07-07 09:31 AM
Get an 100 MHz oscilloscope with probes you trust....
Start by gating HSI to MCO/DIV1 and confirm that2015-07-07 09:33 AM
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