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.
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?
My code "cleaned" from example sketch flash_info (Adafruit SPIFlash):
#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:
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:
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;
}
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.
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.