esp32 s2 DFU update

chegewara
Posts: 2210
Joined: Wed Jun 14, 2017 9:00 pm

esp32 s2 DFU update

Postby chegewara » Thu Jun 04, 2020 7:38 am

Recently i am playing a lot with native USB on S2 and i have had some success with running MSC, CDC, DFU and webUSB.
Making more researches i found this website:
https://devanlai.github.io/webdfu/dfu-util/
and i discovered it it is possible to DFU update esp32S2 without any extra preparations. All we have to do is to connect it with native USB to PC, enter bootload mode with buttons, input espressif vendor ID (0x303a) and connect. Then just download new firmware.
There is one extra step required on linux, its udev rules, which is described here:
https://docs.espressif.com/projects/esp ... s/dfu.html

It is not big deal because we still need 2 buttons on board to enter bootload mode, but with tinyusb component and implemented USB DFU it is no longer required to have boot and RST buttons. That also means it is possible to OTA update without need to have extra partitions, just one, factory partition is enough.

What do you think, is it useful? Is it a reason to have S2?

ESP_Sprite
Posts: 8926
Joined: Thu Nov 26, 2015 4:08 am

Re: esp32 s2 DFU update

Postby ESP_Sprite » Thu Jun 04, 2020 7:59 am

Cute, but note it's limited to Chrome... other webbrowsers do not support WebUSB afaik. (Also, do note you still need the buttons in case the firmware crashes before it is able to enable DFU.)

chegewara
Posts: 2210
Joined: Wed Jun 14, 2017 9:00 pm

Re: esp32 s2 DFU update

Postby chegewara » Thu Jun 04, 2020 9:43 am

Are you sure espressif want to sell this product?

Thats true mozilla is not supporting webusb, thats true you have to add udev on linux, and in addition on windows you have to install driver for device with VID and PID, but all of this is not esp32 dependent. Thats is also not a reason to not show it as option.
ESP_Sprite wrote: Also, do note you still need the buttons in case the firmware crashes before it is able to enable DFU.)
Are you sure? You can always unplug device and plug it in one more time.

As a bonus, for those who would like to try few USB devices at the same time on esp32s2, not espressif because they seems not to be interested, here is dfu prepared bin, ready to install from mentioned website. In that bin is enabled webUSB echo terminal, CDC which can be tested with putty or other serial terminal, MSC 1.5MB ram disk.
Because of ram disk which is using PSRAM only wrover modules are supported. If someone with S2 wroom module would like to test it too i can build another demo.
Attachments
dfu.zip
(122.05 KiB) Downloaded 583 times

chegewara
Posts: 2210
Joined: Wed Jun 14, 2017 9:00 pm

Re: esp32 s2 DFU update

Postby chegewara » Thu Jun 04, 2020 9:53 am

This is some cool project, built with ATTiny85 which is using webUSB protocol:
https://github.com/sowbug/weblight


https://github.com/WICG/webusb

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: esp32 s2 DFU update

Postby WiFive » Thu Jun 04, 2020 1:23 pm

Could you have a dfu second stage bootloader which tries to enumerate then if it fails goes to normal boot?

chegewara
Posts: 2210
Joined: Wed Jun 14, 2017 9:00 pm

Re: esp32 s2 DFU update

Postby chegewara » Thu Jun 04, 2020 4:36 pm

I cant fully answer that question yet, but this question made me thinking. How dfu really works, because for example nordic is not using partitions. I did some test and looks like dfu is writing 1 merged file, bootloader + app, from address 0x0. That allows to update bootloader and partitions table fairly easy (tested with hello world example). That also leads to conclusion that device will be bricked if you dont have option to enter bootloader mode with buttons and something will disturb dfu update.

There is option to use software dfu. It will basically register device with USB dfu descriptor, but you have control over data and you can perform just regular OTA update. It is just theory, because i didnt test it yet.

