Advanced Users can post their questions and comments here for the not so Newbie crowd.

Moderator: eriksl

User avatar
By eriksl
#82692 That is exactly what I'd suggest. Just not by using this ugly construction from Espressif, but simply put strings and other readonly data in flash memory (and keep it there).

I guess I have freed up over 32 kbytes by doing that. If I wouldn't be doing this, development of my image would have ceased years ago ;)

Having said that, Espressif has distributed a piece of example code, where mp3 is decoded into audio (PWM and I2S) and it requires more memory than DRAM available on the ESP8266. They have a suggestion where SPI RAM (not flash) is added.

The RAM chip is soldered piggy back to the SPI flash chip, leaving only the CS line, which is to be connected to GPIO0 IIRC.

If I understand it all correctly, the trick is like this:
- the SPI/HSPI interface is programmed in "combined" mode, where both use the same pins (so you still have all GPIO's available, minus one)
- because for RAM access the HSPI interface is used, it doesn't interfere (greatly) with the SPI interface, used for flash access
- for RAM access, the GPIO0 pin is used as CS; when this is asserted, the SPI RAM will react and the flash chip will remain sleeping, because it's CS is not asserted
- for flash access, the reverse happens
- you can read/write arrays of 64 bytes at a time, not really random access, for but for large chunk data style memory, it may be very well be usable
- also no memory-style access possible (like flash)
- I am not sure if the code that access the SPI RAM must be in IRAM (no flash access) or not, but I am going to find out, I ordered some of these chips.

The ESP32 has an interface to SPI RAM similar as to SPI flash, where you can have random access using memory address interface, BUT I've read there are quite a lot of caveats.

The alternative could also be to start using FRAM memory over IC. I've ordered some of these too, so let's see.
User avatar
By davydnorris
#82701
eriksl wrote:...

If I understand it all correctly, the trick is like this:
- the SPI/HSPI interface is programmed in "combined" mode, where both use the same pins (so you still have all GPIO's available, minus one)
- because for RAM access the HSPI interface is used, it doesn't interfere (greatly) with the SPI interface, used for flash access
- for RAM access, the GPIO0 pin is used as CS; when this is asserted, the SPI RAM will react and the flash chip will remain sleeping, because it's CS is not asserted
- for flash access, the reverse happens
- you can read/write arrays of 64 bytes at a time, not really random access, for but for large chunk data style memory, it may be very well be usable

...


I have had to use this same approach for SPI to an SD card reader - this is because the I2S input pins are multiplexed with the 'standard' SPI pins. You lose one GPIO which becomes the CS as you mentioned but you can overlap up to 3 SPI devices on the same pins as the flash.

The huge problem I have is that I moved to the official Espressif WROOM02 modules because they have by far the greatest set of RF certifications, but they don't expose the SPI pins attached to the flash :-(

The AIThinker ESP12-x series do, and they have some certifications, but nowhere near as many as Espressif, which means my post production costs go up a lot.
User avatar
By eriksl
#82704 That's a shame indeed.

So you're saying here that you actually got it working? I'll come back to you when I'm going to experiment :-) Do you know if the code that accesses the ram must be in iram or not? IIRC the example from Espressif had the code in flash, not iram.

The "three devices" is a limitation of the HSPI interface, right, the amount of CS lines that can be configured.

I think if you make your own SPI implementation (bit bang, which shouldn't be too hard, but won't nearly be as fast) you'd be able to use A LOT of devices. The major drawback being you need to use your own pins, so you'd loose at least 3 pins.

I've been looking for an I2C to SPI converter, and actually, they do exist. NXP has one. But they're in a TSSOP package and no breakout boards exists, so bummer for me. I already have always I2C pins, so that way I won't loose more pins.
User avatar
By martinayotte
#82713
eriksl wrote:But they're in a TSSOP package and no breakout boards exists, so bummer for me.

There are some https://www.ebay.ca/itm/TSSOP28-SSOP28- ... 4295025103
I've used them to test Dual Uarts SC16S752 before actually design a real PCB with them.