3
\$\begingroup\$

I'm using an external interrupt triggered by a button press to wake up an STM32F030K6 from STOP mode. I was wondering if there's any way of distinguishing, within the interrupt handler, a button press that triggered a wakeup from a regular button press.

\$\endgroup\$
3
\$\begingroup\$

You always have the possibility to add that feature manually through setting a flag before you enter the STOP mode, and check if that flag is set in the interrupt handler.

As you might forget to do that every time you enter STOP mode, you could write a global function (like the compiler intrinsic) which sets the flag and enters STOP mode.


EDIT: I thought this bit would be helpful, but as @foldl found out, this bit seems to be set only in case of a wakeup from the wakeup pins and not from other pins. I haven't seen any other bit which might be useful for this.

The PWR_CSR register contains a wakeup flag bit (WUF, bit 0):

Bit 0 WUF: Wakeup flag This bit is set by hardware to indicate that the device received a wakeup event. It is cleared by a system reset or by setting the CWUF bit in the Power control register (PWR_CR)

0: No wakeup event occurred

1: A wakeup event was received from one of the enabled WKUPx pins or from the RTC alarm.

Note: An additional wakeup event is detected if one WKUPx pin is enabled (by setting the EWUPx bit) when its pin level is already high.

See Reference Manual Page 83.

So in your interrupt service routine, you can check this flag. Note however, that you have to manually clear it through setting the CWUF bit in the PWR_CR register:

Bit 2 CWUF: Clear wakeup flag.

This bit is always read as 0.

0: No effect

1: Clear the WUF Wakeup Flag after 2 System clock cycles. (write)

\$\endgroup\$
  • 1
    \$\begingroup\$ WUF reads as 0 within the interrupt handler. I think this is because the interrupt isn't coming from the WKUP pin (there's only one on the STM32F030K6). The uc is in STOP mode, not STANDBY mode, so any external interrupt can be used to wake it up. Perhaps the only way to do this is to set a flag manually. \$\endgroup\$ – foldl Apr 19 '15 at 18:22
  • \$\begingroup\$ The horrible thing about st's reference manuals is that they don't have a consistent naming for things. Wakeup event is used quite often in different meanings. I haven't seen any other helpful bit in the reference or programming manual. I'll edit my post to reflect your testing. \$\endgroup\$ – Arsenal Apr 19 '15 at 18:43
  • \$\begingroup\$ Thanks. One thing: I'm not sure if it's necessarily the case that the uc has to be in STANDBY mode. It may be that even in STOP mode, the flag would be set if the wakeup event was triggered by one of the WKUPx pins. \$\endgroup\$ – foldl Apr 19 '15 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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