SPIMemory on ATMEGA32u4 (Leonardo) with Adesto AT25QF128A 16MB only detects 512K

Hello Everyone,

I did quite a bit of digging, and I don’t see that too many folks have used the flashram I picked solely based on capacity and cost from Mouser. The 16 megabyte x 8, Adesto AT25QF128A @ $1.52 ea, not too bad for the size. Fortunately, it seems I may have picked relatively wisely, as it seems to be detected by the SPIMemory library, and even supports SFDP.

I have a PCB I built myself which has an atmega32u4 running the 8MHz 3.3V (have also tried 16MHz too, same result) running the Leonardo bootloader at the moment connected to this chip. The CS pin for memory is on arduino Pin 7 and I am running the built-in diagnostic example program provided with the SPIMemory library. It more or less works, but I see errors on reads and writes sporadically like crazy. I will also mention in full disclosure, I may well have fried this chip. I have on more than one occasion overvolted it to 5V messing around with other problems I had on the board. But, the trooper that it seems to be, it 100% of the time will erase, and it always reads the JEDEC ID, sees it’s SFDP capable etc. My own code works for reads & writes too. I am waiting on a new IC now, and I wouldn’t post here if I didn’t think I was having a library issue. I promise! :slight_smile:

I uncommented the following three settings in SPIMemory.h per the docs:
#define USES_SFDP
#define RUNDIAGNOSTIC
#define DISABLEOVERFLOW

In addition, I would have thought SFDP would read the capacity correctly, and I have even tried to instantiate flash by specifying: flash.begin(MB(16));

That should be a match for this chip. No matter what combination I have tried, I always see this when I run the diag:

Initialising..........
Chip Diagnostics initiated.

SFDP available
Error code: 0x12
Error code: 0x13
Chip identified using sfdp. Most of this chip's functions are supported by the library.
No Chip size defined by user. Checking library support.
Chip identified. This chip is fully supported by the library.

SPIMemory Library version: < 2.5.0

JEDEC ID: 0x1F8901
Man ID: 0x1F
Memory ID: 0x89
Capacity: 524288
Max Pages: 2048
Unique ID: 2395288456731648, 0x234274408D991C00

The two errors thrown from SFDP are here:
#define NOSFDPERASETIME 0x12
#define NOSFDPPROGRAMTIMEPARAM 0x13

Neither of these seem to be a deal breaker, and should pull the capacity just fine. I also forced it to 16MB, but the output always says I didn’t specify it. So I think what may be happening is that there is one Adesto flash IC supported by SPIMemory, and it sees the 0x1F manufacturer ID and says, aha! It’s this chip. That IC so happens to be a 512kb chip, which is what it is detecting. I cannot seem to override this with SFDP nor by forcing the value.
I also wrote a quick bit of code to simply erase the whole chip, then loop from address 0x0-0xFFFFFF. I simply write each byte as 0x00 and immediately read it back to see if it matches. If not, I throw an error to the serial port. It works no problem until it hits 512kb, then throws error 0x05, which is out of bounds. So the lib won’t even try to write past the capacity with DISABLEOVERFLOW enabled it seems.
I didn’t tear through the library too much, as I’m probably not the best to debug something like this. I know technically this is an unsupported chip, but I do think it will work fine based on what I’m seeing.

Is there some other way to force 16MB I’m missing?
Thanks,
-Kevin

Ok, on a whim, I just tried to remove adesto from the supported IC list:
SPIFlash.h was:
const uint8_t _supportedManID[9] = {WINBOND_MANID, MICROCHIP_MANID, CYPRESS_MANID, ADESTO_MANID, MICRON_MANID, ON_MANID, GIGA_MANID, AMIC_MANID, MACRONIX_MANID};

now:
const uint8_t _supportedManID[9] = {WINBOND_MANID, MICROCHIP_MANID, CYPRESS_MANID, MICRON_MANID, ON_MANID, GIGA_MANID, AMIC_MANID, MACRONIX_MANID};

Now it’s working as it should:

SFDP available
Error code: 0x12
Error code: 0x13
Chip identified using sfdp. Most of this chip's functions are supported by the library.
SFDP ID finished.

SPIMemory Library version: < 2.5.0

JEDEC ID: 0x1F8901
Man ID: 0x1F
Memory ID: 0x89
Capacity: 16777216
Max Pages: 65536
Unique ID: 2395288456731648, 0x234274408D991C00
-----------------------------------------------------------------------------------------------------------------------------
                                                        Testing library code
-----------------------------------------------------------------------------------------------------------------------------
                        Function                Test result                          Runtime
-----------------------------------------------------------------------------------------------------------------------------
                        Power Down                 PASS                               80 us
                        Power Up                   PASS                               64 us

                        Erase Chip                 PASS                               2.973 s
                        Erase 72KB                 PASS                               7.82 ms
                        Erase 64KB                 PASS                               7.21 ms
                        Erase 32KB                 PASS                               3.66 ms
                        Erase 4KB                  PASS                               552 us
-----------------------------------------------------------------------------------------------------------------------------
                        Data type               I/O Result            Write time              Read time
-----------------------------------------------------------------------------------------------------------------------------
                        Byte                       PASS                 160 us                  64 us
                        Char                       PASS                 168 us                  72 us
                        Word                       PASS                 176 us                  64 us
                        Short                      PASS                 176 us                  64 us
                        ULong                      PASS                 192 us                  72 us
                        Long                       PASS                 192 us                  72 us
                        Float                      PASS                 192 us                  80 us
                        Struct                     PASS                 320 us                  104 us
                        Byte Array                 PASS                 2.77 ms                 424 us
                        String                     PASS                 624 us                  232 us
-----------------------------------------------------------------------------------------------------------------------------

It looks like any Adesto IC will be detected as the one supported IC and params will be overridden but the library. Also, I tried specifying 8MB on flash start, but SFDP overrides this and sets it to 16MB.

Also, all of the tests now pass 100%. I think before it was picking random values above 512k at times, causing the out of bound errors I was seeing.

Thanks!
-Kevin