cancel
Showing results for 
Search instead for 
Did you mean: 

Stop mode is woken by another EXTI line

markH
Associate II

STM32L071CBT wakeup power button PC13, PWM signal = PA11

I have a device that wakes every 20 seconds then goes to sleep, it can also wake when the power button is pressed, part of it's wake cycle it to check the servoInt pin for activity.

pin setup

/*Configure GPIO pin : servoInt_Pin */
  GPIO_InitStruct.Pin = servoInt_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(servoInt_GPIO_Port, &GPIO_InitStruct);
 
/*Configure GPIO pin : powerButton_Pin */
  GPIO_InitStruct.Pin = powerButton_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(powerButton_GPIO_Port, &GPIO_InitStruct);

stop mode is called

if(HAL_RTC_SetAlarm_IT(&hrtc, &RTC_AlarmStructure, RTC_FORMAT_BIN) != HAL_OK)
{
ErrorHandler(ERR_RTC_ALARM);
}
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);

IRQHandler

void EXTI4_15_IRQHandler(void)
{
if(__HAL_GPIO_EXTI_GET_FLAG(servoInt_Pin) != RESET)
{ 
	HAL_GPIO_EXTI_IRQHandler(servoInt_Pin);
}
else if(__HAL_GPIO_EXTI_GET_FLAG(powerButton_Pin) != RESET)
{ 
	HAL_GPIO_EXTI_IRQHandler(powerButton_Pin);
}

callback handler

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
	switch (GPIO_Pin)
	{
		case servoInt_Pin:
		servoFlag = true;
		break;
		
		case powerButton_Pin:
		powerTick = HAL_GetTick();
		break;
	}
}

the IRQ handler decerns the two exti lines and calls the callback correctly but the device wake on WFI from the servoInt_pin as well as the powerButton pin.

Is there a way to make WFI not be triggered from exti11?

1 ACCEPTED SOLUTION

Accepted Solutions

Disable the EXTI11 interrupt before entering STOP mode, reenable upon exiting it in any way.

JW

View solution in original post

4 REPLIES 4

Disable the EXTI11 interrupt before entering STOP mode, reenable upon exiting it in any way.

JW

Sarra.S
ST Employee

Hello @markH​ 

As Jan already said,

Add a line to disable the servoInt_Pin EXTI interrupt before entering stop mode:

HAL_NVIC_DisableIRQ(EXTI11_IRQn); // Disable EXTI11_IRQn to prevent waking up from servoInt_Pin 
 
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);

and then, add a line to re-enable the it after waking up from stop mode:

HAL_NVIC_EnableIRQ(EXTI11_IRQn); // Re-enable EXTI11_IRQn 

after waking up from stop mode

With these changes, the device should only wake up when the power button is pressed while in stop mode.

You can also check this wiki article that provides steps and code for all the low power modes.

Hope that helps!

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

markH
Associate II

Thank you, waclawek.jan answer worked, I sort of realised on my way home after I posted the question. Sometimes you have to step back to allow yourself to think!