This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf9160 GPIO wakeup from System OFF

Hi!  I'm trying to get a basic example to show the 9160 going into the System Off mode and then waking up when a button is pressed.  However I have not been able to get the button to pull the chip out of the Off state.

My example looks like this currently

#include <zephyr.h>
#include <drivers/gpio.h>
#include <device.h>
#include <hal/nrf_gpio.h>
#include <hal/nrf_power.h>
#include <hal/nrf_regulators.h>

#define BUTTON_PIN 26
#define RED_LED    12
#define GREEN_LED  13

static struct device *dev;
void setup_io(void) {
    dev = device_get_binding("GPIO_0");
    // Configure both LED's as outputs
    gpio_pin_configure(dev, RED_LED, GPIO_OUTPUT_INACTIVE | GPIO_ACTIVE_LOW | GPIO_PULL_UP);
    gpio_pin_configure(dev, GREEN_LED, GPIO_OUTPUT_INACTIVE | GPIO_ACTIVE_LOW | GPIO_PULL_UP);
}

void main(void) {
    setup_io();

    uint32_t rr = nrf_power_resetreas_get(NRF_POWER_NS);
    if (rr & NRF_POWER_RESETREAS_OFF_MASK) {
        nrf_power_resetreas_clear(NRF_POWER_NS, 0x70017);
        gpio_pin_set(dev, GREEN_LED, 1);
    } else {
        gpio_pin_set(dev, RED_LED, 1);
    }

    k_sleep(K_MSEC(2000));

    gpio_pin_set(dev, GREEN_LED, 0);
    gpio_pin_set(dev, RED_LED, 0);

    nrf_gpio_cfg_input(BUTTON_PIN, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_sense_set(BUTTON_PIN, NRF_GPIO_PIN_SENSE_LOW);

    //
    nrf_regulators_system_off(NRF_REGULATORS_NS);
}

The prj.conf looks like this:

CONFIG_HEAP_MEM_POOL_SIZE=16384

CONFIG_SERIAL=n
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_LOG=n
CONFIG_LOG_BACKEND_UART=n

and the SPM prj.conf looks like this:

CONFIG_IS_SPM=y
CONFIG_FW_INFO=y
CONFIG_GPIO=n

CONFIG_SPM_NRF_REGULATORS_NS=y

CONFIG_SERIAL=n
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_LOG=n
CONFIG_LOG_BACKEND_UART=n

Does anyone have any experience with getting this to work and could they point out what I'm missing?


Thank you so much!

Related