AnsweredAssumed Answered

STM32F401 Stop Mode entry

Question asked by johansson.jesper on Apr 11, 2016
Latest reply on Apr 20, 2017 by Szim.Wojciech
Hello,


I'm currently working on an application in which I need to put the MCU into the STOP mode, being able to wake it up by means of an EXTI. However, I'm having difficulties putting the MCU to STOP using __WFI(). It works properly when calling __WFE(); __WFE(); (twice).


According to Table 19 in the reference manual the following needs to be performed before trying to enter into Stop, otherwise the instruction will be ignored:


Note: To enter stop mode, all EXTI line pending bits in EXTI_PR, all peripheral interrupts pending bits, the RTC alarms (A and B), RTC Wakeup, RTC Tamper, and RTC TimeStamp flags, must be reset. Otherwise, the Stop mode entry procedure is ignored and program execution continues.


As far as I can understand, I perform these steps, but the device still ignores the __WFI() instruction.


Has anyone had similar problems with this or can understand where I'm missing the point?




/* STOP mode entry procedure from RM Table 19.
 * ==========================================================
 * Note: To enter stop mode, all EXTI line pending bits in
 * EXTI_PR, all peripheral interrupts pending bits, the RTC
 * alarms (A and B), RTC Wakeup, RTC Tamper, and RTC TimeStamp
 * flags, must be reset. Otherwise, the Stop mode entry
 * procedure is ignored and program execution continues. */


/* Disable the SysTick */
SysTick->CTRL  = 0;


/* Clear any pending EXTI */
EXTI->PR = 0xFFFFFFFF;


/* Clear any pending peripheral interrupts */
for (i = 0; i < 8; i++) {
    NVIC->ICPR[i] = 0xFFFFFFFF;
}


/* Clear the RTC pending flags */
RTC->ISR &= ~(RTC_ISR_ALRAF | RTC_ISR_ALRBF | RTC_ISR_WUTF | RTC_ISR_TSF | RTC_ISR_TAMP1F);


/* 1. Set the SLEEPDEEP bit in FPU System Control register.
 * From PM:
 * 1: Deep sleep. */
SCB->SCR |= (1 << SCB_SCR_SLEEPDEEP_Pos);


/* 2. Clear PDDS bit in power control register
 * From RM:
 * 0: Enter stop mode when CPU enters deepsleep.
 * The regulator status depends on the LPDS bit */
PWR->CR &= ~(PWR_CR_PDDS);


/* 3. Select the voltage regulator mode by configuring LPDS bit in PWR_CR.
 * From RM:
 * 1: Low-power voltage regulator on during stop mode */
PWR->CR |= PWR_CR_LPDS;


/* Perform a wait-for-interrupt */
__WFI();






Sincerely,


Jesper

Outcomes