Skip to main content
Strooom
Senior
June 11, 2026
Question

EEPROM Emulation number of variables

  • June 11, 2026
  • 4 replies
  • 108 views

I am using the EEPROM emulation (X-CUBE-EEPROM) on a STM32C0.

The default setting for number of variables is 100 : In eeprom_emul_conf.h : 

#define NB_OF_VARIABLES         100U  /*!< Number of variables to handle in eeprom */

If I understand this emulation correctly, it uses a number of 2K flash pages (minimum 2 for alternating...).

Also, each (32bit) variable is stored as 8 bytes : 16bit virtual address, 32bit data, 16bit CRC.

I understood there is also some header overhead of 32 bytes per 2K page.

So the number of variables fitting in a single page is (2048 - 32) / 8 = 252

So my question is then : why is the default value set to 100 io. 252 ???

4 replies

Chloe Meunier
ST Employee
June 12, 2026

Hello,

 

this is an example. 100 is a number given as example, you can choose which number of variables you want to store.

If you need more examples you can refer to the app note related to eeprom emulation.

BR

 

Strooom
StrooomAuthor
Senior
June 12, 2026

Yes, it's the Appliction Note that mentions a default of 100 for STM32C0.

I like to understand why it's not default 252, because I think this allows more variables while not consuming any more flash. 


​​​​​

 

Strooom
StrooomAuthor
Senior
June 12, 2026

From the application note, I understand that 252 variables is the maximum for 2+2K flash, but also that it's better to not fill it up completely. If you fill it up completely with 252 variables, every change on any of the variables, requires the whole page to be rewritten in the the other flash page, so consuming a erase/write cycle per single change.

If you store eg 126 variables, you can change all of them before the page is full and needs a rewrite.

I've also found that the NM_OF_VARIABLES setting, controls a loop in the eeprom emulation library, but it's not yet 100% clear to me what is the effect. 

Thank you ​@Chloe Meunier for your help.

Florian LR
ST Employee
August 24, 2026

Hi ​@Strooom

 

Yes it’s correct, if you use the full amount of data that can be contain in a single page and that you are writing each of these, you’re falling in this case you’re describing. That is also why there is a guard pages mechanism, to prevent this full page transfer each time a variable is updated, allowing to have extra pages without needing to change your “true” variables number. 

I hope this will help you, 

Best Regards, 

Florian LR