cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 & CubeMX 4.25 clocksettings failure

taraben
Senior
Posted on April 26, 2018 at 19:04

Hello All,

I am using STM32L486RGT, CubeMX 4.25 STM32L4 lib 1.11.

At the STM32 I have a 16MHz crystall connected.

Now I run into problems setting up the clocktree. It works under certain combinations but not under the ones I want.

I want to use the 16MHz crystal, HSE, PLL, USB and CPU running at 64MHz.

not working: 16MHz Crystal, PLLSource:HSE, PLLM:1, PLLN:8, PLLR:2, Sysclock:64MHz, PLLSAI1N:12, PLLSAI1Q:4, USB:PLLSAI1Q:48MHz

working: switching the PLL source to HSI

I tried also with Nucleo Board STM32L452 and found the combination does initially does not work.

I put an 16MHz crystal to the board.

working: 16MHz Crystal, PLLSource:HSE, PLLM:1, PLLN:8, PLLR:2, Sysclock:64MHz

not working: as above, plus USB, PLLSAI1N:2, PLLSAI1Q:4, USB:PLLSAI1Q:48MHz

On all examples: AHBPrescalers are 1 so all peripheral/core/sysclock clocks are 64MHz

Here is the example SysClock Init from the generated not working sample:

the failing function is:

<<

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

>>

Can anyone confirm those problems?

Regards, Adib.

--

/**

  * @brief System Clock Configuration

  * @retval None

  */

void SystemClock_Config(void)

{

  RCC_OscInitTypeDef RCC_OscInitStruct;

  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  RCC_PeriphCLKInitTypeDef PeriphClkInit;

    /**Initializes the CPU, AHB and APB busses clocks

    */

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

  RCC_OscInitStruct.HSEState = RCC_HSE_ON;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

  RCC_OscInitStruct.PLL.PLLN = 8;

  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;

  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;

  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;

  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

  {

    _Error_Handler(__FILE__, __LINE__);

  }

    /**Initializes the CPU, AHB and APB busses clocks

    */

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

  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_3) != HAL_OK)

  {

    _Error_Handler(__FILE__, __LINE__);

  }

  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART3

                              |RCC_PERIPHCLK_LPUART1|RCC_PERIPHCLK_I2C1

                              |RCC_PERIPHCLK_USB|RCC_PERIPHCLK_ADC;

  PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;

  PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;

  PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;

  PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;

  PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;

  PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;

  PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSE;

  PeriphClkInit.PLLSAI1.PLLSAI1M = 1;

  PeriphClkInit.PLLSAI1.PLLSAI1N = 12;

  PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7;

  PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV4;

  PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV8;

  PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_48M2CLK;

  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

  {

    _Error_Handler(__FILE__, __LINE__);

  }

    /**Configure the main internal regulator output voltage

    */

  if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)

  {

    _Error_Handler(__FILE__, __LINE__);

  }

    /**Configure the Systick interrupt time

    */

  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

    /**Configure the Systick

    */

  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  /* SysTick_IRQn interrupt configuration */

  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

}
17 REPLIES 17
Szymon PANECKI
Senior III
Posted on April 26, 2018 at 19:11

Helloadib,

It could be that you faced CubeMX issue with code generation for clock domain.Could you please take a look on this thread:

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

? The issue described there is wrong PLLM parameter set by CubeMX.

Regards

Szymon

Posted on April 26, 2018 at 19:32

Hello Szymon,

indeed the PLLM was undefined :(

But even fixing this I run into timeout after setting the PLL parameter.

Any idea?

I have following values:

PLLSource 3

PLLM 1

PLLN 8

PLLP 7

PLLQ 2

PLLR 2

regards, Adib.

---

        /* Configure the main PLL clock source, multiplication and division factors. */

        __HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource,

                             RCC_OscInitStruct->PLL.PLLM,

                             RCC_OscInitStruct->PLL.PLLN,

                             RCC_OscInitStruct->PLL.PLLP,

                             RCC_OscInitStruct->PLL.PLLQ,

                             RCC_OscInitStruct->PLL.PLLR);

        /* Enable the main PLL. */

        __HAL_RCC_PLL_ENABLE();

        /* Enable PLL System Clock output. */

         __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL_SYSCLK);

        /* Get Start Tick*/

        tickstart = HAL_GetTick();

        /* Wait till PLL is ready */

        while(READ_BIT(RCC->CR, RCC_CR_PLLRDY) == RESET)

        {

          if((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE)

          {

            return HAL_TIMEOUT;

          }

        }
Posted on April 26, 2018 at 19:50

Hello Szymon,

I tried further and used the LL driver for RCC initialisation.

This works, but somehow the systick interrupt was shut off.

So all the HALDelay did not work ...

I will investigate tomorrow.

(I can't await the fix in CubeMX)

Regards, Adib.

--

Posted on April 26, 2018 at 19:57

added:

LL_SYSTICK_EnableIT();

before running to while(1) {

and then it works.

Maybe an other problem on RCC_LL initialisation.

regards, Adib.

--

taraben
Senior
Posted on May 29, 2018 at 13:31

Hello ST Team,

I tried the cubeMX 4.25.1 with no luck on this project.

Although the releasenotes claimes the clocksettings has been fixed for STM32L4.

Please investigate.

Adib.

--

Nawres GHARBI
ST Employee
Posted on May 29, 2018 at 15:02

Hi Adib could you please share your ioc and give me some more details about the board you are using please

Posted on May 29, 2018 at 13:39

Hello

Taraben.Adib

,

I will raise your issue internally for check.Can you please share your ioc file?

With Regards,

Imen.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on May 29, 2018 at 13:59

Hi Imen, please could you guide me how to append files. I don't see any attach button :-? Thanks, Adib.

Posted on May 29, 2018 at 14:07

ok , found that. Editing the original post allows to attach files; uhmm 'not so intuitive ..'.

I use the sam2_goware.ioc using the LL driver.

When switching to HAL for RCC module I am stuck in ClockConfiguration.

HTH, Adib.