Xiao nrf52 exit qspi flash deep sleep

I can succesfully put my qspi flash into deep sleep with

    flashTransport.begin();
    flashTransport.runCommand(0xB9);
    flashTransport.end();

I then power off the system with a interrupt pin to wake it up:

// setup pin for wakeup
    nrf_gpio_cfg_sense_input(g_ADigitalPinMap[INTERRUPT], NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    // power off
    sd_power_system_off();

So far so good, everything works I get 8.6uA
Now when I turn it on again through the interrupt I can’t access the qspi flash anymore.
I figured maybe I need to bring it out of deep sleep separately by running:

flashTransport.begin();
    flashTransport.runCommand(0xAB);
    flashTransport.end();

This command runs fine but any read or write command afterward still hang.
It works again when I fully power cycle the device.

Does anyone know how can I get it out of deep sleep without a full power cycle?

Hi Phillipp_W,
I am writing to the QSPI Flash using “System_ON_Sleep” and RTC interrupt wakeup instead of “deep sleep”. Maybe the sketch in the following link is helpful.
XIAO_BLE wakes up from System_ON_Sleep and Writes weather data to on-board Flash

Hi @msfujino,
Thanks for your reply. In your thread, I see you have a sleep current of 110uA. Is there any other load on the battery while it is in sleep?
I am trying to get to the 8.6uA
Currently, the best I can do is to not deep sleep QSPI flash, just the MUC. I get 25uA deep sleep consumption and everything is working perfectly fine when it wakes up. If there was a way I could wake up the QSPI flash then I could also put it into deep sleep and get back to my base line of 8.6uA

Sleep mode includes “5.3.3 System OFF mode” and “5.3.4 System ON mode” as described in the datasheet. I am using “System ON mode”, which is not expected to save much current, but can easily wake up the internal RTC. 110uA seems to be the limit for “System ON mode”.
In my sketch, the MPU sleeps in “System ON mode”, the QSPI Flash sleeps in “Deep Power-Down mode”, and both wake up with the internal RTC interrupt and can write to the QSPI Flash normally.
I suspect (but have not confirmed) that the QSPI Flash wake-up method is the same in both “System ON mode” and “System OFF mode”. Please try it.

Hi @msfujino,
Thank for the reply. I looked at the code and see what you are doing. It does work for me if I don’t go into deep sleep while the QSPI is in deep sleep, but that is what I am trying to archive.

Hi Philipp_W,
So far I have experimented with System_ON_Sleep and QSPI Flush and have had some success.
I was just about to start experimenting with Deep Sleep mode and QSPI Flush next.
If you don’t mind, could you please show me your code so I can use it as a starting point for my considerations?

Hi @msfujino,
No problem.
I am using Visual Studio Code and Platform IO. I am using the board without the sense, if you want to use the sense you have to use the board “xiaoblesense_adafruit” in the platformio.ini file
platformio.ini file:

[env]
platform = https://github.com/maxgerhardt/platform-nordicnrf52
framework = arduino

[env:xiaoble_adafruit_nrf52]
board = xiaoble_adafruit
lib_deps = 
	adafruit/Adafruit SPIFlash@^4.1.1
	adafruit/SdFat - Adafruit Fork@^2.2.1

Then in my code I use this to do to deep sleep and attach a pin interrupt:

#include <Arduino.h>
#include <bluefruit.h>
#include <Adafruit_SPIFlash.h>

#define INTERRUPT 0 // the pin you want to use to interrupt and wake up the device

Adafruit_FlashTransport_QSPI flashTransport;

void shutdown();

void setup()
{
    ...
    // Enable Soft Device
    if (!Bluefruit.begin(1))
    {
        while (1);
    }
    ...
}

void loop()
{
    ...
    if (shutdown_condition)
    {
        shutdown();
    }
    ...
}

void shutdown()
{
    //Put flash into deep sleep
    flashTransport.begin();
    flashTransport.runCommand(0xB9);
    flashTransport.end();
    // attach interrupt to wakeup
    nrf_gpio_cfg_sense_input(g_ADigitalPinMap[INTERRUPT], NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    // power off
    sd_power_system_off();
}

On wake up the device basically soft resets.

Hi Philipp_W,

if (shutdown_condition)

I have one question, what is “shutdown_condition” ?

Hi @msfujino ,
shutdown_condition is something you can fill with your own logic to evaluate to true or false.
I have a button and use that to turn on/off the device. if someone presses the button it triggers an ISR to set the shutdown condition to true.

#define INTERRUPT 0

nrf_gpio_cfg_sense_input(g_ADigitalPinMap[INTERRUPT], NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);

What is the relationship with “INTERRUPT”?

edit
Preliminary report of the experiment;
Every time I turn the D0 pin LOW, data is written to the flash, but the current during sleep is 18uA. It seems that the flash is not sleeping.

There is a discussion on releasing Flash from DeepPowerDown mode after post 6 in the link below.
Please refer to it.
XIAO_BLE wakes up from System_ON_Sleep and Writes weather data to on-board Flash - #6 by msfujino

@msfujino wow looks like you two did a lot of research, great job! And also thanks! I will try out the SPI.transfer() solution when I get the chance! getting deep sleep working for QSPI Flash would be great!