cancel
Showing results for 
Search instead for 
Did you mean: 

EEPROM emulation problem in STM32F0

michelemancini2
Associate III
Posted on May 02, 2013 at 14:13

Hi, I try eeprom emulation but I have problem:

I use this function for storage variable:

void write_block_eeprom(uint16_t stato,uint8_t *numberbuff){
uint16_t lsb,i;
uint16_t checksum;
uint8_t msb; 
uint8_t flag; 
uint16_t value;
checksum = 0;
FLASH_Unlock(); 
checksum = 0;
value = 0;
//stato
if(stato){
lsb = 1;
EE_WriteVariable(START_EEPROM_CONTATORE_ADD, lsb);
checksum = 1;
EE_WriteVariable(START_EEPROM_CONTATORE_ADD+1, checksum);
}else{
lsb = 0;
EE_WriteVariable(START_EEPROM_CONTATORE_ADD, lsb);
checksum = 0;
EE_WriteVariable(START_EEPROM_CONTATORE_ADD+1, checksum);
}
//number
flag = 0;
for(i=0;i<20;i++){
lsb = numberbuff[i] & 0x00FF;
if(lsb == 0x00){
flag = 1;
}
if(flag==1){
lsb = 0x0000;
EE_WriteVariable(START_EEPROM_CONTATORE_ADD+1+i, lsb); 
}else{ 
EE_WriteVariable(START_EEPROM_CONTATORE_ADD+1+i, lsb);
}
checksum = checksum + lsb;
} 
//timer
//ore
EE_WriteVariable(START_EEPROM_CONTATORE_ADD+1+20+1, timer.ore);
checksum = checksum + timer.ore; 
//minuti
EE_WriteVariable(START_EEPROM_CONTATORE_ADD+1+20+2, 0x00FF & timer.minuti);
checksum = checksum + timer.minuti; 
//secodni
EE_WriteVariable(START_EEPROM_CONTATORE_ADD+1+20+3, 0x00FF & timer.secondi);
checksum = checksum + timer.secondi; 
//checksum
EE_WriteVariable(START_EEPROM_CONTATORE_ADD+1+20+4, checksum);
FLASH_Lock(); 
}

work very well, but the eeprom emulation work with 2 page, when I repeat this function ''

write_block_eeprom

'' ,

after several

repetition

its

jumps

to the

PAGE1

and

I lose

the data, Is it possible storage

in the same

memory location

?
2 REPLIES 2
Posted on May 02, 2013 at 18:04

Is it possible storage

in the same

memory location

?

 

The smart solution is to put your data in a structure, and manage the flash directly and in a fashion you want.

The EE emulation adds virtualization and journalling which might not work in the way you want. The purpose of using two pages is that you don't get a case where you've erased the memory, but haven't written any content yet.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
emalund
Associate III
Posted on May 03, 2013 at 17:50

never done EEPROM emulation on this chip, but on another chip I realized that someone's problem with EEPROM emulation was that the ''EEPROM emulation memory section'' included a segment partially containing code. Thus when the ''EEPROM emulator'' did its erase, it also erased some code.

Erik