This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Exiting Sleep mode via GPIO interrupt

I've been playing around with the v1.9.1\zephyr\samples\boards\nrf\system_off\ example code, as I want to implement something similar in my own code.  But I want to be able to detect which GPIO caused the system to exit from system off, update a counter, then send it back to sleep.
In the sample code, they make a call to the following API to set up the GPIO pin to cause the interrupt and bring the device out of sleep mode
	nrf_gpio_cfg_sense_set(DT_GPIO_PIN(DT_NODELABEL(button0), gpios),
			       NRF_GPIO_PIN_SENSE_LOW);
In my code, without any of the system off functionality, I set up a GPIO to trigger an interrupt and update my counter.  That all works OK.  This is how I have it set up:
#define STRIKE_S_NODE DT_ALIAS(sw0)
    
#if DT_NODE_HAS_STATUS(STRIKE_S_NODE, okay)
#define STRIKE_SML	        DT_GPIO_LABEL(STRIKE_S_NODE, gpios)
#define STRIKE_SML_PIN	    DT_GPIO_PIN(STRIKE_S_NODE, gpios)
#define STRIKE_SML_FLAGS	DT_GPIO_FLAGS(STRIKE_S_NODE, gpios)
#else
#error "Unsupported board: button0 devicetree alias is not defined"
#define STRIKE_S_NODE    DT_INVALID_NODE
#define STRIKE_SML	""
#define STRIKE_SML_PIN	0
#define STRIKE_SML_FLAGS	0
#endif
    
const struct gpio_dt_spec sml_strike = GPIO_DT_SPEC_GET_OR(STRIKE_S_NODE, gpios,{0});

gpio_pin_configure_dt(&sml_strike, GPIO_INPUT);

gpio_pin_interrupt_configure_dt(&sml_strike,GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&strike_sml_cb_data, sml_strike_detected, BIT(sml_strike.pin));
gpio_add_callback(sml_strike.port, &strike_sml_cb_data);
But if I put the system into sleep mode, this doesn't bring the system out of sleep mode when I activate the appropriate GPIO.  In order to achieve this, I have to include the following (essentially a modification of what was in the example code)
    nrf_gpio_cfg_sense_input(sml_strike.pin, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
Is that the correct way of going about it?  Or is there a more appropriate Zephyr API for configuring a GPIO to trigger the device out of sleep mode?
And how come setting up the GPIO to trigger an interrupt as I did originally (without the nrf_gpio_cfg_sense_input API call) doesn't trigger the system out of sleep mode?
Thanks and regards,
Mike
Parents Reply Children
No Data
Related