flash_internal: fix erase for any bit write
This commit is contained in:
parent
32948f9e8d
commit
99bf7157b2
|
@ -138,11 +138,12 @@ int32_t flash_internal_write(uint32_t address, const uint8_t *buffer, size_t siz
|
|||
for (uint32_t i = 0; i < size && (address + i) < (page_start + page_size); i += 2) { // verify if no bit needs to be flipped to 1 again
|
||||
if (*(uint16_t*)(buffer + i) != (*(uint16_t*)(address + i))) { // verify if the data to be written is identical to the one already written
|
||||
identical = false;
|
||||
}
|
||||
if ((*(uint16_t*)(buffer + i) & *(uint16_t*)(address + i)) != *(uint16_t*)(buffer + i)) { // check if a bit needs to be flipped from 0 back to 1 (through an erase)
|
||||
erase = true;
|
||||
identical = false; // should already have been set, but I want to be sure
|
||||
break; // no need to check further
|
||||
// in theory writing flash is only about flipping (individual) bits from 1 (erase state) to 0
|
||||
// in practice the micro-controller won't allow to flip individual bits if the whole half-word is erased (set to 0xffff)
|
||||
if (*(uint16_t*)(address + i) != 0xffff) { // flash is not erased
|
||||
erase = true; // we need to erase it for it to be written
|
||||
break; // no need to check further
|
||||
}
|
||||
}
|
||||
}
|
||||
if (identical) { // no data needs to be changed
|
||||
|
|
Loading…
Reference in New Issue