cancel
Showing results for 
Search instead for 
Did you mean: 

Enabling PLL on stm32f7 cube version 1.16 goes into errorhandler

leonardo
Associate III

I made a simple cubemx project for a stm32f722 uC, just configure the clock and nothing more.

I enable PLL with HSI to get 200MHz of systemcoreclock. I debug the project running step by step. Inside the SystemClockConfig

  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

goes into Error_Handler. I continue execution step-by-step and finally SystemCoreClock get 192MHz. If I "reset the chip and restart debugging session" then SystemClockConfig is executed without problem and SystemCoreClock get 200MHz.

Is this a bug? is there a workaround?

6 REPLIES 6
TDK
Guru

> I debug the project running step by step. Inside the SystemClockConfig goes into Error_Handler

So what part of HAL_RCC_OscConfig fails? Custom board? Doubt anyone can help if you don't show your code.

If you feel a post has answered your question, please click "Accept as Solution".
leonardo
Associate III

Hi, it's a custom board, but as i use HSI + PLL I don't think that it is related to my board.

I attache an ioc file, as you can see it just config the clock and nothing else. If I use the PLL (with HSI or HSE) the generated code fail. If I don't use the PLL and just pass through the HSI clock, then generated code is working ok.

Code for HSI+PLL:

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 
  /** Configure the main internal regulator output voltage
  */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 200;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

Inside HAL_RCC_OscConfig it fails on line 683 (line 25 on the following code):

  /*-------------------------------- PLL Configuration -----------------------*/
  /* Check the parameters */
  assert_param(IS_RCC_PLL(RCC_OscInitStruct->PLL.PLLState));
  if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE)
  {
    /* Check if the PLL is used as system clock or not */
    if (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK)
    {
....
....
....
    else
    {
      /* Do not return HAL_ERROR if request repeats the current configuration */
      pll_config = RCC->PLLCFGR;
#if defined (RCC_PLLCFGR_PLLR)
      if (((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_OFF) ||
          (READ_BIT(pll_config, RCC_PLLCFGR_PLLSRC) != RCC_OscInitStruct->PLL.PLLSource) ||
          (READ_BIT(pll_config, RCC_PLLCFGR_PLLM) != RCC_OscInitStruct->PLL.PLLM) ||
          (READ_BIT(pll_config, RCC_PLLCFGR_PLLN) != (RCC_OscInitStruct->PLL.PLLN << RCC_PLLCFGR_PLLN_Pos)) ||
          (READ_BIT(pll_config, RCC_PLLCFGR_PLLP) != ((((RCC_OscInitStruct->PLL.PLLP) >> 1U) - 1U) << RCC_PLLCFGR_PLLP_Pos)) ||
          (READ_BIT(pll_config, RCC_PLLCFGR_PLLQ) != (RCC_OscInitStruct->PLL.PLLQ << RCC_PLLCFGR_PLLQ_Pos)) ||
          (READ_BIT(pll_config, RCC_PLLCFGR_PLLR) != (RCC_OscInitStruct->PLL.PLLR << RCC_PLLCFGR_PLLR_Pos)))
#else
      if (((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_OFF) ||
          (READ_BIT(pll_config, RCC_PLLCFGR_PLLSRC) != RCC_OscInitStruct->PLL.PLLSource) ||
          (READ_BIT(pll_config, RCC_PLLCFGR_PLLM) != RCC_OscInitStruct->PLL.PLLM) ||
          (READ_BIT(pll_config, RCC_PLLCFGR_PLLN) != (RCC_OscInitStruct->PLL.PLLN << RCC_PLLCFGR_PLLN_Pos)) ||
          (READ_BIT(pll_config, RCC_PLLCFGR_PLLP) != ((((RCC_OscInitStruct->PLL.PLLP) >> 1U) - 1U) << RCC_PLLCFGR_PLLP_Pos)) ||
          (READ_BIT(pll_config, RCC_PLLCFGR_PLLQ) != (RCC_OscInitStruct->PLL.PLLQ << RCC_PLLCFGR_PLLQ_Pos)))
#endif
      {
        return HAL_ERROR;
      }

READ_BIT functions returns different values than expected, soy it returns HAL_ERROR

I think that the if statement on line 7 should be true, but, as it returns false, then the code executed is the else on line 12. Here the code checks for the configuration, but the code that make the configuration was never executed.

Thank

TDK
Guru

If __HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK, then you are currently using the PLL as the system clock source and can't change it. Maybe you have multiple calls to HAL_RCC_OscConfig. Attach your main.c code.

If you feel a post has answered your question, please click "Accept as Solution".
leonardo
Associate III

it's a cubemx generated file, I didn't change anything.

thank

leonardo
Associate III

BTW, this problem is not present on cubeF7 v1.12

The problem on v1.16 is that RCC->CFGR is equal to 37898 instead of 0 as soon as the main function is running. This produce that __HAL_RCC_GET_SYSCLK_SOURCE() will be 8 instead of 0.

I've notice some definition changes on stm32f722xx.h, some 0xXXXXXXXXU to 0xXXXXXXXUL. I'm not sure if this is a bug or not, but I can't make PLL to run at selected frequency on v1.16

Best regards

leonardo
Associate III

This issue is not present on f7 v1.15 so the workaround is tu use last cubemx 6 and generate code using CubeF7 v1.15