Accessing the flash memory on Feather RP2040

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
georgemichael2000
 
Posts: 36
Joined: Fri Jan 12, 2024 1:55 pm

Accessing the flash memory on Feather RP2040

Post by georgemichael2000 »

I am trying to access the flash memory on Feather RP2040. I am using Arduino, not Python. Can't use Python as it's too slow for the application I need. Not a single example works. SDfat_format's f_mkfs executes without error, but then when it goes back to actually mount the filesystem, calls fatfs.begin() it fails with "can't mount new filesystem". Of course none of the examples are written for the 2040, only for M0, whatever that is.

So I am naturally wondering, what's the trick here? Has anyone been able to successfully use the onboard flash memory on the Feather RP2040?

Also, something of note, is that when I ask for flash chip ID and size, it returns ID and size, but the size is half of what the built-in flash is supposed to be. flash.size()/1024 returns 3906, so about 4Mb, nowhere near the supposedly included 8Mb. Does that have something to do with the problems? Or is this not related?

User avatar
mikeysklar
 
Posts: 15471
Joined: Mon Aug 01, 2016 8:10 pm

Re: Accessing the flash memory on Feather RP2040

Post by mikeysklar »

Are you using the Adafruit_SPIFlash/examples?

Start with flash_info.ino.

This built and ran on a Feather RP2040 for me identifying the flash which is the first step.

Code: Select all

11:34:41.803 -> Adafruit Serial Flash Info example
11:34:41.803 -> JEDEC ID: 0xADAF00
11:34:41.803 -> Flash size: 0 KB

User avatar
georgemichael2000
 
Posts: 36
Joined: Fri Jan 12, 2024 1:55 pm

Re: Accessing the flash memory on Feather RP2040

Post by georgemichael2000 »

Okay. I just run that, for what it's worth. It tells me that there is a flash memory chip. And its size is 0 KB. Like I said, other sketches show that there's 4MB or so. Also the JEDEC ID is different in different sketches.

Code: Select all

Adafruit Serial Flash Info example
JEDEC ID: 0xADAF00
Flash size: 0 KB
I have also tried commenting out "include "flash_config.h" and simply using the Adafruit_FlashTransport_RP2040 definition. Same result.

When I instead use this definition:

Code: Select all

// for flashTransport definition
//#include "flash_config.h"

Adafruit_FlashTransport_SPI flashTransport(SS, &SPI);
Adafruit_SPIFlash flash(&flashTransport);
I get a different answer:

Code: Select all

Adafruit Serial Flash Info example
JEDEC ID: 0x3D0000
Flash size: 3906 KB

User avatar
georgemichael2000
 
Posts: 36
Joined: Fri Jan 12, 2024 1:55 pm

Re: Accessing the flash memory on Feather RP2040

Post by georgemichael2000 »

mikeysklar wrote: Sun Jul 07, 2024 2:29 pm Are you using the Adafruit_SPIFlash/examples?

Start with flash_info.ino.

This built and ran on a Feather RP2040 for me identifying the flash which is the first step.

Code: Select all

11:34:41.803 -> Adafruit Serial Flash Info example
11:34:41.803 -> JEDEC ID: 0xADAF00
11:34:41.803 -> Flash size: 0 KB
All right. So both of us are getting the same exact insane answer. What's next?

User avatar
mikeysklar
 
Posts: 15471
Joined: Mon Aug 01, 2016 8:10 pm

Re: Accessing the flash memory on Feather RP2040

Post by mikeysklar »

I'm also having trouble with the SPIFlash/examples. The code compiles, but there are various problems with formatting, mounting and reporting flash size.

Here is my setup:
Feather RP2040
Arduino IDE 2.3.2
PhilHower Core BSP 3.9.3
Adafruit_SPIFlash 4.3.4

Adafruit_SPIFlash/SdFat_format example ::

Code: Select all

