Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stetrx opened this issue Jun 28, 2023 · 1 comment
Assignees
Labels
possible bug Possibly a bug. Needs verification before moving to *bug* status.

Comments

@stetrx
Copy link

stetrx commented Jun 28, 2023

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

@stetrx stetrx added the possible bug Possibly a bug. Needs verification before moving to *bug* status. label Jun 28, 2023
@alexbussiere
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Possibly a bug. Needs verification before moving to *bug* status.
Projects
None yet
Development

No branches or pull requests

3 participants