cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot Enable More Than 1 Output on PLL2/3

MDS
Associate III
Posted on April 24, 2018 at 16:33

I am using the STM32H743xx Nucleo board with CubeMX V4.25.0 and CubeH7 V1.2.0.

The HAL drivers have some issues with enabling the PLLs and individual PLL outputs (P, Q, R).

1. HAL_RCC_OscConfig() always enables all PLL1 outputs (P, Q, R) even if they are not used.

2. HAL_RCCEx_PeriphCLKConfig() has the problem with PLL2/3. Only the first output enabled gets enabled. PLL2/3 also have the problem when an output is mapped to MCO1/MCO2, the PLL and output will not be enabled unless a peripheral using that output is also enabled. If a peripheral uses a PLL1 output, it only works because HAL_RCC_OscConfig() has already enabled all the PLL1 outputs.

At least for PLL2/3, CubeMX attempts to save power by only enabling the PLL if an output is mapped to a peripheral, and only mapped outputs are enabled. Unused outputs are not enabled. Apparently PLL1 does not have these rules. I am only using PLL1P, but outputs Q & R are also always enabled by HAL_RCC_OscConfig().

At reset, HAL_RCC_OscConfig() runs first and always enables PLL1 and all of its outputs. The good news is that because all PLL1 outputs are enabled, peripherals that use PLL1 will work. Things are not so good for PLL2/3 peripherals. For PLL2/3, which are configured by HAL_RCCEx_PeriphCLKConfig(), only the first enabled output gets enabled, and this is only because the PLL is disabled at reset. The problem in HAL_RCCEx_PeriphCLKConfig() is that after the first PLL output is enabled, the PLL is enabled. The next peripheral that attempts to use a different PLL output first sets the output enable then calls the RCCEx_PLLx_Config(). Setting an output enable for a PLL clock cannot be done when the PLL is already enabled. The PLL must be disabled first, then outputs can be enabled. As a result of RCCEx_PLLx_Config() enabling the PLL, only one PLL clock output can be enabled on PLL2/3.

The functions mentioned above need to be restructured to determine all the used PLLs and outputs, then enable the PLL after the required outputs are enabled. Actually Cube MX knows this and could generate another '.init' parameter specifying the OR'ed mask of PLL outputs to enable per PLL. Also, the MCO1/MCO2, outputs need to be considered as peripherals when enabling PLL outputs. I am using PLL2P mapped to MCO2 to provide an external clock. To do so, CubeMX required me to enable a peripheral like LPTIM1 also mapped to PLL2P to be able to configure PLL2. I am implementing a simple fix so I can keep working.

Another CubeMX improvement would be to include the fractional multiplier value in the Clock Configuration tab calculations. As I am using the fractional multiplier on PLL1, all the system related clocks in the Clock Configuration tab are wrong, but the calculated SystemCoreClock in the code is correct. Maybe the clocks are  just being rounded/truncated in the Clock Configuration tab. It would be convenient if one could hover over a clock in the Clock Configuration tab and see the actual frequency and name used in the driver code. Currently if one hovers over a clock in the Clock Configuration tab, usually only the label to the right of the clock name is displayed, which is of no help.

This posting supersedes my posting named 'STM32H7 PLLFRACN Support' which I have marked as answered. This posting is more complete.

#stm32-pll-power-saving
7 REPLIES 7
Posted on April 24, 2018 at 17:44

The H7 is relatively new and complex, CubeMX is a lagging project trying to catch up, you'll always do better putting your coding pants on, deciphering the Reference Manual, and architecting the solution you want properly.

The PLL stuff in HAL is a horrible mess that could do with someone refactoring, currently a lot of cut and paste of code, using volatile variables repetitively that can't be optimized and cleaned up by the compiler.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Amel NASRI
ST Employee
Posted on April 26, 2018 at 15:52

Hi

Skelton.Merle

‌,

Your request will be deeply reviewed by our STM32CubeMX experts.

However, I have some comments:

  • difference between PLL1 and PLL2 can be illustrated on following sentences from RM0433:

0690X0000060AngQAE.png

  • From the pinout, if you select ''RCC_MCO_2'' on PC9, you will see that you can configure parameters for PLL2P. However you cannot link it to MCO2. Then, PLL2P isn't enabled in the code. This is one of the problems you want to highlight and I'll report to MX team.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on April 26, 2018 at 16:48

I have MCO2 mapped to PC9. When I connect MCO2 to PLL2P output, AND MCO2 is the ONLY user of PLL2P, HAL_RCCEx_PeriphCLKConfig() will not enable PLL2P as MCO2 is not in the

PeriphClkInitStruct.PeriphClockSelection list and no peripheral is using PLL2P.

I am suggesting that when an MCOx pin is connected to a PLLx output, the MCOx must be in the

PeriphClkInitStruct.PeriphClockSelection list and HAL_RCCEx_PeriphCLKConfig() must check for the MCOx as if it is a peripheral so it can enable the PLLx output.

I have also noticed that once CubeMX enabled a PLL, it will not disable it when there are no peripherals connected to it. So with CubeMX, once a PLL is enabled, it is forever enabled in CubeMX, although if no peripherals are connected, the CubeMX code does not enable the PLL outputs.

Yi Zhou
Associate III
Posted on July 03, 2018 at 17:42

Hi all:

     I have this problem too and this is the bug of cubemx. Cubemx does NOT open

RCC_PLLCFGR

 bit 19, according to RM0433 Page 377, '

Bit 19

DIVP2EN

: PLL2 DIVP divider output enable, 

This bit can be written only when the PLL2 is disabled

'.

     So just add the following code in the function main(), this bug is fixed.

/* USER CODE BEGIN SysInit */

///以下代�?由于cubemx32的BUG

///使能pll2_p_ck

///This bit can be written only when the PLL2 is disabled。�?�考RM0433编程手册P377

__HAL_RCC_PLL2_DISABLE();

__HAL_RCC_PLL2CLKOUT_ENABLE(RCC_PLL2_DIVP);

__HAL_RCC_PLL2_ENABLE();

/* USER CODE END SysInit */
MDS
Associate III
Posted on July 05, 2018 at 13:54

The CubeMX code for the PLL outputs has some problems. It examines which peripherals are enabled one at a time. When it finds a peripheral that uses a PLL output, it enables that output and the PLL. This works for the 1st output. When another output is needed, the code tries to set the enable bit, which does not work because the PLL is enabled and the enable register is locked. The CubeMX code is not disabling the PLL before enabling outputs, which is required. This is why CubeMX can only enable one output on any of the 3 PLLs. I had to do some significant rewrites to get my PLL outputs enabled. My fixes are not production quality, I just needed it to work for now.

Posted on July 05, 2018 at 15:34

Hello,

In order to use more than 1 output of PLL2/3 for STM32H7 peripherals, please refer to patch I provided in 

https://community.st.com/0D50X00009XkZJxSAN

 .

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Amel NASRI
ST Employee

Fix applied in RCC driver available in last STM32H7 package version (1.3.0)

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.