STM32L0 standby mode and wakeup pin

Thread Starter

killerfish

Joined Feb 27, 2009
29
Hi guys,

I'm new to embedded works. I am using STM32L0C8 MCU and STM32cubemx to generate hal driver for my first project. One of the feature of the project, is I'm trying to configure it to go into standby mode to conserve lowest power consumption if my program has been idling for some amount of time, then use WKUP pin(PA0) which is wired to a button to trigger a rising edge to wake the MCU. The problem here is I couldn't get it neither the standby mode and wakeup pin to work. I have been working this problem 7 days straight and gone through all the technical manual and couldn't find where am I did wrong, really..... it getting my nerve.

Very appreciate if you can shed some light where am I doing wrong.

MCU pin configuration


Clock configuration


Wakeup pin configuration


Clock config program


The code to put the device in standby mode is standard.


CSR, CR and SCR Flags
 

MrChips

Joined Oct 2, 2009
34,727
What is the part number of the MCU?

Have you looked at the device Reference Manual and any application notes and programming examples?

Stating simply that it doesn't work does not give us much to work on.
What does it do? What does it not do?
What is your IDE platform? Can you run debug?
Can you flash an LED?

You will have to post your entire code.
 

Thread Starter

killerfish

Joined Feb 27, 2009
29
What is the part number of the MCU?

Have you looked at the device Reference Manual and any application notes and programming examples?

Stating simply that it doesn't work does not give us much to work on.
What does it do? What does it not do?
What is your IDE platform? Can you run debug?
Can you flash an LED

You will have to post your entire code.
My apology MrChips for not providing a clean details. The part number of MCU is STM32L0C8T6. I am using Keil uVision for my IDE platform, and I did not use LED because I did not init the GPIO in programming. I suppose the wakeup pin doesn't require GPIO init according to my MCU pin configuration.

I removed the rest of the codes except the standby codes in the main for testing yesterday. I managed to observe the standby function work but only by pressing and holding the push button down, the current measurement at the source dropped from about 3.5mA to 0.5mA. But that wasn't the correct execution I wanted, the push button use is to wake the device. After the device went into standby mode, I pushed the button again, the wakeup pin still do not work.

Push button schematic



My codes:

Code:
int main(void)
{

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

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

    HAL_Delay(10000);


    HAL_PWREx_EnableUltraLowPower();
    /* Enable the fast wake up from Ultra low power mode */
    HAL_PWREx_EnableFastWakeUp();
        
    if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
    {
    /* Clear Standby flag */
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
            }
    
    /* Insert 5 seconds delay */
    HAL_Delay(5000);
    
    /*Disable all used wakeup sources: Pin1(PA.0)*/
    HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
    
    /*Clear all related wakeup flags*/
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
    
    /*Re-enable all used wakeup sources: Pin1(PA.0)*/
    HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
    HAL_PWR_EnterSTANDBYMode();
    
    while(1)
    {}

}

HAL_StatusTypeDef HAL_Init(void)
{
  /* Configure Buffer cache, Flash prefetch,  Flash preread */
#if (BUFFER_CACHE_DISABLE != 0)
  __HAL_FLASH_BUFFER_CACHE_DISABLE();
#endif /* BUFFER_CACHE_DISABLE */

#if (PREREAD_ENABLE != 0)
  __HAL_FLASH_PREREAD_BUFFER_ENABLE();
#endif /* PREREAD_ENABLE */

#if (PREFETCH_ENABLE != 0)
  __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
#endif /* PREFETCH_ENABLE */

  /* Use systick as time base source and configure 1ms tick (default clock after Reset is MSI) */

  HAL_InitTick(TICK_INT_PRIORITY);

  /* Init the low level hardware */
  HAL_MspInit();

  /* Return function status */
  return HAL_OK;
}

void SystemClock_Config(void)
{

  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_OscInitTypeDef RCC_OscInitStruct;

  __PWR_CLK_ENABLE();

  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI
                              |RCC_OSCILLATORTYPE_HSI48;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 16;
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV16;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
}

void HAL_PWREx_EnableUltraLowPower(void)
{
  /* Enable the Ultra Low Power mode */
  PWR->CR |= PWR_CR_ULP;
}

void HAL_PWREx_EnableFastWakeUp(void)
{
  /* Enable the fast wake up */
  PWR->CR |= PWR_CR_FWU;
}

void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
{
  /* Check the parameter */
  assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
  /* Disable the EWUPx pin */
  PWR->CSR &= ~WakeUpPinx;
}

void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx)
{
  /* Check the parameter */
  assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
  /* Enable the EWUPx pin */
  PWR->CSR |= WakeUpPinx;
}

void HAL_PWR_EnterSTANDBYMode(void)
{
  /* Select Standby mode */
  PWR->CR |= PWR_CR_PDDS;

  /* Set SLEEPDEEP bit of Cortex System Control Register */
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;

  /* This option is used to ensure that store operations are completed */
#if defined ( __CC_ARM)
  __force_stores();
#endif
  /* Request Wait For Interrupt */
  __WFI();
}
 
Last edited:

MrChips

Joined Oct 2, 2009
34,727
All GPIO pins need initialization.
Look at the HAL_Init( ) source code and see if SYS_WKUP1 (PA0) is configured correctly.
 
Top