Does that not conflict with the post further above
Standby: HF OSC shuts down, voltage regulators shut down. All SRAM and register state is lost, except for in RTC domain. Only hard reset, RTC, IWDG, WKUP event can wake up the CPU.
AIUI, the __WFI is never executed.
The code sequence I have is
SET_BIT(PWR->CR, PWR_CR_PDDS); // select standby mode
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk)); // Set SLEEPDEEP bit
__WFI();
Why is this so complicated? There seems to be no clear description of a procedure to simply shut down the CPU. If you google for it, you get hundreds of hits of people trying to work it out.
I have put in some GPIO waggle code in various places:
CLEAR_BIT(PWR->CSR, 0x00000100U); // disable WKUP pin, just in case
SET_BIT(PWR->CR, PWR_CR_PDDS); // select standby mode
TopLED(true); // this pulse comes out
TopLED(false);
TopLED(true); // this pulse comes out
TopLED(false);
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk)); // Set SLEEPDEEP bit
TopLED(true); // this pulse comes out, and DAC outputs are seen floating at this point
TopLED(false);
TopLED(true); // this pulse doesn't come out
TopLED(false);
__WFI // this is obviously never reached
Clearly it takes many CPU clocks to execute the deep sleep selection. This doesn't matter; it's just interesting. But if the main oscillator stops, there is no point in disabling Systick, is there
And you can't possibly get any internal interrupts. Which confirms the quoted text above is probably spot on.
However, then I did another test:
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk)); // Set SLEEPDEEP bit
__WFI();
TopLED(true); // this pulse doesn't come out
TopLED(false);
I suspected that due to the long delay after setting the deep sleep bit, the __WFI
does get executed, but that last pulse does not come out, so presumably the __WFI blocked execution.
More tests show that __WFI is required; the sleep bit does nothing otherwise. And no instructions get executed after __WFI; checked with this
__WFI();
TopLED(true);
TopLED(false);
if you hit that __WFI() with a masked interrupt pending of *any* type, the __WFI() effectively becomes a NOP
It doesn't appear to be as simple; I have not disabled e.g. a TIM6 1kHz interrupt, but it does
not terminate the Standby mode. Perhaps you mean if one executes __WFI and at that instant there is an interrupt pending, the __WFI is skipped. But how could one avoid that? If I clear all "IP" bits (lots of them around) there is no guarantee that one of them won't get set when I then execute the __WFI. One would have to disable all interrupts individually, clear the IP bits, and wait a bit. Is that really the procedure??