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.

Hi there,

I can verify this information is SOLID.

Be VERY Careful… I FAFO’d :crossed_fingers: BRICK MODE!

I won’t use this Xiao in anything EVER to fragile and to LAME! IMO.
GL :slight_smile: PJ :v:

@msfujino - Thanks for the important information! Very useful for those “playing” with the sleep modes.

I have been using the “Escape Pin” as D10 (MOSI), or PA5.

This allowed me to use EM4 Wakeups via GPIO, as well as GPIO Interrupts when running or using EM2/3 Sleep modes.

This pin required no soldering to underside pads.

Hi there,

Also FWIW , I’m using the MG24 Sense Version with the IMU…

GL :slight_smile: PJ :v:

Hi, you can use the attached tool to perform the recovery operation, you just need to connect the data cable, unzip the zip package, and then run the bat file.
xiao_mg24_flash_erase.zip (2.8 MB)

1 Like

Hi there,

I was able to , restore Normal operation AOK…
PC0 to GND Reboot 2 times. :grin: :v:

GL :slight_smile: PJ :v:

This is a pretty serious problem, sorry everyone, I’m late. I understand that the XIAO MG24, the XIAO, is the only XIAO with a serial port chip at the moment, so at the beginning of the product’s definition it shouldn’t be like other XIAOs where you can’t upload a programme due to software anomalies in the serial port emulation. So there is no BOOT button designed, and unlike other XIAOs, there is no BOOT recovery method. But obviously, we are not thoughtful enough, ignoring the XIAO sleep mode needs to be restored in this case, then for this case, we need to give you the basic method of waking up the serial port, later I will update to the wiki. here to respond to the untimely response to the inconvenience caused by the development of all of us to express my apologies.

Thanks @Chunchun - Can you please add Verify, Reset and Debug batch files?
I have created some that work but your flash_erase looks better than my versions, I don’t have the reset_config srst_nogate; command.

Key Updates🎉
Unbricking Method
We’ve developed a script to help you recover your XIAO MG24 if it becomes unresponsive. The script is available for both Windows and macOS users. Detailed instructions can be found here.

Wiki Updates
The XIAO MG24 Wiki has been updated with preventive measures, such as using the escape pin (PC0) and modifying your sketch to avoid bricking during Deep Sleep.
These updates were inspired by the valuable contributions of our community members. Thank you for sharing your expertise and solutions!

Special Thanks
We would like to extend our heartfelt gratitude to the following community members for their exceptional contributions:
@msfujino for identifying the issue and proposing the escape pin solution.
@PJ_Glasso for sharing the recovery script and testing methods.

Your efforts have not only helped resolve this issue but also enriched our documentation for the benefit of all users.

2 Likes