cancel
Showing results for 
Search instead for 
Did you mean: 

emulate EEPROM with STM32F407 flash memory

gian0652
Associate
Posted on October 01, 2014 at 18:24

Hi I use the routine listed below to read in flash area (sector 11) three words that contain values ​​of sampling and if the first value found is different, register the new three values. 

The problem is that the values ​​that are written to the flash, do not correspond to the values ​​contained in the variables. In practice in flash are not recorded the correct values 

That 's the Routine:

void ReadDataFromFlash(void)

{

FLASH_Status  FlashStatus; //  flag

uwAddress = AddrFlashDataDDS; // Punto al settore Flash 

uwData32 = *(__IO uint32_t*)uwAddress; // leggo primi 4 bytes 

FlashStatus = FLASH_COMPLETE;

FLASH_Unlock();

FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | 

FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR |         FLASH_FLAG_PGSERR); 

uwAddress = AddrFlashDataDDS; // Punto al settore Flash FlashStatus=FLASH_ProgramWord(uwAddress, wDATA_32);   // scrivo numeri di test.

if (FlashStatus != FLASH_COMPLETE) {}

uwAddress+=4; // secondo word

FlashStatus=FLASH_ProgramWord(uwAddress,wFreqzStartDDS[0]);

if (FlashStatus != FLASH_COMPLETE) {}

uwAddress+=4; // terzo word

FlashStatus=FLASH_ProgramWord(uwAddress,wFreqzStartNominale[0]);

if (FlashStatus != FLASH_COMPLETE) {}

FLASH_Lock(); 

}

}

2 REPLIES 2
Posted on October 01, 2014 at 19:27

Memory must be erased prior to any writing, you get one shot at writing each location.

What values are you writing? What values end up in the memory? What flash status to you get at each step? Instrument this better.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gian0652
Associate
Posted on October 02, 2014 at 09:51

Thanks for the quick reply. The routine before you actually also contained a statement of the erase sector 11 but did not work because the program crashed on that statement and did not go on anymore.

This was the version:

''

void DataFromFlash(void)

{

FLASH_Status  FlashStatus;

FlashStatus = FLASH_COMPLETE;

FLASH_Unlock();

FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR |          FLASH_FLAG_PGSERR); 

uwAddress = AddrFlashDataDDS;

FlashStatus=FLASH_EraseSector(uwAddress, VoltageRange_3);

if (FlashStatus != FLASH_COMPLETE) {}

uwAddress = AddrFlashDataDDS;

FlashStatus=FLASH_ProgramWord(uwAddress, wDATA_32);

if (FlashStatus != FLASH_COMPLETE) {}

uwAddress+=4;

FlashStatus=FLASH_ProgramWord(uwAddress,wFreqzStartDDS[0]);

if (FlashStatus != FLASH_COMPLETE) {}

uwAddress+=4;

FlashStatus=FLASH_ProgramWord(uwAddress,wFreqzStartNominale[0]);

if (FlashStatus != FLASH_COMPLETE) {}

FLASH_Lock(); 

}

}