Teensy 4.1 with QSPI EEPROM

Ausplex

Well-known member
I regularly use Teensy 4.1's with large external SPI EEPROM chips using my own code (no library) driving external SPI pins.

My next project will use the M95P32-IXMNT/E 32 MBIT EEPROM chip that supports standard SPI and also QSPI. I am running short of external pins on the Teensy and I would prefer to mount the EEPROM using the QSPI pads already provided.

Are there library calls available to access the QSPI port directly either in SPI or QSPI mode that I could use to port my code, or has anyone else developed a QSPI EEPROM library?
 
You won't be able to use those pads as a "regular" SPI port. The chip will only be accessible via FlexSPI or by bit-banging the pins. It might work with LittleFS, depending how standard the command set is.
 
QSPI might be too fast. In version 1.60 we default to 105 MHz. Prior versions used 88 MHz.

Quick look at the M95P32 datasheet says 80 MHz maximum.

You'll probably need to edit startup.c in the core library to configure a slower clock speed on FlexSPI2.

Looking at the command table on page 21, this looks pretty similar to all other QSPI flash. I don't understand why they call it "EEPROM". It does have command for erasing smaller chunks of 512 bytes, in addition to the usual 4K and 64K, but there's not single byte functionality like the EEPROM normally means. Maybe I missed something? Admittedly I only spent less than a minute rapidly glancing at the datasheet.

Info on page 38 and 41 looks like M95P32 will respond to the JEDEC ID command with 0x20, 0x00, 0x16. You'll need to edit the known_chips table in LittleFS.cpp to add these 3 bytes and the parameters you want LittleFS to use.

Even if you ultimately want to craft your own code to access this chip directly, I would highly recommend first making these 2 edits and test the chip with LittleFS. The FlexSPI hardware has an extremely steep learning curve. Best to get to a known good working code & hardware first. Then help yourself to the working FlexSPI2 code inside LittleFS.cpp. Just for your own sanity, please take the easy path to get the chip working first before you dive into complex details like the FlexSPI LUTs.
 
Last edited:
Ah, looking at the ST's web page, they call it "Page EEPROM". That's deceptive marketing! It's really just flash memory. Smaller erasable sector size doesn't make it EEPROM.

You'd probably be better off with a normal 256 Mbit serial flash, which would give you the same number of erasable sectors.
 
Thanks for the reply Paul.

I would be happy to use normal flash, but as best I understand it LittleFS is for file handling. I simply want to access several very large arrays of flat data (100K entries each with 8 bytes) that occasionally gets updated.

This is a design update for an existing commercial product. With the Page EEPROM I usually read each page before write and compare to the image held in RAM and only update the page if the page has changed to avoid too much wear on the EEPROM. I need non-volatile storage as the tables need to persist through power cycles.

Is there a better way to communicate with structured array data using QSPI flash on the T4.1 ?

David
 
On Teensy 4.1, access to QSPI is only by the bottom side pads. You can't use QSPI from any of the normal pins. If your M95P32 is already soldered to an existing PCB, not sure how that could possibly work. Maybe I'm not imaging something about how the hardware will get connected?

You can use either of 2 ordinary SPI ports from the normal pins. SPI is much simpler and has a nice library, so that's probably your best path. Raw read speed (ignoring command overhead) is slower, about 30 Mbit/sec versus 400 Mbit/sec. Erase and write speed is about the same, paced by the chip not by the communication. If 30 Mbit/sec is good enough, this way will probably take less of your time. You also don't need to worry about the clock faster than M95P32's maximum spec.

But if you really want to use QSPI, and you're able to connect the chip to the bottom side of Teensy 4.1, the only example code we have is inside LittleFS (ignoring the PSRAM stuff in the core library, which isn't useful for this chip). Even if you never intend to use the chip as a structured filesystem, that's where you'll find working code. There isn't a library specifically for QSPI like there is for SPI. Even with the working code from LittleFS, using FlexSPI (the peripheral inside the chip which implements QSPI) is quite complicated. You probably won't have to change much if you're just reading, erasing and writing blocks. LittleFS has this code, so you won't have to start from nothing. But you will have to dig into LittleFS to get that code which reads, erases, and writes.
 
Paul... thanks for the tips,. Very helpful.

I have a busy T4.1 for this upgraded project and didn't have 4 pins spare to attach an external SPI EEPROM. I've attached a Winbond 128 MBit chip and LittleFS is working like a charm. I'll convert my product to use a file system for this application as it makes sense to not waste time tinkering with QSPI. Just need to manage the timing of how I save the large data files as it appears LittleFS is blocking for about 280uS while updating a flash page and I've got a fairly busy processor already.

Thanks again :)
 
Back
Top