AnsweredAssumed Answered

Trouble with internal flash, EEPROM emulation

Question asked by petrulis.darius on Oct 18, 2016
Latest reply on Oct 18, 2016 by petrulis.darius
Hello,
i have problem with eeprom, then i erasing eeprom (writing 0 or any other values) then everything is working without problem , later then i write 0 then everything is working fine, but if i write other value then i got error 2, please help,
i am suing STM32F103RB
i provided test code:

#include <EEPROM.h>
byte ReadStatus ;
uint32 as;
 int as1 = 0;
void setup() {
  Serial.begin(115200);
  delay(5000);
  uint32 *mem = (uint32 *)0x08019000 + 1010;
  as = *mem & 0xFFFF;
  if (as != 0) { // if value is not zero then erase memory
    FLASH_Unlock();
    for (int i = 0 ; i < 2040 ; i++ ) {
      ReadStatus = FLASH_ProgramHalfWord(0x08019000 + (i * 4), 0);
      Serial.println(ReadStatus);
    }
    FLASH_Lock();
  }

  for (int i = 0 ; i < 2040 ; i++ ) {  // debug - check erased memory
    uint32 *mem = (uint32 *)0x08019000 + i;
    as = *mem & 0xFFFF;
    Serial.print(*mem); Serial.print("-"); Serial.println(as);
    delay(1);
  }
  delay(5000);
}

void loop() {
  ReadStatus = FLASH_WaitForLastOperation(1000);
  Serial.print(String(ReadStatus)); Serial.print("-");
  FLASH_Unlock();
  ReadStatus = FLASH_ProgramHalfWord(0x08019000 + 4, as1); // there i got error code 2
  FLASH_Lock();
  Serial.print(String(ReadStatus)); Serial.println("-");
  as1++;
  delay(5000);
}

Outcomes