cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446ZE doesn't enter in Standby mode

OBili.2132
Associate

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?

6 REPLIES 6

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

OBili.2132
Associate

Thanks a lot

Oleksii​

NOP is not guaranteed be time-consuming at all... They should be used only for alignment purposes. Dummy read is a safer approach.

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

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. =)

Nice trick, thanks.

JW