drivers: flash: stm32: allow to overwrite zeros
On stm32g0, stm32g4, stm32l4, stm32l5, stm32u5, and stm32wbx, it is allowed to write a zeroed dword on unerased flash. Signed-off-by: Cyril Fougeray <cyril.fougeray@worldcoin.org>
This commit is contained in:
parent
5b1dd71f3e
commit
9bc639dd59
5 changed files with 39 additions and 14 deletions
|
@ -86,9 +86,14 @@ static int write_dword(const struct device *dev, off_t offset, uint64_t val)
|
|||
return rc;
|
||||
}
|
||||
|
||||
/* Check if this double word is erased */
|
||||
if (flash[0] != 0xFFFFFFFFUL ||
|
||||
flash[1] != 0xFFFFFFFFUL) {
|
||||
/* Check if this double word is erased and value isn't 0.
|
||||
*
|
||||
* It is allowed to write only zeros over an already written dword
|
||||
* See 3.3.8 in reference manual.
|
||||
*/
|
||||
if ((flash[0] != 0xFFFFFFFFUL ||
|
||||
flash[1] != 0xFFFFFFFFUL) && val != 0UL) {
|
||||
LOG_ERR("Word at offs %ld not erased", (long)offset);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
|
|
@ -92,9 +92,13 @@ static int write_dword(const struct device *dev, off_t offset, uint64_t val)
|
|||
return rc;
|
||||
}
|
||||
|
||||
/* Check if this double word is erased */
|
||||
if (flash[0] != 0xFFFFFFFFUL ||
|
||||
flash[1] != 0xFFFFFFFFUL) {
|
||||
/* Check if this double word is erased and value isn't 0.
|
||||
*
|
||||
* It is allowed to write only zeros over an already written dword
|
||||
* See 3.3.7 in reference manual.
|
||||
*/
|
||||
if ((flash[0] != 0xFFFFFFFFUL ||
|
||||
flash[1] != 0xFFFFFFFFUL) && val != 0UL) {
|
||||
LOG_ERR("Word at offs %ld not erased", (long)offset);
|
||||
return -EIO;
|
||||
}
|
||||
|
|
|
@ -95,9 +95,14 @@ static int write_dword(const struct device *dev, off_t offset, uint64_t val)
|
|||
return rc;
|
||||
}
|
||||
|
||||
/* Check if this double word is erased */
|
||||
if (flash[0] != 0xFFFFFFFFUL ||
|
||||
flash[1] != 0xFFFFFFFFUL) {
|
||||
/* Check if this double word is erased and value isn't 0.
|
||||
*
|
||||
* It is allowed to write only zeros over an already written dword
|
||||
* See 3.3.7 in reference manual.
|
||||
*/
|
||||
if ((flash[0] != 0xFFFFFFFFUL ||
|
||||
flash[1] != 0xFFFFFFFFUL) && val != 0UL) {
|
||||
LOG_ERR("Word at offs %ld not erased", (long)offset);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
|
|
@ -160,8 +160,14 @@ static int write_dword(const struct device *dev, off_t offset, uint64_t val)
|
|||
return rc;
|
||||
}
|
||||
|
||||
/* Check if this double word is erased */
|
||||
if ((flash[0] != 0xFFFFFFFFUL) || (flash[1] != 0xFFFFFFFFUL)) {
|
||||
/* Check if this double word is erased and value isn't 0.
|
||||
*
|
||||
* It is allowed to write only zeros over an already written dword
|
||||
* See 6.3.7 in STM32L5 reference manual.
|
||||
* See 7.3.7 in STM32U5 reference manual.
|
||||
*/
|
||||
if ((flash[0] != 0xFFFFFFFFUL ||
|
||||
flash[1] != 0xFFFFFFFFUL) && val != 0UL) {
|
||||
LOG_ERR("Word at offs %ld not erased", (long)offset);
|
||||
return -EIO;
|
||||
}
|
||||
|
|
|
@ -84,9 +84,14 @@ static int write_dword(const struct device *dev, off_t offset, uint64_t val)
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
/* Check if this double word is erased */
|
||||
if (flash[0] != 0xFFFFFFFFUL ||
|
||||
flash[1] != 0xFFFFFFFFUL) {
|
||||
/* Check if this double word is erased and value isn't 0.
|
||||
*
|
||||
* It is allowed to write only zeros over an already written dword
|
||||
* See 3.3.8 in reference manual.
|
||||
*/
|
||||
if ((flash[0] != 0xFFFFFFFFUL ||
|
||||
flash[1] != 0xFFFFFFFFUL) && val != 0UL) {
|
||||
LOG_ERR("Word at offs %ld not erased", (long)offset);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue