AnsweredAssumed Answered

Power usage issue with STM32L1 in Stop & Standby modes

Question asked by simal.david on Jul 22, 2015
I'm unable to get close to the advertised power consumption with STM32L152CBT6 and STM32L151C8T6 MCUs (Both are revison V)

The test board is the simpliest possible: MCU, decoupling caps of 0.1µF on each VSS/VDD + one 10µF on top, 0.1µF on VREF and another on NRST. BOOT0 connected to ground, all caps are high quality multi layer ceramic SMD. Circuit is powered by a 3.0V regulated source and tests are made with ambiant temperature of 25°C

Please find the code used below. I get exactly the same consumption in Stop or Standby mode : 14.4µA, and if I disable the LSI it goes down to 13.7µA with the STM32L152CBT6 (2 different boards same result), with the STM32L151C8T6 (1 board) it is 15.7µA or 15.0 µA with LSI disabled (this test board has 8Mhz & 32.768Khz crystals connected with proper caps, but HSE/LSE are not used)

I have spent days searching online, forums and example code and we just can't get it any lower than this. This is pretty critical as I need to get < 2 µA consumption in stop mode with RTC (which shouldn't be a problem according to the datasheet), or it's a show stopper for this MCU

Please find the test code below:

/**
 ******************************************************************************
 * File Name     : main.c
 * Date        : 07/05/2015 03:52:50
 * Description    : Main program body
 ******************************************************************************
 *
 * COPYRIGHT(c) 2015 STMicroelectronics
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *  1. Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *  3. Neither the name of STMicroelectronics nor the names of its contributors
 *   may be used to endorse or promote products derived from this software
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 ******************************************************************************
 */

/* Includes ------------------------------------------------------------------*/
#include "stm32l1xx_hal.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/
RTC_HandleTypeDef hrtc;

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_RTC_Init(void);

/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

int main(void)
{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

 /* MCU Configuration----------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();

 /* Configure the system clock */
 SystemClock_Config();

 /* Initialize all configured peripherals */
 //MX_RTC_Init();
        

__GPIOA_CLK_ENABLE();
__GPIOB_CLK_ENABLE();
__GPIOC_CLK_ENABLE();
__GPIOD_CLK_ENABLE();
__GPIOE_CLK_ENABLE();
__GPIOH_CLK_ENABLE();


GPIO_InitTypeDef GPIO_InitStructure;
 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
 GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
 GPIO_InitStructure.Pull = GPIO_NOPULL;
 GPIO_InitStructure.Pin = GPIO_PIN_All;

 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
 HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
 HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
 HAL_GPIO_Init(GPIOE, &GPIO_InitStructure);
 HAL_GPIO_Init(GPIOH, &GPIO_InitStructure); 

__GPIOA_CLK_DISABLE();
__GPIOB_CLK_DISABLE();
__GPIOC_CLK_DISABLE();
__GPIOD_CLK_DISABLE();
__GPIOE_CLK_DISABLE();
__GPIOH_CLK_DISABLE();


//HAL_RCC_DeInit();

HAL_PWREx_DisableFastWakeUp();
HAL_PWR_DisablePVD();
HAL_PWREx_EnableUltraLowPower();

RCC->AHBENR = 0;
 RCC->AHBLPENR = 0; // Disables all peripheral clocks during sleep
 RCC->APB1ENR = 0; //RCC_APB1ENR_PWREN;
 RCC->APB2ENR = 0; // Disables all periph clocks including adc, spi, usart, ...
 RCC->APB1LPENR = 0; //RCC_APB1ENR_PWREN;
 RCC->APB2LPENR = 0; // Disables all periph clocks including adc, spi, usart, ...
SysTick->CTRL=0;


// Disable flash prefetch buffer, enable flash powerdown, seems to have no effect on power consumption
FLASH->ACR &=(~FLASH_ACR_PRFTEN);
SET_BIT(FLASH->ACR, FLASH_ACR_SLEEP_PD);
FLASH->PDKEYR = FLASH_PDKEY1;  
 FLASH->PDKEYR = FLASH_PDKEY2;  
 SET_BIT(FLASH->ACR, FLASH_ACR_RUN_PD);


 /* Infinite loop */
 /* USER CODE BEGIN WHILE */


HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON,PWR_STOPENTRY_WFI);

// Exactly same power usage if I enter in STANDBY Mode instead
//HAL_PWR_EnterSTANDBYMode();

 while (1)
 {
 /* USER CODE END WHILE */



 /* USER CODE BEGIN 3 */

 }
 /* USER CODE END 3 */

}

/** System Clock Configuration
*/

void SystemClock_Config(void)
{

  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_PeriphCLKInitTypeDef PeriphClkInit;

  __PWR_CLK_ENABLE();

  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_MSI;
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  RCC_OscInitStruct.MSIState = RCC_MSI_ON;
  RCC_OscInitStruct.MSICalibrationValue = 0;
  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_5 ; // ~2Mhz
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);

  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);

  __SYSCFG_CLK_ENABLE();

 

}

/* RTC init function */
void MX_RTC_Init(void)
{

  RTC_TimeTypeDef sTime;
  RTC_DateTypeDef sDate;

    /**Initialize RTC and set the Time and Date
    */
  hrtc.Instance = RTC;
  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
  hrtc.Init.AsynchPrediv = 127;
  hrtc.Init.SynchPrediv = 255;
  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE; 
  HAL_RTC_Init(&hrtc);
 

  sTime.Hours = 0;
  sTime.Minutes = 0;
  sTime.Seconds = 0;
  sTime.TimeFormat = RTC_HOURFORMAT12_AM;
  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  sTime.StoreOperation = RTC_STOREOPERATION_RESET;
  HAL_RTC_SetTime(&hrtc, &sTime, FORMAT_BCD);

  sDate.WeekDay = RTC_WEEKDAY_MONDAY;
  sDate.Month = RTC_MONTH_JANUARY;
  sDate.Date = 1;
  sDate.Year = 0;
  HAL_RTC_SetDate(&hrtc, &sDate, FORMAT_BCD);

    /**Enable the WakeUp
    */
  //HAL_RTCEx_SetWakeUpTimer(&hrtc, 0x1FFF, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
 HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
}
 

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

#ifdef USE_FULL_ASSERT

/**
   * @brief Reports the name of the source file and the source line number
   * where the assert_param error has occurred.
   * @param file: pointer to the source file name
   * @param line: assert_param error line source number
   * @retval None
   */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */

}

#endif

/**
  * @}
  */

/**
  * @}
*/

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Outcomes