chore(spiflash): improve the efficiency of "is block erased" detection (#7582)

This commit is contained in:
richardclli
2026-08-11 08:12:23 +10:00
committed by GitHub
parent bc9903c8d2
commit 2848cc1cae
@@ -270,8 +270,10 @@ uint32_t flashSpiGetSize()
bool flashSpiIsErased(uint32_t address)
{
// verify sector alignment
if((address & FLASH_SECTOR_MASK) != 0)
static uint8_t temp_buffer[FLASH_SECTOR_SIZE] __DMA_NO_CACHE;
// Verify sector alignment
if ((address & FLASH_SECTOR_MASK) != 0)
return false;
flash_wait_for_not_busy();
@@ -283,17 +285,25 @@ bool flashSpiIsErased(uint32_t address)
flash_put_cmd_addr(FLASH_CMD_READ, address);
}
bool ret = true;
for(uint32_t i = 0; i < FLASH_SECTOR_SIZE; i++) {
uint8_t byte = flash_rw_byte(0xFF);
if (byte != 0xff) {
ret = false;
break;
// Check first 4 bytes
for (uint32_t i = 0; i < 4; i++) {
if (flash_rw_byte(0xFF) != 0xff) {
flash_unselect();
return false;
}
}
// First 4 bytes all 0xFF, now need to check the remaining using DMA
flash_dma_read_bytes(temp_buffer, FLASH_SECTOR_SIZE - 4);
flash_unselect();
return ret;
for (uint32_t i = 0; i < FLASH_SECTOR_SIZE - 4; i++) {
if (temp_buffer[i] != 0xff) {
return false;
}
}
return true;
}
uint32_t flashSpiRead(uint32_t address, uint8_t* data, uint32_t size)