flash_internal: flash only when data is different
This commit is contained in:
parent
f85a3d2439
commit
ee0b68e836
|
@ -202,17 +202,17 @@ int32_t flash_internal_write(uint32_t address, const uint8_t *buffer, size_t siz
|
|||
}
|
||||
}
|
||||
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
|
||||
flash_program_half_word(address, *((uint16_t*)(buffer)));
|
||||
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))); // program the data
|
||||
if (flash_get_status_flags() != FLASH_SR_EOP) { // operation went wrong
|
||||
flash_lock(); // lock back flash to protect it
|
||||
return -10;
|
||||
}
|
||||
}
|
||||
if (*((uint16_t*)address) != *((uint16_t*)buffer)) { // verify the programmed data is right
|
||||
flash_lock(); // lock back flash to protect it
|
||||
return -11;
|
||||
}
|
||||
}
|
||||
written += 2;
|
||||
buffer += 2;
|
||||
address += 2;
|
||||
|
|
Loading…
Reference in New Issue