18:07:23.230 -> Adafruit SPI Flash FatFs Format Example
18:07:23.230 -> Flash chip JEDEC ID: 0xADAF00
18:07:23.230 -> Flash size: 0 KB
18:07:23.230 -> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
18:07:23.230 -> This sketch will ERASE ALL DATA on the flash chip and format it with a new filesystem!
18:07:23.230 -> Type OK (all caps) and press enter to continue.
18:07:23.230 -> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
18:07:26.205 -> Creating and formatting FAT filesystem (this takes ~60 seconds)...
18:07:26.205 -> Error, f_mkfs failed with error code: 14
I'll keep looking into this as there has been various RP2040 support additions for the last two years.

User avatar
mikeysklar
 
Posts: 15471
Joined: Mon Aug 01, 2016 8:10 pm

Re: Accessing the flash memory on Feather RP2040

Post by mikeysklar »

I think I have it worked out with the Feather RP2040 and Adafruit_SPIFlash.

The Arduino IDE has a:

Code: Select all

Tools --> Flash Size
Screenshot 2024-07-09 at 4.55.45 PM.png
Screenshot 2024-07-09 at 4.55.45 PM.png (235.73 KiB) Viewed 32 times

After selecting a value form the above menu then running the flash_info script you can see the selected value reported back for flash size being correct. I ran two different configurations here given the sketch code 1MB and 2MB and leaving the remainders as flash filesystems. You can see the results.

Code: Select all

16:53:22.033 -> Adafruit Serial Flash Info example
16:53:22.033 -> JEDEC ID: 0xADAF00
16:53:22.033 -> Flash size: 7168 KB
16:55:16.216 -> Adafruit Serial Flash Info example
16:55:16.216 -> JEDEC ID: 0xADAF00
16:55:16.216 -> Flash size: 6144 KB
Whichever configuration you select you will likely need to select it again to get the other Adafruit_SPIFlash examples to run.

eg.

flash_speedtest.ino:

Code: Select all

17:01:54.125 -> Adafruit Serial Flash Speed Test example
17:01:54.125 -> JEDEC ID: ADAF00
17:01:54.125 -> Flash size: 6291456
17:01:54.125 -> Erase chip
17:01:56.362 -> Write flash with 0xAA
17:02:18.380 -> Write 6291456 bytes in 21.99 seconds.
17:02:18.380 -> Speed: 286.16 KB/s.
17:02:18.380 -> 
17:02:18.380 -> Read flash and compare
17:02:20.850 -> Read  6291456 bytes in 1.86 seconds.
17:02:20.850 -> Speed: 3378.87 KB/s.
17:02:20.850 -> 
17:02:20.850 -> Erase chip
If you want to write files.

SdFat_format.ino - which prompts for an OK to format the flash space

then use the datalogger example to get going.

SdFat_datalogger.ino

Code: Select all

 17:12:17.265 -> Adafruit SPI Flash FatFs Simple Datalogging Example
17:12:17.265 -> Flash chip JEDEC ID: 0xADAF00
17:12:17.265 -> Mounted filesystem!
17:12:17.265 -> Logging data every 60 seconds...
17:12:17.431 -> Wrote new measurement to data file!
17:12:17.431 -> Trying again in 60 seconds...

User avatar
hathach
 
Posts: 1278
Joined: Tue Apr 23, 2013 1:02 am

Re: Accessing the flash memory on Feather RP2040

Post by hathach »

right, you need to select Flash layout code + filesystem) in the Menu Tool->Flash Size. It is mentioned in the flash_config.h , though admittedly it is not a best place for documentation

Code: Select all

#elif defined(ARDUINO_ARCH_RP2040)
// RP2040 use same flash device that store code for file system. Therefore we
// only need to specify start address and size (no need SPI or SS)
// By default (start=0, size=0), values that match file system setting in
// 'Tools->Flash Size' menu selection will be used.
Adafruit_FlashTransport_RP2040 flashTransport;

User avatar
mikeysklar
 
Posts: 15471
Joined: Mon Aug 01, 2016 8:10 pm

Re: Accessing the flash memory on Feather RP2040

Post by mikeysklar »

I came across the same comments in the mini-gif code which is using the SPIFlash library with an RP2040. I had been looking at that guide since it was the only example I had remembered with this configuration.

Would it make sense to have a dedicated guide about using filesystems on flash? Highlighting the minor configuration differences between chips and different hardware options to consider.

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”