adafruit / Adafruit_TinyUSB_Arduino

Arduino library for TinyUSB
MIT License
487 stars 129 forks source link

ESP32S2 MassStorage with External Flash chip #150

Closed 1337ralfy69 closed 2 years ago

1337ralfy69 commented 2 years ago

Operating System

Others

IDE version

1.8.19

Board

ESP32S2

BSP version

1.8.4

TinyUSB Library version

github latest

Sketch

examples/massstorage/msc_external_flash

What happened ?

Hey there, im trying to build a usb mass storage device with ESP32S2 and W25Q80 flash chip connected via SPI and using Adafruit TinyUSB and Adafruit SPIFlash library. :star_struck:

So, msc_ramdisk and msc_sdfat(with sd card adpter) examples works great and shows up as mass storage device, also Marzogh`s SpiMemory library example TestFlash works with flash chip, shows flash ID e.t.c. :slightly_smiling_face:

But i cant figure out why example code msc_external_flash(TinyUSB) or flash_info(Adafruit SPIFlash) doesnt run on ESP32S2. Codes are similar, and i suspect that it does not correctly initialize SPI interface, as oscilliscope is connected to SCK and SS pins, all above written skeches shows activity on SPI bus, but when msc_external_flash or flash_info are uploaded, it shows floating pins. :face_with_raised_eyebrow: And also these two example sketches with no alteration runs ok, but no SPI communication, when trying set "custom" SPI, ESP chip starts resetting itself - Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.

`#include "SdFat.h"

include "Adafruit_SPIFlash.h"

define CUSTOM_CS 34

define CUSTOM_SPI SPI //some examples use FSPI insted of SPI, but it doesnt work here

Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);

Adafruit_SPIFlash flash(&flashTransport);

void setup() { Serial.begin(115200); Serial.println("Adafruit Serial Flash Info example");

// flash.begin(); //this one should be used, but esp starts reseting when calling, mby thats the problem? flashTransport.begin(); //initializes SPI but obviously flash.getJEDECID() and flash.size() will not work. }

void loop() { Serial.print("JEDEC ID: 0x"); Serial.println(flash.getJEDECID(), HEX); Serial.print("Flash size: "); Serial.print(flash.size() / 1024); Serial.println(" KB"); delay(100); }`

What i tried: -Different GPIO_Pins for SS(chip select) and that code on ESP32-WROVER-IE, and does the same thing - 1 core paniced, and also does not decode backtrace

-Many different verisons, with no luck, and yeah, looks like mby issue is in Adafruit_SPIFlash library?

How to reproduce ?

Upload to ESP32S2 Board without any changes, does no initialize SPI, when set to custom SPI, it starts reseting.

Debug Log

It would give much needed info, but it fails to decode

'Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.

Core 0 register dump: PC : 0x4009918b PS : 0x00060630 A0 : 0x800816e4 A1 : 0x3ffc65c0
A2 : 0x00000001 A3 : 0x3f0018a6 A4 : 0x00000022 A5 : 0x0000ff00
A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x3ffc0be0 A9 : 0x009c1001
A10 : 0x3ffc0c78 A11 : 0x00000022 A12 : 0x000000ff A13 : 0x000000ff
A14 : 0x000000ff A15 : 0xff000000 SAR : 0x0000001d EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000019 LBEG : 0x000000ff LEND : 0x000000ff LCOUNT : 0x40026ef5

Backtrace:0x40099188:0x3ffc65c00x400816e1:0x3ffc65e0 0x40081649:0x3ffc6600 0x40081002:0x3ffc6620 0x400834e6:0x3ffc6650 Decode Failed'

Screenshots

No response

hathach commented 2 years ago

which specific board you are testing on, is it your custom hardware ?

1337ralfy69 commented 2 years ago

Im testing on ESP32-S2-Saola-1

hathach commented 2 years ago

This is not a bug of this repo, Adafruit_SPIFlash currently only supports accessing the files that is on the same chip with the executing code. We have no plan to support this, but we are happy to review and merge it if you want to make an PR (to Adafruit_SPIFlash).