Skip to main content
motla
Associate II
January 8, 2019
Solved

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

  • January 8, 2019
  • 1 reply
  • 3773 views

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

This topic has been closed for replies.
Best answer by Khouloud GARSI

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 reply

Khouloud GARSI
Technical Moderator
January 9, 2019

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.

motla
motlaAuthor
Associate II
January 9, 2019

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

Khouloud GARSI
Technical Moderator
January 9, 2019

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.