2019-12-06 05:41 AM
Hi,
I am using Standby mode on STM32F446ZE, but I faced with a problem. Sometimes MCU doesn't enter in this mode. Exiting Standby mode via RTC wakeup.
Below is present steps which I perform for entering Standby
SCB->SCR |= 0x00000004;
PWR->CR |= 0x00000002;
PWR->CR |= 0x00000004;
__WFI();
Could you check if it is correct?
2019-12-06 09:51 PM
Looks good at the first sight, but PWR_CR.WUF bit has this in its description:
1: Clear the WUF Wakeup Flag after 2 System clock cycles
so you may need to insert a few NOPs or rearrange the code.
Also make sure there's no other interrupt pending when trying to enter standby.
JW
2019-12-06 10:48 PM
Thanks a lot
Oleksii
2019-12-07 01:56 AM
NOP is not guaranteed be time-consuming at all... They should be used only for alignment purposes. Dummy read is a safer approach.
2019-12-07 02:25 AM
In Cortex-M4 there's no mechanism which would prevent NOP from being executed (i.e. early decoding, pipeline-level skip). I don't say it's the best option though, and certainly not if you intend to migrate to 'M7 or any other core where performance is achieved by giving up "straighforwardness".
I prefer code reorganisation as primary source of timing, as it's cheap. Here WUF could be possible cleared after wakeup - but I don't use actively low-power modes so maybe this scheme would have some substantial shortcomings.
JW
2019-12-07 04:48 AM
I mostly agree, but load instructions take at least 2 clock cycles and additional cycles are dependent on a bus speed of the particular peripheral, which can be important.
Actually I'm using this and it's siblings for 16 an 8 bit types:
static inline void Cex_DummyRead32(const volatile uint32_t *pAddr, size_t nReads)
{
uint32_t xDummy; (void)xDummy;
for (; nReads > 0; --nReads) {
xDummy = *pAddr;
}
}
When optimization is turned on, this function is inlined and the loop is unrolled as a bunch of basic load instructions.
P.S. And yes - my code is also for a Cortex-M7, therefore I cannot trust on NOP. =)
2019-12-07 06:46 AM
Nice trick, thanks.
JW