DeepSleep bricks XIAO_MG24

DeepSleep on MG24 may cause it to stop accepting new sketch upload. Currently, there is no way to recover from this, as there is no published method on the Wiki to put the MG24 into “boot mode”. Caution is required.

A possible interim solution is to detect the user switch in the setup() so that it enters an infinite loop, and upload the sketch while it is looping.
I have experimented with the following sketch and it works.

We are waiting for a formal countermeasure as soon as possible.

//----------------------------------------------------------------------------------------------
// BoardBoard Library : Silicon Labs 2.2.0
// Board Select       : Seeed Studio XIAO MG24 (Sense)
// Plotocol stack     : None 
//----------------------------------------------------------------------------------------------
// 2024/12/29 @msfujino

// IMPORTANT NOTE:Cannot upload new sketches during DeepSleep

#include <Arduino.h>
#include "ArduinoLowPower.h"

// User SW for upload
#define USER_SW  PC3   // (3), D3 for example

// on board Flush SPI_1 pins
#define CS1      PA6   // (21)
#define CLK1     PA0   // (17), D17   
#define MOSI1    PB0   // (15), D15
#define MISO1    PB1   // (16), D16

// on board peripherals pins
#define IMU_EN   PD5   // (19)
#define MIC_EN   PC8   // (22)
#define VBAT_EN  PD3   // (25)
#define RFSW_EN  PB5   // (27)

// Flash commands
#define READ_DATA     0x03
#define WRITE_ENABLE  0x06
#define PAGE_PROGRAM  0x02
#define SECTOR_ERASE  0x20

// Flash functions
void sendSPI(byte data) {
  for (int i = 0; i < 8; i++) {
    digitalWrite(MOSI1, data & 0x80);
    data <<= 1;
    digitalWrite(CLK1, HIGH);
    delayMicroseconds(1);
    digitalWrite(CLK1, LOW);
    delayMicroseconds(1);
  }
}

void writeEnable() {
  digitalWrite(CS1, LOW);
  sendSPI(WRITE_ENABLE);
  digitalWrite(CS1, HIGH);
}

// ******************************************************************************
void setup()
{
  Serial.begin(115200);
  while(!Serial);
  delay(2000);
  Serial.println("Deep sleep / upload test");

  // builtin LED
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);

  // on board flash
  pinMode(CS1, OUTPUT);
  pinMode(CLK1, OUTPUT);
  pinMode(MOSI1, OUTPUT);
  pinMode(MISO1, INPUT);
  digitalWrite(CS1, HIGH);   // CS1 HIGH

  // on board peripherals
  pinMode(IMU_EN, OUTPUT);
  pinMode(MIC_EN, OUTPUT);
  pinMode(VBAT_EN, OUTPUT);
  pinMode(RFSW_EN, OUTPUT);
  digitalWrite(IMU_EN, LOW);   // IMU Power OFF
  digitalWrite(MIC_EN, LOW);   // MIC Power OFF
  digitalWrite(VBAT_EN, LOW);  // VBAT Power OFF
  digitalWrite(RFSW_EN, LOW);  // RFSW Power OFF

  // Flash Deep Power Down 
  writeEnable();
  digitalWrite(CS1, LOW);
  sendSPI(0xB9);
  digitalWrite(CS1, HIGH);

  Serial.println("Need to stay awake to upload new sketches");

  // if user sw is on, blink and enable to upload new sketch
  pinMode(USER_SW, INPUT_PULLUP);
  if(digitalRead(USER_SW) == LOW) {
    Serial.println("enable to upload new sketch");
    while(true) {
      digitalWrite(LED_BUILTIN, LOW);
      delay(50);
      digitalWrite(LED_BUILTIN, HIGH);
      delay(50);
    }
  }

  Serial.println("end of setup");
}

// *******************************************************************************************
void loop()
{
  // blink LED
  digitalWrite(LED_BUILTIN, LOW);
  delay(500); 
  digitalWrite(LED_BUILTIN, HIGH);

  Serial.printf("Going to deep sleep");

  // IMPORTANT NOTE:Cannot upload new sketches during DeepSleep
  LowPower.deepSleep(10000);
}

I think i had this happen to me on ano6her XIAO when I was “PLAYING” with it! dont remember how i got it to snap out of it… maybe if it is unpowered for a long period of time

Each of the other XIAOs has a way to enter boot mode, so this is not a problem, but XIAO_MG24 does not have a way published on the Wiki at this time.

2 Likes

Hi there,

Seasons Greetings :christmas_tree: and THANK YOU for saving me from the “BRICK” mode…
Man No interrupt support(IMU) or battery A/D the list is growing? Why even use this device?
appears to me someone pulled the wool on them, because this device is NOT ready for PRIME time! IMO…

I see there published SLEEP numbers… :face_with_peeking_eye: Hmm I’m skeptical.
NOT BL mode tops it for Me LOL, it’s like Soup with NO spoon :grimacing:

GL :slight_smile: PJ :v:

Hi PJ,
MG24, which is very similar to nRF52840, is being evaluated, but so far it is not very attractive.
The DeepSleep current is indeed less than 2uA, but it easily reaches 5uA when the room temperature rises, which is the same level as the nRF52840.
In my opinion, the 8-port pads on the back side is not necessary so many, rather the ports should be used for IMU interrupts and boot switch.

I will post a report after I finish my evaluation.

1 Like

The part that put the flash in sleep mode is also a problem . My code is only going later to deep sleep (LowPower.deepSleep) after BLE stuff . But on setup I still did the flash sleep mode code.

Please submit your sketche so we can try them out.

1 Like

After a careful search of BSP 2.2.0, I found a loop function already prepared to avoid bricking.
There is no need to call any particular function, just set PC0 = LOW and reset to enter the loop and enable upload.
Care should be taken when using PC0 as its own I/O.
See below.

\Arduino15\packages\SiliconLabs\hardware\silabs\2.2.0\libraries\ArduinoLowPower\src\ArduinoLowPower.cpp:L240 escape_hatch()

\Arduino15\packages\SiliconLabs\hardware\silabs\2.2.0\variants\xiao_mg24\pins_arduino.h:L114

Information on wake-up pins.
The 8 pins that can be used for wake-up from EM4:DeepSleep seem to be PC0(ESCAPE), PC5(SCL), PC7(RX), PA5(MOSI), and back side PB1, PB3, PD2, PD5(IMU_PW).

Reference Manual, 24.3.12.3 Pin Function Tables, Table 24.3. GPIO Alternate Function Table

PC0 is also defined as ESCAPE to avoid bricking. It is not impossible to use it as ESCAPE function when it is LOW for a long time and as a wake-up function for a short time.