Marzogh / SPIMemory

Arduino library for Flash Memory Chips (SPI based only). Formerly SPIFlash
http://spimemory.readthedocs.io/en/latest/
GNU General Public License v3.0
430 stars 136 forks source link

ESP32S3 stops due to SPI_PARAM_LOCK() when calling getUniqueID(). Is it necessary _endSPI()? #252

Open stetrx opened 1 year ago

stetrx commented 1 year ago

Hello, I'm using library to access the W25Q64JV chip. Board used: ESP32-S3 DevKitC-1 Chip Model: ESP32-S3-WROOM-2-N32R8V Esp32 Arduino Core: v.2.0.9 SDK Vers.: v.4.4.3

As long as I connect just W25Q64JV to ESP32S3 through HSPI by using GPIO as follow NOR_CS=14 NOR_MISO=15 NOR_MOSI=16 NOR_CLK=17 there are no problems with code of FlashDiagnostics.ino and #define RUNDIAGNOSTICS uncommented.

But I need to drive also a display by using TFT_eSPI library always through SPI bus. Initially, to proceed step by step, I separated the two devices on two available spi buses (HSPI and VSPI available on ESP32S3) So W25Q64JV as shown above on HSPI, and display on VSPI by using TFT_CS=10 TFT_MOSI=11 TFT_MISO=not used, but GPIO13 is free TFT_SCLK=12 and TFT device works too.

But when I try to make the two devices work together on their respective SPI buses ESP32S3 stops. Display stops to work, serial monitor stops to work and ESP32 seem to be stuck. I found that after calling flash.getUniqueID() the ESP32 stops on SPI.cpp at: void SPIClass::beginTransaction(SPISettings settings) { SPI_PARAM_LOCK(); //<<<ESP32 stops here waiting do {} while (xSemaphoreTake(paramLock, portMAX_DELAY) != pdPASS)

I'm not sure, but by adding _endSPI(); inside getUniqueID(void) ESP32 starts working again and Flash and display works together .

Please see below function uint64_t SPIFlash::getUniqueID(void)

/***/ // Returns a 64-bit Unique ID that is unique to each flash memory chip uint64_t SPIFlash::getUniqueID(void) { if(!_notBusy() || _isChipPoweredDown()) { return false; } _beginSPI(UNIQUEID); for (uint8_t i = 0; i < 4; i++) { _nextByte(WRITE, DUMMYBYTE); } if (address4ByteEnabled) { _nextByte(WRITE, DUMMYBYTE); }

for (uint8_t i = 0; i < 8; i++) { _uniqueID[i] = _nextByte(READ); } CHIP_DESELECT _endSPI(); //<<<ESP32 needs unlock

long long _uid = 0; for (uint8_t i = 0; i < 8; i++) { _uid += _uniqueID[i]; _uid = _uid << 8; } return _uid; } /***/

This behavior does not happen with write and read functions (byte,word,string,...as in the FlashDiagnostics example), but it happens again with powerDownTest and powerUpTest and with erase memory function.

Could this behavior be caused by not calling _endSPI() to unlock semaphore and free SPI bus? What I mean is that i found that in some places of the library it is just called CHIP_DESELECT and not a _endSPI(). _endSPI() calls SPI.endTransaction() where SPI_PARAM_UNLOCK();

I hope I have given you clear and sufficient information to understand my problem. Thank's for your job. Regards

alexbussiere commented 8 months ago

I believe this might be an issue with the latest version of the Espressif Arduino package related to the beginTransaction(). I just ran into this issue with a variety of projects using SPI devices after updating from V5.0.0 to V6.5.0