# ESP32S2 MassStorage with External Flash chip

**URL:** <https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664>\
**Category:** Programming\
**Created:** [January 13, 2022, 3:07pm UTC](https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664 "2022-01-13T15:07:44Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![1337ralfy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/1337ralfy/32/542899_2.png) [@1337ralfy](https://forum.arduino.cc/u/1337ralfy)\
**Post date:** [January 13, 2022, 3:07pm UTC](https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664/1 "2022-01-13T15:07:45Z")

</div>

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. 🤩

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. 🙂

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. 🤨  
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. 🧐

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [January 13, 2022, 3:34pm UTC](https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664/2 "2022-01-13T15:34:38Z")

</div>

Yuppers.  
Well the line of code where you wrote... Oh no lines of code that you wrote. I could get an ESP32 and a W25Q80 flash chip and try the example code but that would be in another 2 weeks or so. Tell you want. Not really telling but asking, could you post the code that is failing to work?

In code tag thingies.

---

<div class="post-metadata">

**Author:** ![1337ralfy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/1337ralfy/32/542899_2.png) [@1337ralfy](https://forum.arduino.cc/u/1337ralfy)\
**Post date:** [January 13, 2022, 3:44pm UTC](https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664/3 "2022-01-13T15:44:26Z")

</div>

My code "cleaned" from example sketch flash\_info (Adafruit SPIFlash):

```cpp
#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);
}

```

I suspect the problem is somewhere in library itself, but cant find where. Part where SPI is initialized:

```cpp
Adafruit_FlashTransport_SPI::Adafruit_FlashTransport_SPI(
    uint8_t ss, SPIClass *spiinterface) {
  _cmd_read = SFLASH_CMD_READ;
  _addr_len = 3; // work with most device if not set
  _ss = ss;
  _spi = spiinterface;
  _clock_wr = _clock_rd = 4000000;
}

Adafruit_FlashTransport_SPI::Adafruit_FlashTransport_SPI(uint8_t ss,
                                                         SPIClass &spiinterface)
    : Adafruit_FlashTransport_SPI(ss, &spiinterface) {}

void Adafruit_FlashTransport_SPI::begin(void) {
  pinMode(_ss, OUTPUT);
  digitalWrite(_ss, HIGH);

  _spi->begin();
}

```

And after that follows:

```cpp
Adafruit_SPIFlash::Adafruit_SPIFlash() : Adafruit_SPIFlashBase() {
  _cache = NULL;
}

Adafruit_SPIFlash::Adafruit_SPIFlash(Adafruit_FlashTransport *transport)
    : Adafruit_SPIFlashBase(transport) {
  _cache = NULL;
}

bool Adafruit_SPIFlash::begin(SPIFlash_Device_t const *flash_devs,
                              size_t count) {
  bool ret = Adafruit_SPIFlashBase::begin(flash_devs, count);

  // Use cache if not FRAM
  if (_flash_dev && !_flash_dev->is_fram) {
    // new cache object if not already
    if (!_cache) {
      _cache = new Adafruit_FlashCache();
    }
  }

  return ret;
}

```

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [January 13, 2022, 3:52pm UTC](https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664/4 "2022-01-13T15:52:46Z")

</div>

> [@1337ralfy](#):
>
> `#define CUSTOM_CS 34`

I know the single core ESP32S has 2 more GPIO pins but the GPIO ports on the 32S correspond to the ESP32's GPIO API.

The ESP32 has 2 32 bit GPIO ports. The pins below GPIO\_NUM\_33 are on port A and are designed for general I/O. GPIO\_NUM\_33 and above are on portB do not have pullups are tuned to match the A:D converter 0 and are input only.

[GPIO & RTC GPIO - ESP32 - — ESP-IDF Programming Guide latest documentation (espressif.com)](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html)

I can use the GPIO pins on portB as normal GPIO pins by using the RTC API. You might be able to do the same if you require portB pins as outputs.

You might use a different GPIO pin for the CS pin. One on portB.

---

<div class="post-metadata">

**Author:** ![1337ralfy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/1337ralfy/32/542899_2.png) [@1337ralfy](https://forum.arduino.cc/u/1337ralfy)\
**Post date:** [January 13, 2022, 6:01pm UTC](https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664/5 "2022-01-13T18:01:23Z")

</div>

Tried many other pins, but with no luck, still esp is resetting - Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [January 13, 2022, 7:09pm UTC](https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664/6 "2022-01-13T19:09:20Z")

</div>

I guess the Guru meditation error is a secret.

I guess you've installed into the Arduino IDE the ESP Exception Decoder and posted the results?

---

<div class="post-metadata">

**Author:** ![1337ralfy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/1337ralfy/32/542899_2.png) [@1337ralfy](https://forum.arduino.cc/u/1337ralfy)\
**Post date:** [January 13, 2022, 9:34pm UTC](https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664/7 "2022-01-13T21:34:26Z")

</div>

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

```cpp
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

Also tried that code on ESP32-WROVER-IE, and does the same thing - 1 core paniced, and also does not decode backtrace ☹

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [January 13, 2022, 10:08pm UTC](https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664/8 "2022-01-13T22:08:36Z")

</div>

I'd take all the info you have provided and go to the Adafruit Github page supporting the Adafruit SPI Flash library. Open a trouble issue. Post your code, post the type and model of ESP32 you are using, post the error message and let them know the Exceptiondecoder fails to decode the error. Be patient and answer the question the programmer asks. It may take a few days but they should either let you know it is not their library or they will fix their library.

What the error means is that something has wrote across one or 2 other memory heaps. Be clear that you have used other GPIO\_Pins.

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [January 13, 2022, 10:12pm UTC](https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664/9 "2022-01-13T22:12:54Z")

</div>

almost forgot. GO back a version or 2 of the library to see if the issue goes away.

---

<div class="post-metadata">

**Author:** ![1337ralfy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/1337ralfy/32/542899_2.png) [@1337ralfy](https://forum.arduino.cc/u/1337ralfy)\
**Post date:** [January 13, 2022, 10:26pm UTC](https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664/10 "2022-01-13T22:26:18Z")

</div>

> [@Idahowalker](#):
>
> Open a trouble issue.

Already done that 🤠

---

<div class="post-metadata">

**Author:** ![1337ralfy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/1337ralfy/32/542899_2.png) [@1337ralfy](https://forum.arduino.cc/u/1337ralfy)\
**Post date:** [January 13, 2022, 10:26pm UTC](https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664/11 "2022-01-13T22:26:40Z")

</div>

> [@Idahowalker](#):
>
> . GO back a version or 2 of the library to see if the issue goes away.

Hmm, ok, will try 🤗  
Update - tried many different verisons, with no luck, and yeah, looks like issue is in Adafruit\_SPIFlash library

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 12, 2022, 10:27pm UTC](https://forum.arduino.cc/t/esp32s2-massstorage-with-external-flash-chip/946664/12 "2022-07-12T22:27:24Z")

</div>

Closed on July 12, 2022, 10:27pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
