cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32Cube/MX] PLLI2S is not enabled when MCO2 is configured from it

motla
Associate II

Hi!

I use an STM32F746 and I configured STM32CubeMX clock tree as is :

0690X000006D09UQAS.png

I just use PLLI2S for the MCO2 output (for Ethernet purposes). I don't use SAI1, SAI2, I2S or SPDIF-RX, so the HAL_RCCEx_PeriphCLKConfig function does not initialize PLLI2S:

HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef  *PeriphClkInit)
{
...
  /*-------------------------------------- PLLI2S Configuration ---------------------------------*/
  /* PLLI2S is configured when a peripheral will use it as source clock : SAI1, SAI2, I2S or SPDIF-RX */
  if((plli2sused == 1) || (PeriphClkInit->PeriphClockSelection == RCC_PERIPHCLK_PLLI2S))
  {
   ... // THIS SECTION IS NOT CALLED: plli2sused == 0 and PeriphClkInit->PeriphClockSelection is not strictly equal to RCC_PERIPHCLK_PLLI2S, although it contains it as a binary mask
  }
...
}

The workaround is to initialize it manually after the SystemClock_Config() call :

  PLLI2SInit.PLLI2SN = 100;
  PLLI2SInit.PLLI2SP = RCC_PLLP_DIV2;
  PLLI2SInit.PLLI2SR = 2;
  PLLI2SInit.PLLI2SQ = 2;
  HAL_RCCEx_EnablePLLI2S(&PLLI2SInit);

EDIT: actually it's a bug inside the HAL_RCCEx_PeriphCLKConfig function of STM32Cube HAL library, it should be:

if((plli2sused == 1) || (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_PLLI2S) == RCC_PERIPHCLK_PLLI2S))

(By the way, MCO2 GPIO speed must be set manually to "Very high" inside STM32CubeMX settings)

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Hi Romain,

1- You're right! I'm able to reproduce your issue now.

At first, based on your description, I was on "case 1" -> Signal was correctly gotten on MCO2.

This is now internally highlighted and I will keep you posted about any further update.

Thanks for bringing this point to our attention.

2- However, I don't recommend to use the clock source output issued from the PLL on MCO2 pin for Ethernet.   

When the clock source output by the MCU on the MCO pin is issued from the PLL,  the MCO pin cannot be used to deliver a 50 MHz RMII clock input or a 25 MHz MII clock input to the Ethernet PHY compliant with the long term jitter maximum value for 1.4 ns specified in the IEEE802.3 standard.

As a workaround, you may :

* In MII mode: Use a 25 MHz external crystal to generate the HSE clock and output the clock signal on the MCO pin to clock the PHY

* In RMII mode: Either use an external 50 MHz oscillator to clock the PHY or select a PHY with an internal PLL that is able to generate the 50 MHz RMII clock. 

Khouloud.

View solution in original post

7 REPLIES 7
Khouloud GARSI
Lead II

Hi @motla​ ,

Just by setting the PC9's maximum output speed to "Very High" using STM32CubeMX, you should be able to have a correct PLLIS2R signal on MCO2.

The proposed update in "HAL_RCCEx_PeriphCLKConfig " function is not needed. 

If you're not able to see the correct signal on MCO2 using the "HAL_RCCEx_PeriphCLKConfig" function as it is, please further describe the seen behavior.

Khouloud.

Well no, AFAIK the code generated by STM32CubeMX does not initialize PLLI2S, even if the speed is set to "Very High" for the GPIO.

  GPIO_InitStruct.Pin = GPIO_PIN_9;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

↑ this does not initialize the PLL...

Thanks

Hi Romain,

  • Sure! The code that you're shown is only for configuring the pin PC9.
  • What I wanted to say in my previous comment is that I was not able to reproduce your issue: Using the "HAL_RCCEx_PeriphCLKConfig" function as it is, I'm able to have the PLLIS2R signal on MCO2; Just make sure to set the pin's speed to "Very High".
  • You may share your ioc file, that will help me to debug the behavior that you're encountering.

Khouloud.

Hello!

Just did some tests this morning, actually this is a bit complicated because of the "bug" I mentioned at the end of my original post. Here is the situation:

Case 1: when you only initialize PLLI2S it works, i.e.

PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_PLLI2S;

Case 2: when you initialize PLLI2S along some other PeriphClk including one of the followings [SAI1, SAI2, I2S or SPDIF-RX], it works again, i.e.

PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_PLLI2S|RCC_PERIPHCLK_SAI1;

(it works only because (plli2sused == 1) inside HAL_RCCEx_PeriphCLKConfig)

Case 3: when you initialize PLLI2S along some other PeriphClk NOT including one of the followings [SAI1, SAI2, I2S or SPDIF-RX], it doesn't work, i.e.

PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_PLLI2S|RCC_PERIPHCLK_I2C1;

Here is the .ioc file.

I can't help you more 😉

Thanks

Romain

Hi Romain,

1- You're right! I'm able to reproduce your issue now.

At first, based on your description, I was on "case 1" -> Signal was correctly gotten on MCO2.

This is now internally highlighted and I will keep you posted about any further update.

Thanks for bringing this point to our attention.

2- However, I don't recommend to use the clock source output issued from the PLL on MCO2 pin for Ethernet.   

When the clock source output by the MCU on the MCO pin is issued from the PLL,  the MCO pin cannot be used to deliver a 50 MHz RMII clock input or a 25 MHz MII clock input to the Ethernet PHY compliant with the long term jitter maximum value for 1.4 ns specified in the IEEE802.3 standard.

As a workaround, you may :

* In MII mode: Use a 25 MHz external crystal to generate the HSE clock and output the clock signal on the MCO pin to clock the PHY

* In RMII mode: Either use an external 50 MHz oscillator to clock the PHY or select a PHY with an internal PLL that is able to generate the 50 MHz RMII clock. 

Khouloud.

1- My bad, I've not even thought that PLLI2S could be alone in the initializer.

2- Thanks for pointing this to me... I was not aware of it. I'll change my design to use the PHY PLL then.

Have a nice day!

You're always welcome! If you have any question/feedback, please do not hesitate to post it in our STM32MCUs forum.

Have a nice day 😊

Khouloud.