Pin Wake-Up from EM4 on Jade/Pearl Gecko

by <a href=""><font color="#000000"><font size="2">Hero Employee</font></font> </a> JohnB ‎03-01-2017 06:02 PM - edited ‎03-03-2017 07:38 PM

EM4 on the original Gecko MCU served as a kind of lowest power standby mode where the only wake-up options were power-cycling the device or asserting the RESETn pin. This was enhanced on subsequent devices with a mechanism that allows wake-up via alternate pins that, while still causing resets, are registered so that program flow can change depending on which pin caused the wake-up.


Pin-based wake-ups on Jade and Pearl Gecko, along with the EFR32 Blue, Flex, and Mighty Gecko families, operate in a fashion similar to that on previous devices. No distinction is made between hibernate (EM4H) and shutoff (EM4S) modes with regards to either configuration or functionality; pin wake-ups operate the same in both modes.


Knowing this, then, how are pin wake-ups configured on these devices? The procedure is quite simple:


  1. Configure any I/O pins that will be used for wake-up as inputs. The supported pins are PA3, PB13, PC10, PD14, PF2, and PF7. Note that PA2 and PF7 are not bonded on the QFN32 package.

  2. Each wake-up capable pin has a corresponding bits in the GPIO_EXTILEVEL register that determines whether the pin triggers wake-up on a low or high level.

  3. Likewise, a flag bit in the EM4WU field of the GPIO_IF register captures if a given pin caused the most recent wake-up. This bit must preemptively be cleared before the pin is enabled for wake-up.

  4. One of the two GPIO pin state retention options must be selected by the EM4IORETMODE field in the EMU_EM4CTRL register. This has the effect of retaining the output enable, output value, and pull enable states of all GPIO pins either through exit (wake-up) from EM4 or until the GPIO registers are unlatched under software control. This is required in order to use pin-based wake-ups.

    Consequently, any output pins capable of sourcing current should be disabled in order to achieve the 40 nA range current draw of which Jade/Pearl Gecko is capable when in EM4.

    Similarly, on-chip pull devices enabled on wake-up pins will also increase EM4 current, so consider using external pull-up resistors and wake upon falling edges.

  5. Finally, enable a pin for EM4 wake-up by setting its respective bit in the GPIO_EM4WUEN register. Particularly helpful in all of this is that the GPIO_EM4EnablePinWakeup() function takes care of steps 2 through 5 of this procedure.

Once setup is complete, including anything needed for EM4, such as selection of hibernate or shutoff mode, drop into EM4 at any time by calling the emlib EMU_EnterEM4() function or by writing the designated bit sequence to the EM4ENTRY field of the EMU_EM4CTRL register. Wake-up occurs when a designated pin (or pins) sees its specified level in addition to the usual RESETn assertion or power-cycling events.


To illustrate this, an example Simplicity Studio v4 project for the Pearl Gecko SLSTK3401A Starter Kit is attached to this Knowledge Base article. Program flow is as follows:


  1. After some minimal initialization, the cause of the last reset is determined.

  2. GPIO pins are configured for inputs or outputs as needed, and LED1 is turned on only if a pin wake-up from EM4 was responsible for the last reset.

  3. The program then performs a 4-second countdown before turning on LED1 and configuring PF7, which is connected to push button BTN1, for wake-up.

  4. EMU_EnterEM4() is called, and the device goes into EM4 (shutoff, in this example) and remains in this mode until PF7 goes low (BTN1 is pressed).

After downloading the example project, import it into Simplicity Studio as follows:


  1. In the Simplicity Studio IDE, go the File menu (not the Project menu) and select Import…

  2. Under General, select Existing Projects into Workspace, then click Next.

  3. For Select archive file, locate the project .ZIP file and select it.

  4. Make sure Copy projects into workspace is checked.

  5. Click Finish.

Build the project, download it to the STK, and run it with the debugger. Note that when the MCU enters EM4, the debugger will lose its connection to the STK. Press BTN1 to exit EM4 before attempting to restore the debugger connection.

by napowelson
on ‎03-02-2017 10:21 PM

Can you show an example of this, perhaps using the Pearl Gecko starter kit? BTN1 is a supported wake-pin, so it should be possible, but a lot of what you describe here doesn't make sense.


What about functions like:

void GPIO_EM4EnablePinWakeup	(uint32_t 	pinmask,uint32_t 	polaritymask)


I can' t for the life of me find any documentation on what the pinmask and polaritymask's are to configure.

by <a href=""><font color="#000000"><font size="2">Hero Employee</font></font> </a> JohnB
on ‎03-03-2017 07:37 PM



The article got published while it was still waiting in the drafts folder. I based it on the articles I did for Happy Gecko and Zero Gecko but hadn't yet finished making all of the necessary changes.


I've gone ahead and finished what I started and included an example for the Pearl Gecko STK. The code is heavily commented and should explain any questions you have.

by napowelson
on ‎03-04-2017 02:18 PM

Followup question, where can I find documentation on the pinmasks? In the example you use 0x2 to map the wakeup pin to PF7, but I don't understand the mapping.


GPIO_EM4EnablePinWakeup(0x2 << _GPIO_EM4WUEN_EM4WUEN_SHIFT, 0);
by <a href=""><font color="#000000"><font size="2">Hero Employee</font></font> </a> JohnB
on ‎03-06-2017 02:53 PM



Where can I find documentation on the pinmasks?


It's kind of implicit in the naming of the pins capable of external wake-up. Consider this part of the alternate function table from the Pearl Gecko datasheet:




Note that these pins are not numbered contiguously. In theory, we could provide a total of 16 pins for EM4 wake-up, but any given device only has a handful. These pin names correspond to their bit positions in the various registers associated with EM4 wake-up, e.g. GPIO_EXTILEVEL:




You'll notice that although these bits are (potentially) numbered [15:0], they reside in the upper halfword of their associated registers. So, that leads to your next question:


In the example you use 0x2 to map the wakeup pin to PF7, but I don't understand the mapping.


GPIO_EM4EnablePinWakeup(0x2 << _GPIO_EM4WUEN_EM4WUEN_SHIFT, 0);

For any given EM4 wake-up pin, use the bit mask that corresponds to its position in the ordering of pins. As the datasheet table above shows, PF7 corresponds to EM4WU1, so the bit mask corresponding to it would be 0x02 (as 0x01 is the mask for EM4WU0 which is mapped to PF2). This mask is then shifted 16 bits left (_GPIO_EM4WUEN_EM4WUEN_SHIFT), so that it is read/written/ANDed/ORed with the upper 16 bits of whatever registers need to be written to enable, disable, set, or clear a bit in any register associated with EM4 wake-up (GPIO_EXTILEVEL, GPIO_IF, GPIO_IFC, GPIO_IFS, GPIO_IEN, and GPIO_EM4WUEN).


I think that should help explain things. Heck this stuff probably warrants its own KB article Robot wink