2014-10-01 09:24 AM
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(); }}2014-10-01 10:27 AM
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.2014-10-02 12:51 AM
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(); } }