flash_internal: flash only when data is different

This commit is contained in:
King Kévin 2020-01-04 14:36:13 +01:00
parent f85a3d2439
commit ee0b68e836
1 changed files with 6 additions and 6 deletions

View File

@ -202,16 +202,16 @@ int32_t flash_internal_write(uint32_t address, const uint8_t *buffer, size_t siz
} }
} }
while (size > 0 && address < (page_start + page_size)) { while (size > 0 && address < (page_start + page_size)) {
if (*((uint16_t*)(buffer)) != 0xffff) { // after an erase the bits are set to one, no need to program them if (*((uint16_t*)(buffer)) != *((uint16_t*)(address)) && *((uint16_t*)(buffer)) != 0xffff) { // only program when data is different and bits need to be set
flash_program_half_word(address, *((uint16_t*)(buffer))); flash_program_half_word(address, *((uint16_t*)(buffer))); // program the data
if (flash_get_status_flags() != FLASH_SR_EOP) { // operation went wrong if (flash_get_status_flags() != FLASH_SR_EOP) { // operation went wrong
flash_lock(); // lock back flash to protect it flash_lock(); // lock back flash to protect it
return -10; return -10;
} }
} if (*((uint16_t*)address) != *((uint16_t*)buffer)) { // verify the programmed data is right
if (*((uint16_t*)address) != *((uint16_t*)buffer)) { // verify the programmed data is right flash_lock(); // lock back flash to protect it
flash_lock(); // lock back flash to protect it return -11;
return -11; }
} }
written += 2; written += 2;
buffer += 2; buffer += 2;