esp32 s2 tinyUSB

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

esp32 s2 tinyUSB

Postby chegewara » Sat May 30, 2020 2:45 am

I would like to share good news. Today i finished updating tinyUSB component to master branch and have prepared 3 useful and really cool examples https://github.com/chegewara/esp-idf/tr ... herals/usb:
- CDC usb, communication device class, which allows to connect with any terminal like putty and communicate with system, possible use case AT commands etc, alternative to UART, but using native USB,
- MSC, mass storage class, can be used like a common pendrive, for now example is using only internal ram (small ram disk), possible use case - OTA update by drag and drop, adding SD card will make even more use cases,
- webUSB, usb device controlled from web browser without using wifi, currently example is using website terminal to send message to esp32s2 and esp32s2 is echoing it, also its possible to connect with putty at the same time and text between website esp32 and putty, another example project what can be done with webusb https://github.com/sowbug/weblight, another use case is setup wifi credentials and all other device setting using cloud hosted website, without need to run AP

Still few more usb device types left, like HID or MIDI.

esp-idf PRs on the way, lets hope can be merged soon.

WebUSB:
Screenshot from 2020-05-30 04-25-09.png
Screenshot from 2020-05-30 04-25-09.png (143.32 KiB) Viewed 4973 times
MSC disk:
Screenshot from 2020-05-30 05-01-34.png
Screenshot from 2020-05-30 05-01-34.png (47.44 KiB) Viewed 4966 times
MSC disk benchmark:
Screenshot from 2020-05-30 08-26-40.png
Screenshot from 2020-05-30 08-26-40.png (96.3 KiB) Viewed 4946 times

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

Re: esp32 s2 tinyUSB

Postby chegewara » Tue Jun 02, 2020 6:37 am

Here is another test. This time i am using port of tinyusn library with arduino as component. Board is kaluga, and disk is in spiram, disk size 1MB:
Screenshot from 2020-06-02 08-39-10.png
Screenshot from 2020-06-02 08-39-10.png (89.77 KiB) Viewed 4767 times

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

Re: esp32 s2 tinyUSB

Postby chegewara » Fri Jun 12, 2020 3:18 pm

I played with USB and tinyusb for some time recently and i prepared small, not finished, library that can show how it is going to be easy to use it with arduino. There is few examples prepared to show few USB classed at work. Code is prepared to work as arduino as component, sorry for that:
https://github.com/chegewara/esp32s2-ti ... -component

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

Re: esp32 s2 tinyUSB

Postby chegewara » Sun Jun 21, 2020 5:08 pm

I have another cool example how to use USB on S2. This time its MSC class (mass storage) to OTA update device with drag n drop.
Its enough to copy new binary to esp32 which works like a pendrive and new firmware will be flashed and start from OTA partition.

Code is still messy, but for all who would like to test it here is dfu.bin that can be flashed and tested.
dfu.zip
(137.16 KiB) Downloaded 106 times
PS i forgot to mention, there is implemented factory reset with pin 21, so it can be updated as many times as you want

Here is arduino as component code:
https://github.com/chegewara/esp32s2-msc-ota

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

Re: esp32 s2 tinyUSB

Postby chegewara » Fri Jun 26, 2020 12:19 am

Hi,
i would like to share with another esp32 S2 demo using native USB. This time i have connected DS18d20 temp sensor and data are sent to webUSB. Whenever web page is opened and connected to esp32 data are received every 500ms and last 10 records are displayed with chart.js:

Screenshot from 2020-06-26 02-27-00.png
Screenshot from 2020-06-26 02-27-00.png (150.83 KiB) Viewed 3778 times
I know it is possible with old esp32 and web server, but here we dont need wifi connection to esp, website is hosted on internet.

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

Re: esp32 s2 tinyUSB

Postby chegewara » Mon Jul 20, 2020 4:16 am

After some time i have "ready" but still not finished arduino library that i would like to share.

https://github.com/chegewara/EspTinyUSB

I hope you all can have so much fun and joy as i had studying it. Here is short list implemented features:
  • CDC, communication device class,
  • MSC, mass storage class,
  • HID, human interface device class, this class is temporary hardcoded to use IN/OUT vendor HID,
  • MIDI, musical instrument digital interface class,
  • DFU, device firmware update class,
  • WebUSB, its using vendor class to show webusb usage.

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

Re: esp32 s2 tinyUSB

Postby ESP_Sprite » Mon Jul 20, 2020 9:25 am

Thanks for posting this! The ESP32-S2 still is a pretty new chip, and it's good to have some coverage of the features the USB peripheral has / can be used for.

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

