cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX not generating PLL2 code for USB

mangobay11
Associate II

Hi,

I am using STM32F105RC. CubeMX does not seem to configure PLL2 at all in SystemClock_Config(). Below in the clock configurator it is clear that I have enabled PLL2 to be used for PLLCLK and USB clock.

Seems like a CubeMX bug. Or if someone can point me to what I am doing wrong that would be appreciated.

 

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV5;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.Prediv1Source = RCC_PREDIV1_SOURCE_PLL2;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
  RCC_OscInitStruct.PLL2.PLL2State = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  {
    Error_Handler();
  }
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
  PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV2;
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  {
    Error_Handler();
  }

  /** Configure the Systick interrupt time
  */
  __HAL_RCC_PLLI2S_ENABLE();
}


Screenshot from 2024-09-05 13-46-52.png

5 REPLIES 5
SofLit
ST Employee

But here you're setting the system clock config to HSE not to PLL. Or I didn't understand your question?

Screenshot from 2024-09-05 13-46-52.png

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.

Thanks for the reply!

The PLL is used for USB clock, and I have the USB OTG peripheral enabled. Is it not expected for CubeMX to generate clock configuration code for USB? Or does that clock configuration code live elsewhere?

Normally this is the USB clock config:

  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
  PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV2;
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  {
    Error_Handler();
  }

Do you expect something else?

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.

The code snippet you posted seems fine to me, and you will find that exact same code snippet in my original post.

However, the problem is that code to configure and enable PLL2 is not being generated. (see line 18 in my code snippet). USB clock uses PLL and PLL uses PLL2, as my clock configurator screenshot shows, so PLL2 must be enabled and configured for USB clock to work.

Ok I see. You should have mentioned line 18 from the beginning.

Need to check internally and get back to you.

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.