Memory types and uses

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.
Locked
User avatar
PierreDeQuebec
 
Posts: 96
Joined: Sun Jul 25, 2021 3:26 pm

Memory types and uses

Post by PierreDeQuebec »

Hi,

For the Metro M4 Express Airlift Lite microcontroler:

512 KB flash
192 KB RAM
2 MB QSPI flash

In the document "Adafruit Metro M4 Express AirLift (WiFi)", it is written:
When used in Circuit Python, the 2 MB flash acts as storage for all your scripts, libraries and files.
and
In CircuitPython, the QSPI flash is used natively by the interpretter and is read-only to user code, instead the Flash just shows up as the writeable disk drive!
So, I deduce that CircuitPython does not use QSPI flash memory for my dynamic variables (those created by running my code). Currently, my program crashes due to lack of RAM memory. And this, despite having "frozen" several Adafruit modules and some of my project (there are only 112 B left in the Flash memory). I deduce that the RAM memory is used for my dynamic variables and no doubt that my problem of lack of memory comes from there. Yet I only use 0.39 MB of the 2 MB QSPI Flash. Is it possible to use QSPI Flasg memory for dynamic variables in my programs?

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Memory types and uses

Post by User_UMjT7KxnxP8YN8 »

No, it is not possible to use QSPI flash memory for variables. Flash memory must be erased before its contents can be changed, and it is not possible to erase individual memory locations; instead, you would have to save the contents of the page containing the location you want to change, erase the entire page (256 bytes), then rewrite the entire page including the location(s) you wanted to modify. You can do this about 100,000 times before the flash memory no longer works properly.

Instead, focus on reducing your dynamic variable use. Declare variables (especially strings) that don't change as "const", make arrays no larger than they absolutely have to be, pass variables to functions by reference (i.e., by address) rather than by value for a start. You may have to rewrite code to recover RAM; it's usually possible to trade CPU cycles for RAM. For instance, rather than copying data into another buffer at the expense of doubling RAM use, devise a way to work with the data in-place.

User avatar
PierreDeQuebec
 
Posts: 96
Joined: Sun Jul 25, 2021 3:26 pm

Re: Memory types and uses

Post by PierreDeQuebec »

Thanks for your advices. I will follow them.

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”