cancel
Showing results for 
Search instead for 
Did you mean: 

Can't Get HSE to work with STM32L4-Discovery!

jp1
Associate III
Posted on October 26, 2015 at 08:00

Hi,

We are running the STM32CubeL4 demo firmware on the STM32L4-Discovery board.

We are trying to leverage the demo ''IddMeasurement'' module to assess power consumption with an external 8 MHz 3.3V square wave as HSE. The demo uses MSI as the clock source for Sysclock in all Idd measurement modes(Run, Sleep, LP Run, etc..).

We followed the reference manual and also used the RCC init code generated by CubeL4Mx.  Here's the code for one of the routines:

static void Idd_ExternalSupply_ClockDecrease(void)

{

  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  RCC_OscInitTypeDef RCC_OscInitStruct = {0};

//  /* System clock source set to MSI */

//  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK ;

//  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;

  

  /* JP - turn on HSE in bypass mode  */

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

  RCC_OscInitStruct.HSEState = RCC_HSE_ON;

  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;

  /* JP - switch SYSCLK to HSE in order to modify PLL divider */

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;

  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;

  /* end of JP mods to orginal code */

  if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)

  {

    /* Initialization Error */

    Error_Handler();

  }

   

  /* JP - Turn off PLL to make changes to PLL divider */

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_NONE;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_OFF;

  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

  RCC_OscInitStruct.PLL.PLLM = 2;

  RCC_OscInitStruct.PLL.PLLN = 18; /* PLL o/p = 72 MHz */

  RCC_OscInitStruct.PLL.PLLR = 3;  /* sysclock = 72/3 = 24 MHz */

  RCC_OscInitStruct.PLL.PLLP = 7;

  RCC_OscInitStruct.PLL.PLLQ = 4;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

    /* End of JP mods  */

  if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

  {

    /* Initialization Error */

    Error_Handler();

  }

  /* JP- Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 

     clocks dividers */

  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | 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_4) != HAL_OK)

  {

    /* Initialization Error */

    Error_Handler();

  }

  

//  /* Set MSI to range 9 (24 MHz) */

//  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;

//  RCC_OscInitStruct.MSIState = RCC_MSI_ON;

//  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_9; /* 24 MHz */

//  RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;

//  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

//  if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

//  {

//    /* Initialization Error */

//    Error_Handler();

//  }

  

  

  /* Move to Voltage Scale 2 */

  

  /* Enable Power Control clock */

  __HAL_RCC_PWR_CLK_ENABLE();

  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE2);

  /* Disable Power Control clock once PWR registers are updated */

   __HAL_RCC_PWR_CLK_DISABLE();

   

   

   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  

}

The above code flashes the welcome message across the glass LCD instead of displaying the IDD value in Sleep and LP modes.

Any guidance on any other code settings we may be missing will be much appreciated.

Thanks.

 

#hse-sysclock-idd-stm32l4-disco
2 REPLIES 2
Breukers.Ron
Associate II
Posted on November 04, 2015 at 12:44

In my board, the HSE crystal was not mounted. That may be the reason for your troubles.

RON

Posted on November 04, 2015 at 14:11

Normally on the DISCO boards it is presented as an 8 MHz from the ST-LINK's MCO pin.

Not sure this is right...

RCC_OscInitStruct.HSEState = RCC_HSE_ON;

RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;

You'd want to wade into the function enabling the clocks, and make sure it doesn't assert() or fail.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..