ESP_Sprite
Posts: 8926
Joined: Thu Nov 26, 2015 4:08 am

Re: esp32 s2 DFU update

Postby ESP_Sprite » Thu Jun 04, 2020 6:53 pm

Wrt how dfu supports partitions: note we don't upload a raw binary over DFU, it's a bit more complicated and the ROM does a bunch of on-the-fly interpreting of what's uploaded before it does any writing. Documentation should be coming at some point, but here's a hint:

Code: Select all

jeroen@laptop:idfproject/build$ file blink.dfu 
blink.dfu: ASCII cpio archive (SVR4 with no CRC)
Also, sorry, my 'cute' may have been misunderstood, it was not sarcastic and I do think it's an interesting use of the WebUSB technology for sure. I just think that the inherent limitations of WebUSB in various OSses/browsers hinder general adoptation a bit.

chegewara
Posts: 2210
Joined: Wed Jun 14, 2017 9:00 pm

Re: esp32 s2 DFU update

Postby chegewara » Thu Jun 04, 2020 7:21 pm

ESP_Sprite wrote: Also, sorry, my 'cute' may have been misunderstood, it was not sarcastic and I do think it's an interesting use of the WebUSB technology for sure. I just think that the inherent limitations of WebUSB in various OSses/browsers hinder general adoptation a bit.
Like they say, where one doors get closer other doors get opened.
I agree there is a lot limitations on personal computers, like support on chromium family browsers, requirements to install drivers with VID and PID to support webUSB or DFU on windows (here espressif could help to make drivers), reuirements to add udev rules in linux, but there is a lot use cases where this can be used. Lets think about device that does not have built in wifi. It will be possible to update it, not only firmware, but also to change set of instructions by not qualified person, with android tablet or smartphone. No need to install drivers, all android devices are preinstalled with chrome browser. Just plug n play.
Sure, it was possible before with old esp32 but requires cp210x or similar usb to uart IC, now it is part of esp32 and much much cheaper and easier to use. I tested only serial example, but you can easy implement full AT set, upload spiffs or ffat partition and many more. I can find teens examples how to use it and still i feel like my mind is not open wide enough to make full usage of it.

rainman
Posts: 9
Joined: Mon Nov 16, 2015 10:50 pm

Re: esp32 s2 DFU update

Postby rainman » Sun Jun 14, 2020 1:35 pm

A contribution to this nice community: a way to flash the ESP32-S2 directly from a browser exploiting WebUSB. Built specifically for the ESP32-S2. It automatically switches the dfu mode without the need to connect twice.

dfu.stetelthings.com

You have to place the ESP32-S2 in boot mode (GPIO0 when connecting or reseting) connect it to the computer and you're good to go.
I must admit, as sprite_tm pointed out, support is basically limited to Chromium based browsers (Chrome, Chromiums, Opera and the new Edge) and also that only on the OS X it is plug'nplay. On windows you have to install an .inf file that makes the usb device available to WebUSB (available on the flashing site) while on Linux you have to grant access.

Please try it out and let me know what you like, what must be better or problems you faced. Any feedback is welcome.
(There is an example dfu bin file with a Rainmaker demo you could use).

devanl
Posts: 14
Joined: Sat Jan 04, 2020 5:26 pm

Re: esp32 s2 DFU update

Postby devanl » Mon Jun 15, 2020 8:29 pm

Hi, author of the webdfu proof-of-concept code here.

I just want to second rainman's suggestion to add a WCID descriptor to the ROM DFU bootloader so that Windows will automatically install a generic WinUSB driver. This would be a huge step forward in usability for browser based IDEs and demos that would otherwise require the user to install a driver manually. (Yes, there's a far bit of trust involved with flashing firmware from the web, but at least that's restricted to doing terrible things on your $10 devkit and whatever it can access, as opposed to doing terrible things on your workstation directly).

Who is online

Users browsing this forum: OSCPUDEV and 93 guests