How much memory does my M01 have?

Continuing the discussion from Colormap plugin is “variant”?:

  1. How much ‘EEPROM’ is there?

  2. How can I store data in it?

  3. How much ‘PROGMEM’ is there?

  4. Where is in-code data not declared as ‘PROGMEM’ stored?

  5. How much memory is available for that?

  6. What memory of the above three (or two) is referred to when my make flash prints:

    • Program: 26518 bytes (92.5% Full)
    • Data: 2045 bytes (79.9% Full)
  7. The numbers seem to indicate a total of about 32KiB. What decides the program/data percentage quota?

1024 bytes.

Currently, by using Arduino’s EEPROM library directly:

https://www.arduino.cc/en/Reference/EEPROM

Well, along with the EEPROMSettings library, if you want to play nice with other EEPROM-using libraries.

I’m working on feature that will make this more convenient, which I hope will be merge-able sometime next week latest.

32k total, minus the bootloader, which is 4k, so 28k.

In SRAM.

2560 bytes of SRAM.

Program is PROGMEM, Data is SRAM.

The architecture is a bit different from x86, where data and code reside in the same area, the AVR stores them separately. Program data (or PROGMEM, or Flash) is executable, persistent, but read-only. Data is read-write, but is neither persistent, nor executable.

So if you have code that you want the MCU to execute, that goes to PROGMEM. If you have data that is read-only, which you don’t want to execute, that can either go to SRAM or PROGMEM. Because there’s more PROGMEM available, larger blocks of read-only data (such as the keymap, or gamma correction tables) are explicitly put into PROGMEM to save SRAM for things that benefit from being read-write-able.

Reading data from PROGMEM is slightly slower than reading from SRAM, and reading from EEPROM is slower than reading from PROGMEM, by the way.

What gets put where, has to be decided manually. When it comes to executable code, you have no option but to use PROGMEM. When it comes to data, you have to decide yourself where to put it, the compiler can’t help you there. So in short, the programmers decide what data goes where.

Hope this helps!

1 Like

And in PROGMEM.xxxxxxxx

Don’t get you! Can you explain?

I know normally we aren’t supposed to write a separate post for saying thanks but such a detailed reply deserves much more than just a :heart: so thank you thank you thank you for that detailed reply! :bouquet::bouquet::bouquet::apple::grapes::clap:

Any static variables defined in the code that are not declared with PROGMEM are stored in SRAM, but they also take up space in Program memory. Since SRAM effectively gets wiped when it loses power, it’s not persistent, so those variables must be copied from Program memory on startup.

3 Likes

Right. That’s what I meant. Although I forgot to mention that this is only true for variables that are being initialized. Their initial values are stored in PROGMEM and then copied to SRAM during program startup.

3 Likes