Re: esp32 s2 tinyUSB

Postby chegewara » Mon Jul 20, 2020 10:44 am

Hi @ESP_Sprite
i think it is temporary library, because i know espressif is working on arduino tinyusb. Actually there is already added official library with USB CDC.

Please check PM

joe_fang_iD
Posts: 4
Joined: Thu Aug 01, 2019 11:59 pm

Re: esp32 s2 tinyUSB

Postby joe_fang_iD » Mon Aug 10, 2020 10:52 pm

Hi, I've been trying out your IDF and arduino-esp32s2 libraries:

Setup:

ESP32-S2-WROOM (Do I need to use the wrover?)
ESP-IDF v4.3-dev-771-gc77c4ccf6-dirty

1. The ESP-IDF MSC example fails during linkage with the following message:

FAILED: tusb_sample_descriptor.elf
cmd.exe /C "cd . && C:\Users\joe_fang\.espressif\tools\xtensa-esp32s2-elf\esp-2020r2-8.2.0\xtensa-esp32s2-elf\bin\xtensa-esp32s2-elf-g++.exe -mlongcalls @CMakeFiles\tusb_sample_descriptor.elf.rsp -o tusb_sample_descriptor.elf && cd ."
c:/users/joe_fang/.espressif/tools/xtensa-esp32s2-elf/esp-2020r2-8.2.0/xtensa-esp32s2-elf/bin/../lib/gcc/xtensa-esp32s2-elf/8.2.0/../../../../xtensa-esp32s2-elf/bin/ld.exe: tusb_sample_descriptor.elf section `.dram0.data' will not fit in region `dram0_0_seg'
c:/users/joe_fang/.espressif/tools/xtensa-esp32s2-elf/esp-2020r2-8.2.0/xtensa-esp32s2-elf/bin/../lib/gcc/xtensa-esp32s2-elf/8.2.0/../../../../xtensa-esp32s2-elf/bin/ld.exe: region `dram0_0_seg' overflowed by 5840 bytes

2. Arduino-esp32s2 EspTinyUSB library, both the MSC and the all_in_one example. They give me the following during runtime:

ELF file SHA256: 0000000000000000

Rebooting...
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x3 (RTC_SW_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40025c41
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe8100,len:0x4
load:0x3ffe8104,len:0x570
load:0x40050000,len:0x1620
load:0x40054000,len:0x1a04
entry 0x40050280
Guru Meditation Error: Core 0 panic'ed (StoreProhibited). Exception was unhandled.

Core 0 register dump:
PC : 0x4001abc8 PS : 0x00060030 A0 : 0x80080e89 A1 : 0x3ffc8a90
A2 : 0x00000000 A3 : 0x3ffbda30 A4 : 0x00001400 A5 : 0x00000000
A6 : 0x4d903ceb A7 : 0x534f4453 A8 : 0x3ffbee30 A9 : 0x3ffc8a60
A10 : 0x00000000 A11 : 0x00000400 A12 : 0x00000000 A13 : 0x00000003
A14 : 0x3ffc2720 A15 : 0x3ffc8b44 SAR : 0x00000000 EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000003 LCOUNT : 0x40026961

Backtrace:0x4001abc5:0x3ffc8a90 |<-CORRUPTED



One of the examples did say that I had to use the wrover, so maybe if I used a ESP32-S2-WROVER, the arduino library would work?

Additional Question:

Can I implement drag-and-drop features using USB CDC instead of TinyUSB?

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

Re: esp32 s2 tinyUSB

Postby chegewara » Thu Aug 20, 2020 8:07 am

Hi,
this has been answered in another post on forum.

Today i would like to share good news. I have first on the world (or maybe not) working ESP32 S2 pendrive that can read SD card over SPI.
Code is working with a bit changed arduino-esp32 and my library. Its not super speed, i would say it slow, yet, but it is working and can be read/write by OS (tested with linux) and still can be read/write by esp32 like usual.
Screenshot from 2020-08-20 10-02-16.png
Screenshot from 2020-08-20 10-02-16.png (90.4 KiB) Viewed 970 times
Screenshot from 2020-08-20 09-59-23.png
Screenshot from 2020-08-20 09-59-23.png (96.3 KiB) Viewed 970 times
Here for comparison is benchmark of RAM disk from the same code:
Screenshot from 2020-08-20 10-05-54.png
Screenshot from 2020-08-20 10-05-54.png (73.41 KiB) Viewed 970 times

Who is online

Users browsing this forum: No registered users and 3 guests