Edit: This question is wrong. The stm325105 has only one wakeup pin. But other ST-parts has more than one wakeup pin, so the given answer is valid for those.

I have a stm32f105 that has two momentary buttons connected to the wakeup inputs. The processor is put in STANDBY MODE. When any of the buttons are pressed, or the RTC timer fires, the cpu wakes up.

The problem is that I want the cpu to do different things depending on which wakeup input was triggered. According to 5.3.5 from ST stm32f105xx reference manual, no registers are preserved except for a status register indicating that we've been woken up (but not by who) and 42 backup registers.

The Standby mode allows to achieve the lowest power consumption. It is based on the Cortex ® -M3 deepsleep mode, with the voltage regulator disabled. The 1.8 V domain is consequently powered off. The PLL, the HSI oscillator and the HSE oscillator are also switched off. SRAM and register contents are lost except for registers in the Backup domain and Standby circuitry.

After waking up from Standby mode, program execution restarts in the same way as after a Reset (boot pins sampling, vector reset is fetched, etc.). The SBF status flag in the Power control/status register (PWR_CSR) indicates that the MCU was in Standby mode.

This ST forum post, How to determine the origin of Wakeup from Standby?, suggests that I can't detect which wakeup triggered in software. I found no other posts there that gave any more enlightment.

How can I use software or hardware for determining, after waking up, which wakeup input was triggered?

  • 1
    \$\begingroup\$ Have the button charge up a cap and read that \$\endgroup\$
    – PlasmaHH
    Sep 29, 2017 at 10:49
  • 1
    \$\begingroup\$ Looked up a few STM32F105 variants, they have only ONE wakeup pin. Which part do you mean exactly, and which pins? \$\endgroup\$ Sep 30, 2017 at 5:42
  • \$\begingroup\$ @berendi My STM32F105 has, as you say, just one wakeup pin. It is configured in STOP MODE, not STANDBY mode as I stated in my question. It uses EXTI events for waking up. I had mixed up the meaning of those "EXTI events" with "wakeup pins". But I guess the answer provided by Olin is still useful if someone needs to differentiate between "woken by RTC" or "woken by wakeup pin" in STANDBY MODE. Does anyone have suggestions on how to edit this question to match Olins answer? A small note at the beginning describing what's wrong? En entire re-edit? Or should I just delete the whole question? \$\endgroup\$ Oct 1, 2017 at 17:31
  • 1
    \$\begingroup\$ There are ST controllers with more than one wakeup pin, like F0, F3, L0, or L1, where the source can indeed not be determined after exit from standby, because they have a single wakeup input flag. ST has corrected this oversight first in the newest F7 and L4 series, which have separate flags for each wakeup input. \$\endgroup\$ Oct 2, 2017 at 6:48

1 Answer 1


I don't know the details of this ST part, so I'll assume your description of it is correct.

The processor should wake up very soon after either button is pressed. This should be especially true if it has a internal RC oscillator. Even if you need to run from a crystal eventually for accuracy reasons, perhaps you can have the part start from a internal RC, then switch to the crystal later. There are micros that can do such things, although I don't know if yours is one of them.

In any case, you read both inputs as soon as possible after wakeup. Unless there is something unusual about this ST micro, that should be from a ms to a few 10s of ms from the button press.

To guarantee the line is still low, use a capacitor to keep the line low for up to 100 ms after the button is released.

For example, let's say the guaranteed logic low input level is 20% of the supply voltage. The line is pulled up with a resistor, and has a capacitor to ground. The button shorts the line to ground. The line therefore floats high, and is actively forced to ground when the button is pressed. When the button is released, the voltage exponentially decays towards the supply.

Decaying to 20% of the final value happens in 0.22 time constants. Lets say you want to guarantee the line looks low for 100 ms after a button press. That means the RC time constant must be 450 ms. With 100 kΩ pullup, the capacitance would need to be 4.5 µF. So a 4.7 µF 10 V cap would do nicely.

In summary, here is the circuit:

  • 1
    \$\begingroup\$ Should be the other way round, STM32s wake up on rising edge. Also, afaik they always start with the internal clock, switching to external crystal and pll is done by the software. The problem is with the startup code supplied or generated by the CubeMX tool, which makes it somewhat difficult to run user code before the clock tree setup. \$\endgroup\$ Sep 29, 2017 at 21:04

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.