2
\$\begingroup\$

I am using an STM32L0 series MCU. I configured my MCU to wake up from Stop Mode using an EXTI line (EXTI0 at PORTA0) during falling edge. At the beginning, it wasn't going to the Stop Mode after I called _WFE(). After tried several things I called _WFE() twice, one after another and that did the trick. Although this solved my problem I was wondering if anyone can shed some light. Maybe I am missing something.

Here is my code:

void HW_WakeupPinInit(void)
{
   GPIO_InitTypeDef gpioInitStruct = {0};

   gpioInitStruct.Mode      = GPIO_MODE_INPUT;
   gpioInitStruct.Pull      = GPIO_PULLDOWN;
   gpioInitStruct.Speed = GPIO_SPEED_HIGH;

   HW_GPIO_Init( WAKEUP_PORT, WAKEUP_PIN, &gpioInitStruct );

   LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
   LL_SYSCFG_SetEXTISource(LL_SYSCFG_EXTI_PORTA, LL_SYSCFG_EXTI_LINE0);


   LL_EXTI_InitTypeDef EXTIinitStruct = {0};
   EXTIinitStruct.Line_0_31 = LL_EXTI_LINE_0;
   EXTIinitStruct.LineCommand = ENABLE;
   EXTIinitStruct.Mode = LL_EXTI_MODE_EVENT;
   EXTIinitStruct.Trigger = LL_EXTI_TRIGGER_FALLING;
   LL_EXTI_Init(&EXTIinitStruct);
}

void HW_EnterStopMode(void)
{
   uint32_t tmpreg = 0U;
   BACKUP_PRIMASK();
   DISABLE_IRQ();
   HW_IoDeInit();

   /*clear wake up flag*/
   LL_PWR_ClearFlag_WU();

   RESTORE_PRIMASK();
   tmpreg = PWR->CR;

   /* Clear PDDS and LPSDSR bits */
   CLEAR_BIT(tmpreg, (PWR_CR_PDDS | PWR_CR_LPSDSR));

   Set LPSDSR bit according to PWR_Regulator value */
   SET_BIT(tmpreg, LL_PWR_REGU_LPMODES_LOW_POWER);

   /* Store the new value */
   PWR->CR = tmpreg;

   LL_LPM_EnableDeepSleep();

   __WFE();
   __WFE();  // <------- Calling __WFE() second time works.
}

Thanks in advance.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

I have solved your issue by following method.

/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();

/*Configure GPIO pin : PA10 */
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

LL_EXTI_InitTypeDef EXTIinitStruct = {0};
EXTIinitStruct.Line_0_31 = LL_EXTI_LINE_10;
EXTIinitStruct.LineCommand = ENABLE;
EXTIinitStruct.Mode = LL_EXTI_MODE_IT_EVENT;
EXTIinitStruct.Trigger = LL_EXTI_TRIGGER_RISING_FALLING;
LL_EXTI_Init(&EXTIinitStruct);

HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON,PWR_SLEEPENTRY_WFE); 
LL_EXTI_DeInit();
\$\endgroup\$
3
  • 8
    \$\begingroup\$ It would be better if you said (as a description) what the cause of the failure was. \$\endgroup\$ Commented Feb 8, 2018 at 14:15
  • \$\begingroup\$ Why rising edge on the GPIO and rising/falling on EXTI? \$\endgroup\$
    – ColinH
    Commented Jan 4, 2019 at 22:08
  • \$\begingroup\$ Interesting enough implementation of HAL_PWR_EnterSTOPMode actually calls _WFE() twice (which can be seen here: line899). So I guess that's how it should be, although the datasheet doesn't say anything! I will mark this as solved. \$\endgroup\$
    – Fahad
    Commented Jan 6, 2019 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.