Memory types and uses (2)

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 (2)

Post by PierreDeQuebec »

Hi,

I return to a similar message but this time to better understand the use of the three types of memories on the Metro M4 Airlift Lite.

The result of the CircuitPython compilation gives a UF2 file of ±992,000 bytes. When I switch the Metro M4 to bootloader mode, I see a memory capacity of 1,048,771 bytes. Obviously, it is not about any of the three memory zones listed here below. So where does the UF2 file go?

512 KB flash (?)
192 KB RAM (Python objects created dynamically during the execution of the user's program).
2 MB QSPI flash (user program including its own and Adafruit librairies (*.py, *.mpy))

Well, I guess the UF2 file slips into Flash memory! But which ?

Thanks you

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

Re: Memory types and uses (2)

Post by mikeysklar »

How much space do you see when you look at the mounted CIRCUITPY drive?

The bootloader view might be confusing things as it is creating an artificial filesystem for the computer:
The UF2 bootloader hijacks the USB Mass Storage protocol to communicate with the computer. The bootloader creates what looks like a filesystem to the computer, but when the computer sends "give me a file listing" or "save a file here" messages, the bootloader shuffles things around and saves the data where it wants. Some information might go into the microcontroller's program memory, while other information might be stored on the QSPI Flash chip.
viewtopic.php?p=730176#p730176

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

Re: Memory types and uses (2)

Post by PierreDeQuebec »

How much space do you see when you look at the mounted CIRCUITPY drive?
I use 127,6 KB. My file manager tells me 1.8 MB free out of 2.0 MB. So, no arithmetic problem here.

Regarding the file UF2. At first glance, arithmetic does not work! But with some research, I understood that the UF2 file is composed of a sequence of data blocks of 512 bytes. Each block has exactly the same structure as defined here: https://github.com/Microsoft/uf2#file-format. By examining the UF2 file (1 MB) on my MCU, I note that obviously, a page is defined by 128 bytes (the other 128 are 0x00). So now the arithmetic works because I end up with 512 kB. But what I don't understand: why the UF2 file when I open it from MCU weighs 1MB? There, it did not fit in the flash memory space of 512 kB!

User avatar
adafruit2
 
Posts: 22193
Joined: Fri Mar 11, 2005 7:36 pm

Re: Memory types and uses (2)

Post by adafruit2 »

a 512byte block contains 260 bytes of data, it is 2x the size you expect

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

Re: Memory types and uses (2)

Post by PierreDeQuebec »

Just to end this discussion. I figured out the 512 byte block trick on my PC but the last 260 bytes are showing up as spaces in my file browser. In reality, on my microcontroller, only the first 260 bytes exist. I deduce that the bootloader takes charge of the trick!

Thank

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

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