cancel
Showing results for 
Search instead for 
Did you mean: 

Initializing External Interrupt pin as wake up option for stop mode

sanctified
Associate II

Hi,

I am using the stm32L100RBT6 and I have successfully implemented the stop mode.

I have chosen to wake up the µC from stop mode either by RTC or by an external interrupt.

Before I put the µC in stop mode, I set all the pins to analog to save power and then I initialize the pins I am using for wake up in interrupt mode.

The first time the µC goes into stop mode, there is no problem with the initialization of the interrupt pins.

The problem arises in the initialization of the interrupt pins after the µC wakes up from stop mode by RTC.

In doing the initialization of the interrupt pins again, the interrupt pin is somehow enabled and it wakes the µC from stop mode immediately after it goes into stop mode.

My question is, what am I doing wrong in either the initialization of the pin as an interrupt or in disabling the interrupt pin when the µC wakes up by RTC?

Or what is the proper procedure to follow to initialize a pin in interrupt mode which will be used to wake the µC from stop mode?

I hope I was clear enough =)

Below are my codes:

Interrupt pins inititalisation

void wakeup_pins_init(void){
  GPIO_InitTypeDef        GPIO_InitStruct;
  memset(&GPIO_InitStruct, 0, sizeof(GPIO_InitStruct));
  
  __HAL_RCC_GPIOB_CLK_ENABLE();  
  
  
  GPIO_InitStruct.Pin = DISPLAY_BUTTON_1_Pin|DISPLAY_BUTTON_2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  
  HAL_NVIC_SetPriority(EXTI0_IRQn, 1, 1);
  HAL_NVIC_EnableIRQ(EXTI0_IRQn);
  HAL_NVIC_SetPriority(EXTI1_IRQn, 1, 1);
  HAL_NVIC_EnableIRQ(EXTI1_IRQn);
  
    
    
}

stop mode enable function

void Stop_Mode_Enable(void){
  HAL_SPI_DeInit(&spi2);
  HAL_ADC_DeInit(&hadc);
  HAL_UART_DeInit(&hsuart1);
  HAL_I2C_DeInit(&i2c1);
  HAL_UART_DeInit(&huart3);
  
  Gpio_Pins_Disable();
  wakeup_pins_init();
  __HAL_RTC_WRITEPROTECTION_DISABLE(&my_rtc);
  
  __HAL_RTC_WAKEUPTIMER_DISABLE_IT(&my_rtc,RTC_IT_WUT);
  
  HAL_RTCEx_SetWakeUpTimer_IT(&my_rtc,10,RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
  
  
  __HAL_RTC_WAKEUPTIMER_ENABLE_IT(&my_rtc,RTC_IT_WUT);
  
  __HAL_RTC_WRITEPROTECTION_ENABLE(&my_rtc);
  
  HAL_NVIC_SetPriority(RTC_WKUP_IRQn,0,0);
  HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
  
  
  HAL_PWREx_EnableUltraLowPower();
  HAL_PWREx_DisableFastWakeUp();
  
  HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON,PWR_STOPENTRY_WFE);
  
  if( WakeUpSource == WAKE_UP_RTC){
    
    after_stop_mode_init();
  }
  
}

Set all pins as analog function

void Gpio_Pins_Disable(void){
  
  GPIO_InitTypeDef        GPIO_InitStruct;
  memset(&GPIO_InitStruct, 0, sizeof(GPIO_InitStruct));
  
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  
  GPIO_InitStruct.Pin = GPIO_PIN_All;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
  
  GPIO_InitStruct.Pin = GPIO_PIN_All & (~(GPIO_PIN_14 | GPIO_PIN_13));// leave debug pins active
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  
  
  __HAL_RCC_GPIOA_CLK_DISABLE();
  __HAL_RCC_GPIOB_CLK_DISABLE();
  __HAL_RCC_GPIOC_CLK_DISABLE();
  __HAL_RCC_GPIOD_CLK_DISABLE();
  __HAL_RCC_GPIOH_CLK_DISABLE();
}

4 REPLIES 4
MM..1
Chief III

You need IRQ handlers functions too and clear irq flags.

Your design is on battery? When not you dont need deinit init and other chaos, simply STOP and after irq continue. Only PLL need reinit after STOP and maybe special devs.

sanctified
Associate II

Thanks for ur reply.

I have IRQ handler functions and I clear the flags in these functions. The interrupt works fine in normal run mode. It only acts strangely after wake up from stop mode. The moment I am initializing the interrupt again as a wake-up source from stop mode, the interrupt is triggered as though I pressed the button. This is where my problem is.

yes my design is on battery.

I mean your problem is start and stop CLK for button ports. And as i write dont do this chaos, better is leave init all used ports in stop mode, because when you stop and change it to AN all your connected parts go to undefined state... Measure currents with and without and locate only special pins , that need be changed to ANALOG maybe.

Too i dont understand your lines before stop

  1. HAL_PWREx_EnableUltraLowPower();
  2. HAL_PWREx_DisableFastWakeUp();

im not expert for L100 , but for exmple in Migrating between STM32L0 Series and STM32L4 Series / STM32L4+ Series microcontrollers - Application note

Table 38 you can see for L4 this commands is NA.

Too you can try disable RTC part for debug buttons first. Maybe your next wakeups is from RTC not cleared flag ....

sanctified
Associate II

1.HAL_PWREx_EnableUltraLowPower(); ---- According to the datasheet, this function switches off the Vrefint, the BOR, PVD, and temperature sensor to further minimize the power consumption

2.HAL_PWREx_DisableFastWakeUp(); ---- This is to ignore a fast wake up time after stop mode. Basically, you enable this if one is making use of the analog peripherals in order to have a reliable internal voltage reference after stop mode.

Okay, I will try out your suggestions. Thank You