Getting the M5StickC Plus2 to flash
The pesky ‘Wrong boot mode detected (0xb) error’
Summary
Hard power off your M5StickC Plus2 by pressing the power button for 6 seconds then try loading code again.
The power button is labelled as ‘BUTTON C’ in the image below, which is taken from this website.
Button C is the power switch. From https://docs.m5stack.com/en/core/M5StickC%20PLUS2
The problem
I’d flashed a program to trial the TFT_eSPI graphics library. I was left with a blank display and what acted like a bricked device. When trying to flash updated code onto my shiney M5StickC Plus2 I repeatedly got the following error:
A fatal error occurred: Failed to connect to ESP32: Wrong boot mode detected (0xb)! The chip needs to be in download mode.
The solution
I use VSCode with the platformio plugin for my ESP32 programming.
First things first, is the module alive?
In VSCode, I clicked on the little house symbol that takes me to the PlatformIO home panel. Then I clicked on ‘Devices’ on the left menu. This showed a board connected to ttyASM0 with a readable PID and serial number.
pio home panel, showing the connected M5StickC Plus2
Handling G0 and EN during flashing ‘should’ be handled by the module. I’ve had an ESP32 board where I did have to manually hold down a button to get it to program. However, it looked like the M5StickC Plus2 had programmed once but with duff code. So the G0 and EN toggling should be handled by the M5StickC Plus2 without my needing to interfere with it.
So…. one of these signals is not toggling correctly. Which made me realise that the M5StickC Plus2 was still powered on but with a blank display. The module has a battery, so just replugging the USB cable did not power off the board.
As often, the trick was to turn it off and back on again! Unplug the USB cable and hold the power button down for 6 seconds. Then reconnect the USB cable and try flashing it again.
More waffle
Initially I thought that G0 needed to be pulled to ground to enable the ESP32 to go into the correct mode to be programmed. In fact, it does, but this is handled by the onboard programming hardware.