Avoid unnecessary flash sector erases

This commit is contained in:
Armel FAUVEAU committed 2026-07-30 02:56:06 +02:00
1 parent 222448e1ad
commit c9da65117f
2 files changed
+6 -2

No files matched your search

+6 -2
View File
@@ -284,9 +284,13 @@ void PY25Q16_WriteBuffer(uint32_t Address, const void *pBuffer, uint32_t Size, b
if (0 != memcmp(pBuffer, (char *)SectorCache + SecOffset, SecSize))
{
bool Erase = false;
const uint8_t *oldData = SectorCache + SecOffset;
const uint8_t *newData = (const uint8_t *)pBuffer;
for (uint32_t i = 0; i < SecSize; i++)
{
if (0xff != SectorCache[SecOffset + i])
// NOR flash programming can only change bits from 1 to 0.
if ((oldData[i] & newData[i]) != newData[i])
{
Erase = true;
break;
@@ -491,4 +495,4 @@ void DMA1_Channel4_5_6_7_IRQHandler()
TC_Flag = true;
}
}
}
Binary file not shown.