chore(spiflash): improve the efficiency of "is block erased" detection (#7582)
This commit is contained in:
@@ -270,8 +270,10 @@ uint32_t flashSpiGetSize()
|
|||||||
|
|
||||||
bool flashSpiIsErased(uint32_t address)
|
bool flashSpiIsErased(uint32_t address)
|
||||||
{
|
{
|
||||||
// verify sector alignment
|
static uint8_t temp_buffer[FLASH_SECTOR_SIZE] __DMA_NO_CACHE;
|
||||||
if((address & FLASH_SECTOR_MASK) != 0)
|
|
||||||
|
// Verify sector alignment
|
||||||
|
if ((address & FLASH_SECTOR_MASK) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
flash_wait_for_not_busy();
|
flash_wait_for_not_busy();
|
||||||
@@ -283,17 +285,25 @@ bool flashSpiIsErased(uint32_t address)
|
|||||||
flash_put_cmd_addr(FLASH_CMD_READ, address);
|
flash_put_cmd_addr(FLASH_CMD_READ, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ret = true;
|
// Check first 4 bytes
|
||||||
for(uint32_t i = 0; i < FLASH_SECTOR_SIZE; i++) {
|
for (uint32_t i = 0; i < 4; i++) {
|
||||||
uint8_t byte = flash_rw_byte(0xFF);
|
if (flash_rw_byte(0xFF) != 0xff) {
|
||||||
if (byte != 0xff) {
|
flash_unselect();
|
||||||
ret = false;
|
return false;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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();
|
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)
|
uint32_t flashSpiRead(uint32_t address, uint8_t* data, uint32_t size)
|
||||||
|
|||||||
Reference in New Issue
Block a user