AnsweredAssumed Answered

EEPROM emulation problem in STM32F0

Question asked by Mancini.Michele on May 2, 2013
Latest reply on May 3, 2013 by malund.erik
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?

Outcomes