Low power with Xiao nrf52840 on Zephyr RTOS

Thanks a lot for this post @daCoder ! It definitely put me in the right track.

Using the latest SDK from nordic (2.7.0) this can be greatly simplified to:

xiao_ble.dts:

// buttons: Use sense mechanism for edge detection (sense-edge-mask) instead of GPIOTE
// to save energyc consumption.

&gpio0 {
    status = "okay";
    sense-edge-mask = <0xffffffff>;
};

&gpio1 {
    status = "okay";
    sense-edge-mask = <0xffffffff>;
};

// Fix pinning of quad spi flash so that it doesn't consume power on suspend
// this won't be needed once https://github.com/zephyrproject-rtos/zephyr/pull/79222 is merged
// and released by Nordic
&qspi {
    // Do not change the pins during sleep otherwise a 6mA consumption happens
    pinctrl-1 = <&qspi_default>;
};

Initialization code:

#include <zephyr/pm/device.h>
#define XIAO_QSPI DT_ALIAS(spi_flash0)
static const struct device *qspi_dev = DEVICE_DT_GET(XIAO_QSPI);

static void init_peripherals(void)
{
	int err = pm_device_action_run(qspi_dev, PM_DEVICE_ACTION_SUSPEND);
	if (err) {
		printk("cannot suspend qspi device\n");
	}
}

proj.conf

# set to 'y' for debugging:
CONFIG_LOG=n
CONFIG_SERIAL=n
CONFIG_CONSOLE=n
CONFIG_USB_CDC_ACM_LOG_LEVEL_OFF=n
CONFIG_USB_DEVICE_STACK=n

CONFIG_PM_DEVICE=y