HAL_ChibiOS: fixed H7 flash storage

this fixes the flash re-init problem when flash storage fills on
H7. It was caused by rejecting writes where one or more of the 32 byte
chunks was not all 0xff but was equal to the current data. That
happens when writing to the sector header in AP_FlashStorage

it also moves the interrupt disable inside the loop to allow for
other interrupts to run between blocks
This commit is contained in:
Andrew Tridgell 2022-04-05 08:46:57 +10:00 committed by Randy Mackay
parent e1c74ee6e5
commit e50f893a7e
1 changed files with 26 additions and 20 deletions

View File

@ -546,28 +546,37 @@ static bool stm32_flash_write_h7(uint32_t addr, const void *buf, uint32_t count)
return false;
}
// check for erasure
if (!stm32h7_check_all_ones(addr, count >> 2)) {
return false;
}
#if STM32_FLASH_DISABLE_ISR
syssts_t sts = chSysGetStatusAndLockX();
#endif
stm32_flash_unlock();
bool success = true;
while (count >= 32) {
if (!stm32h7_flash_write32(addr, b)) {
success = false;
goto failed;
}
const uint8_t *b2 = (const uint8_t *)addr;
// if the bytes already match then skip this chunk
if (memcmp(b, b2, 32) != 0) {
// check for erasure
if (!stm32h7_check_all_ones(addr, 8)) {
return false;
}
// check contents
if (memcmp((void*)addr, b, 32) != 0) {
success = false;
goto failed;
#if STM32_FLASH_DISABLE_ISR
syssts_t sts = chSysGetStatusAndLockX();
#endif
bool ok = stm32h7_flash_write32(addr, b);
#if STM32_FLASH_DISABLE_ISR
chSysRestoreStatusX(sts);
#endif
if (!ok) {
success = false;
goto failed;
}
// check contents
if (memcmp((void*)addr, b, 32) != 0) {
success = false;
goto failed;
}
}
addr += 32;
@ -577,9 +586,6 @@ static bool stm32_flash_write_h7(uint32_t addr, const void *buf, uint32_t count)
failed:
stm32_flash_lock();
#if STM32_FLASH_DISABLE_ISR
chSysRestoreStatusX(sts);
#endif
return success;
}