cancel
Showing results for 
Search instead for 
Did you mean: 

problem about LSE clock of stm32l431

cai.bai
Associate II
Posted on March 15, 2017 at 07:30

hi,I want use LPTIM1 and select clock source is LSE.

when i enable LSE use code auto-gen from stm32cubemx,but LSERDY can't assert,the external OSC is work normal.

init code like as:

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_LSE|RCC_OSCILLATORTYPE_MSI;

  RCC_OscInitStruct.LSEState = RCC_LSE_ON;

  RCC_OscInitStruct.MSIState = RCC_MSI_ON;

  RCC_OscInitStruct.MSICalibrationValue = 0;

  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

  {

    Error_Handler();

  }

    /**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_MSI;

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

  {

    Error_Handler();

  }

  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPTIM1;

  PeriphClkInit.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_LSE;

  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

  {

    Error_Handler();

  }

    /**Configure LSE Drive Capability

    */

  __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH);

    /**Configure the main internal regulator output voltage

    */

  if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)

  {

    Error_Handler();

  }

    /**Configure the Systick interrupt time

    */

  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

    /**Configure the Systick

    */

  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

    /**Enable MSI Auto calibration

    */

  HAL_RCCEx_EnableMSIPLLMode();

  /* SysTick_IRQn interrupt configuration */

  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

}

what's problem about it?

4 REPLIES 4
Khouloud GARSI
Lead II
Posted on March 15, 2017 at 11:11

Hi

cai.bai

‌,

Please replace the line below :

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;

with:

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;

This is a reported issue using CubeMX V4.20 and this will be corrected in the coming version.

Sorry for any inconvenience this may have caused.

Khouloud

Posted on March 16, 2017 at 02:46

i modify code as you talk,but it can't work.

      tickstart = HAL_GetTick();

      /* Wait till LSE is ready */

      while(READ_BIT(RCC->BDCR, RCC_BDCR_LSERDY) == RESET)

      {

        if((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)

        {

          return HAL_TIMEOUT;

        }

      }

LSERDY can't assert and then timeout

Posted on March 16, 2017 at 20:53

What hardware do you use?

Post the read out content of relevant RCC registers at the moment of timeout.

JW

kevin huang
Associate
Posted on July 08, 2017 at 08:34

I met the same issue, that LSE can't be ready.  any solution for this issue? I'm using L431, 32.768KHz, LSE.