cancel
Showing results for 
Search instead for 
Did you mean: 

no interrupts in low power (STM32L151)

Jesse Bax
Associate
Posted on January 18, 2018 at 09:50

Hello everyone,

I'm trying to make a device where the MCU (STM32L151) has to wake up periodically every 5 minutes and send a LoRa message. As such i want to put the device in a low power mode between messages. I read up on the datasheets and manuals on how to do this and decided to use the HAL. Now when i put the device to sleep it does not wake up anymore...

I would like to note that everything works perfectly when i use the 'normal' power mode (ie. not touching any power settings).

I want the device to wakeup from either:

  • RTC alarm interrupt
    • the RTC alarm is set to every 5 minutes. the pin interrupt is connected to a switch that protects our module from people opening the case. 
  • Interrupt on pin PC13 (interrupt wakeup pin)
    • with a signal going from either high to low or low to high (so rising AND falling edge)

In the code below you can see i use 

HAL_PWR_EnterSLEEPMode. while the mcu enters the low power mode, it does not exit on the pin or RTC interrupt. I have also tried HAL_PWR_EnterSTOPMode() and HAL_PWR_EnterStandbyMode(), but the result stays the same.

while (1) {

//if device is open when battery is just inserted the device has to wait till case is closed

if (caseprotector_get_state() >= closed_protected) {

/* run the LoRa class A state machine*/

lora_fsm();

   if (lora_getDeviceState() == DEVICE_STATE_SLEEP) {

      HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON,

      PWR_STOPENTRY_WFI);

}

}

Code for initializing the interrupt pin (PC13):

void MX_GPIO_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct;

/* GPIO Ports Clock Enable */

__HAL_RCC_GPIOC_CLK_ENABLE()

;

__HAL_RCC_GPIOA_CLK_ENABLE()

;

/*Configure GPIO pin Output Level */

/*Configure GPIO pin : PtPin */

GPIO_InitStruct.Pin = Security_Switch_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;

GPIO_InitStruct.Pull = GPIO_PULLDOWN;

HAL_GPIO_Init(Security_Switch_GPIO_Port, &GPIO_InitStruct);

/* EXTI interrupt init*/

HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);

HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);

}

Initializing the RTC:

/*!

* @brief Configures the RTC timer

* @note The timer is based on the RTC

* @param none

* @retval none

*/

static void HW_RTC_SetConfig( void )

{

RTC_TimeTypeDef RTC_TimeStruct;

RTC_DateTypeDef RTC_DateStruct;

RtcHandle.Instance = RTC;

RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;

RtcHandle.Init.AsynchPrediv = PREDIV_A; /* RTC_ASYNCH_PREDIV; */

RtcHandle.Init.SynchPrediv = PREDIV_S; /* RTC_SYNCH_PREDIV; */

RtcHandle.Init.OutPut = RTC_OUTPUT;

RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

HAL_RTC_Init( &RtcHandle );

/*Monday 1st January 2016*/

RTC_DateStruct.Year = 16;

RTC_DateStruct.Month = RTC_MONTH_JANUARY;

RTC_DateStruct.Date = 1;

RTC_DateStruct.WeekDay = RTC_WEEKDAY_MONDAY;

HAL_RTC_SetDate(&RtcHandle , &RTC_DateStruct, RTC_FORMAT_BIN);

/*at 0:0:0*/

RTC_TimeStruct.Hours = 0;

RTC_TimeStruct.Minutes = 0;

RTC_TimeStruct.Seconds = 0;

RTC_TimeStruct.TimeFormat = 0;

RTC_TimeStruct.SubSeconds = 0;

RTC_TimeStruct.StoreOperation = RTC_DAYLIGHTSAVING_NONE;

RTC_TimeStruct.DayLightSaving = RTC_STOREOPERATION_RESET;

HAL_RTC_SetTime(&RtcHandle , &RTC_TimeStruct, RTC_FORMAT_BIN);

/*Enable Direct Read of the calendar registers (not through Shadow) */

HAL_RTCEx_EnableBypassShadow(&RtcHandle);

}

Lastly i would like to add that i don't have a lot of experience with the ST MCU's. 

I hope someone can help me with this problem.

If you have further questions please ask them, i'll be happy to answer them!

Kind regards,

Jesse Bax,

Jr software developer

#rtc-wakeup #low-power-standby #stm32l1 #stm32-standby-wake-rtc
1 REPLY 1
Matthias Schranz
Associate II

Hey jesse

i'm working with STM32L072, so i'm not sure if it's exactly the same with your MCU.

i ha a lot of troubles getting the device to sleep, following code finally did the trick for me.

don't get irritated by the FreeRTOS stuff 😉 maybe this helps

cheers matt

/* Set RTC*/
     HAL_RTCEx_SetWakeUpTimer_IT(&hrtc,u16TimeToStop,RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
 
            /* suspend scheduler*/
        vTaskSuspendAll();
 
            /* disables irq, interrupts will still be able to wake up the system*/
        __disable_irq();
 
        __HAL_RCC_PWR_CLK_ENABLE();
        __HAL_RCC_WWDG_CLK_DISABLE();
        HAL_PWREx_EnableUltraLowPower();
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
        HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON,PWR_STOPENTRY_WFI);
 
            /* System sleeps here*/
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
            /* on wake up, restore system clock*/
        HAL_RCC_DeInit();
        SystemClock_Config();
         __HAL_RCC_WWDG_CLK_ENABLE();
 
            /* check interrupts now*/
        __enable_irq();
 
            /* stop RTC */
        HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
 
        RTC_LORAMAC = bTRUE;
 
            /*resume scheduler*/
        xTaskResumeAll();