Metro esp32-s2 reset into uf2 bootloader from arduino code

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jonspieg
 
Posts: 3
Joined: Thu Jul 27, 2017 6:35 pm

Metro esp32-s2 reset into uf2 bootloader from arduino code

Post by jonspieg »

I'm using the metro esp32s2 with arduino and the tinyuf2 bootloader to easily update firmware.
Is there a way to enter the bootloader from the arduino code?
I'm already doing so on the grandcentral samd51, but briefly going over the esp32s2 bootloader code I'm not sure how the double tap is actually implemented.

Any leads will be greatly appreciated :)

Thanks,

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Metro esp32-s2 reset into uf2 bootloader from arduino co

Post by mikeysklar »

@danhalbert / @tannewt2 example code for the Feather M0 is probably a good starting point. The NVIC_SystemReset() is supported by all ARM cores so that will work with your ESP32-S2. The special flag in the last word of RAM might be trickier to figure out the address for.

Code: Select all

void reset_to_bootloader() {
  *(uint32_t *)(0x20000000 + 32768 -4) = 0xf01669ef;     // Store special flag value in last word in RAM.
  NVIC_SystemReset();    // Like pushing the reset button.
}

void setup() {
  delay(3000);
  reset_to_bootloader();
}

void loop() {
}
viewtopic.php?f=57&t=135094

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro esp32-s2 reset into uf2 bootloader from arduino co

Post by User_UMjT7KxnxP8YN8 »

Interesting reply. I haven't found a set of CMSIS include files for the ESP32 like those for the M0 and M4 (component/instance) and assumed that's because the ESP32's Tensilica Xtensa LX6 MCU isn't based on an ARM core. Am I mistaken?

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Metro esp32-s2 reset into uf2 bootloader from arduino co

Post by mikeysklar »

Good point. The ESP32-S2 is not using an ARM core with CMSIS support.

Have you looked at the automatic bootloader mode in the ESP documentation? The ESP32-S2 is not specifically called out as supported, but it could be a start.

https://docs.espressif.com/projects/esp ... bootloader
esptool.py resets ESP32-S2 automatically by asserting DTR and RTS control lines of the USB to serial converter chip, i.e., FTDI, CP210x, or CH340x. The DTR and RTS control lines are in turn connected to GPIO0 and EN (CHIP_PU) pins of ESP32-S2, thus changes in the voltage levels of DTR and RTS will boot the ESP32-S2 into Firmware Download mode.

User avatar
jonspieg
 
Posts: 3
Joined: Thu Jul 27, 2017 6:35 pm

Re: Metro esp32-s2 reset into uf2 bootloader from arduino co

Post by jonspieg »

Thanks for the reply

What you suggest is almost exactly how I do it on the grandcentral
However NVIC_SystemReset(); Is not available on the ESP (there's an alternative esp_restart();)

After going over the bootloader code, I have the feeling that it's implemented quite differently on the ESP platform, not with a magic number that is stored somewhere in RAM.

I might be missing something here...

My end goal is that the board will be connected to a computer usb port and will run some code. at some point the code decides to get into bootloader mode (the uf2 bootloader of course) and then in the computer a new window will pop up allowing the user to drag a new firmware onto the chip. the user doesn't have access to the board itself and cannot double press the reset button in order to get it to boot as a mass storage device.

User avatar
jonspieg
 
Posts: 3
Joined: Thu Jul 27, 2017 6:35 pm

Re: Metro esp32-s2 reset into uf2 bootloader from arduino co

Post by jonspieg »

OK I think I figured it out.
It's actually using a dedicated pin connected to a resistor and a capacitor that will hold the pin state after reset for a second or so.
so every power cycle this pin is polled, and if it's high then it enters the bootloader. if it's low, it set's it high and after a short while it sets it to low again.

I wonder if there's a reason it's not implemented the same way as the SAMD boards. does anyone have an idea?

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro esp32-s2 reset into uf2 bootloader from arduino co

Post by User_UMjT7KxnxP8YN8 »

If that doesn't work, most processors have a way to invoke interrupts from software. Interrupt 0 is usually the 'power-on' interrupt.

Another way I force resets is to turn on the Watch Dog Timer (often enabled by default in Arduino ports of system files) and put your code in a tight look until it times out. You can reduce the timeout to align with your requirements if needed.

Code: Select all

[set WDT timeout]
while (true) ;

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”