1. 程式人生 > >STM32L152的低功耗測試

STM32L152的低功耗測試

本文將驗證STM32L32在stop模式下的低功耗電流。

在ST官網的STM32L152RE晶片介紹上明確有說明此晶片在stop模式下可以達到560nA,納安!並且還可以支援16個外部中斷喚醒。

真的這麼強!下面來驗證一下。

採用NUCLEO-L152板子進行驗證,使用CubeMx生成工程程式碼。

在CubeMx中選擇STM32L152RE這款晶片,pinout如下設定:

如上圖,只是簡單地將PC13,PB9,PB5,PB4,PD2,PA12,PB15,PB1設定為外部中斷。

為了得到最低功耗,時鐘樹採用晶片內部時鐘HSI:

在configuration下,將GPIO都設定為下拉,PC13在NUCLEO板子上是按鍵,設為上拉。

生成程式碼。main函式稍作修改:

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_GPIO_Init();

  /* USER CODE BEGIN 2 */
  HAL_PWREx_EnableUltraLowPower();
  HAL_PWREx_EnableFastWakeUp();
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
	HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);

    /* Configures system clock after wake-up from STOP: enable HSI, PLL and select
      PLL as system clock source (HSI and PLL are disabled automatically in STOP mode) */
    SystemClockConfig_STOP();
    HAL_Delay(200);
  }
  /* USER CODE END 3 */

}

SystemClockConfig_STOP函式如下配置:

static void SystemClockConfig_STOP(void)
{
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};

  /* Enable Power Control clock */
  __HAL_RCC_PWR_CLK_ENABLE();

  /* The voltage scaling allows optimizing the power consumption when the device is
     clocked below the maximum system frequency, to update the voltage scaling value
     regarding system frequency refer to product datasheet.  */
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  /* Poll VOSF bit of in PWR_CSR. Wait until it is reset to 0 */
  while (__HAL_PWR_GET_FLAG(PWR_FLAG_VOS) != RESET) {};

  /* Get the Oscillators configuration according to the internal RCC registers */
  HAL_RCC_GetOscConfig(&RCC_OscInitStruct);

  /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */
  RCC_OscInitStruct.OscillatorType      = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSEState            = RCC_HSE_OFF;
  RCC_OscInitStruct.HSIState            = RCC_HSI_ON;
  RCC_OscInitStruct.PLL.PLLState        = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource       = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLMUL          = RCC_PLL_MUL6;
  RCC_OscInitStruct.PLL.PLLDIV          = RCC_PLL_DIV3;
  if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
     clocks dividers */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  {
    Error_Handler();
  }
}

編譯燒錄後使用電流表進行測試:

0.3uA! 看來所言非虛,300nA,按下按鍵,發現電流變大了,如下:

電流變為11mA,這個位為工作電流,這說明外部中斷生效了。

STM32L152在低功耗這塊,確實還不錯!實測stop模式下300nA的電流,比手冊上所示的560nA還低,看來ST還是比較保守。