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:
Cyril Fougeray 2022-10-13 12:18:22 +02:00 committed by Carles Cufí
commit 9bc639dd59
5 changed files with 39 additions and 14 deletions

View file

@ -86,9 +86,14 @@ static int write_dword(const struct device *dev, off_t offset, uint64_t val)
return rc; return rc;
} }
/* Check if this double word is erased */ /* Check if this double word is erased and value isn't 0.
if (flash[0] != 0xFFFFFFFFUL || *
flash[1] != 0xFFFFFFFFUL) { * 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; return -EIO;
} }

View file

@ -92,9 +92,13 @@ static int write_dword(const struct device *dev, off_t offset, uint64_t val)
return rc; return rc;
} }
/* Check if this double word is erased */ /* Check if this double word is erased and value isn't 0.
if (flash[0] != 0xFFFFFFFFUL || *
flash[1] != 0xFFFFFFFFUL) { * 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); LOG_ERR("Word at offs %ld not erased", (long)offset);
return -EIO; return -EIO;
} }

View file

@ -95,9 +95,14 @@ static int write_dword(const struct device *dev, off_t offset, uint64_t val)
return rc; return rc;
} }
/* Check if this double word is erased */ /* Check if this double word is erased and value isn't 0.
if (flash[0] != 0xFFFFFFFFUL || *
flash[1] != 0xFFFFFFFFUL) { * 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; return -EIO;
} }

View file

@ -160,8 +160,14 @@ static int write_dword(const struct device *dev, off_t offset, uint64_t val)
return rc; return rc;
} }
/* Check if this double word is erased */ /* Check if this double word is erased and value isn't 0.
if ((flash[0] != 0xFFFFFFFFUL) || (flash[1] != 0xFFFFFFFFUL)) { *
* 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); LOG_ERR("Word at offs %ld not erased", (long)offset);
return -EIO; return -EIO;
} }

View file

@ -84,9 +84,14 @@ static int write_dword(const struct device *dev, off_t offset, uint64_t val)
return -EIO; return -EIO;
} }
/* Check if this double word is erased */ /* Check if this double word is erased and value isn't 0.
if (flash[0] != 0xFFFFFFFFUL || *
flash[1] != 0xFFFFFFFFUL) { * 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; return -EIO;
} }