2015-03-07 07:10 PM
I need to read the flash, add 1 then flash back to same address, so that I can keep track how many time the user use the device, I use:
~~~~~~~~ FLASH_Unlock(); FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); TimeUse= *(__IO uint32_t*)(0x04FFF3325)+1; if (FLASH_ProgramWord(0x04FFF3325,TimeUse) == FLASH_COMPLETE) { uwAddress = uwAddress + 4; } ~~~~~~~~~ It seems the program can not write anything. Then I try: TimeUse= *(vu uint32_t*)(0x04FFF3325)+1; still the same problem. Why the program can write it? Thanks2015-03-08 06:43 AM
Couple of observations
The address 0x04FFF3325 is not a valid flash address.To write you must enable programming mode.You may write data to an address only once.Incrementing a value in flash is not a good plan.Suggest you erase a whole sector and then write a use flag to an incrementing ADDRESS, and where you need to check the number of usages, counts the number marked.Use OTP if the count is fairly limited.2015-03-09 06:11 PM
Thanks. This problem seems fix now.