Skip to main content
AA.81
Associate
February 28, 2019
Question

STM32L151CBT6A can't go to sleep when slowing down the system clocks

  • February 28, 2019
  • 2 replies
  • 749 views

hello!

Recently, I found such a problem: when the MCU works at 32MHz by default, it can enter the low power mode normally. However, in order to reduce the power consumption during operation, when I reduce the system frequency below 4MHz, the MCU can't enter the low power mode. However, when the system is running above 6MHz, it can enter the low power mode normally. Has anyone tried to sleep normally below 4MHz?

In addition, the MCU is powered by 2.5V.

This topic has been closed for replies.

2 replies

Mohamed Aymen HZAMI
ST Employee
March 5, 2019

Hello,

  1. What is the clock source that you use ?
  2. How do you switch to the low frequency ?

Best Regards,

Mohamed Aymen.

AA.81
AA.81Author
Associate
June 19, 2019

Hi

@Mohamed Aymen HZAMI​ 

1.I tried HSI�?MSI�?PLL clock source,but they still have the same result.

2.Below is the code that set the system clock to 2MHz.

void SystemClockConfig(void)
{
 RCC_OscInitTypeDef RCC_OscInitStruct;
 RCC_ClkInitTypeDef RCC_ClkInitStruct;
 RCC_PeriphCLKInitTypeDef PeriphClkInit;
 
 __HAL_RCC_PWR_CLK_ENABLE();
 
 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
 
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE;
 RCC_OscInitStruct.LSEState = RCC_LSE_ON;
 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.PLLMUL = RCC_PLL_MUL3;
 RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 assert_param(FAIL);
 }
 
 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_DIV8;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
 {
 assert_param(FAIL);
 }
 
 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
 PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
 {
 assert_param(FAIL);
 }
 
 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
 
 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
 
 // SysTick_IRQn interrupt configuration
 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

3.Below is the code for the MCU to enter and exit stop mode.

void enterStopMode(void)
{
 CRITICAL_SECTION_BEGIN();
 
 BoardDeInitMcu();
 
 // Disable the Power Voltage Detector
 HAL_PWR_DisablePVD();
 
 // Clear wake up flag
 SET_BIT(PWR->CR, PWR_CR_CWUF);
 
 // Enable Ultra low power mode
 HAL_PWREx_EnableUltraLowPower();
 
 // Enable the fast wake up from Ultra low power mode
 HAL_PWREx_EnableFastWakeUp();
 
 CRITICAL_SECTION_END();
 
 // Enter Stop Mode
 HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
}
 
void exitStopMode(void)
{
 // Disable IRQ while the MCU is not running on HSI
 CRITICAL_SECTION_BEGIN();
 
 // Initilizes the peripherals
 BoardInitMcu();
 
 CRITICAL_SECTION_END();
}