drivers: flash: spi_nor: fix flash busy during init

After a soft-reset of the host controller the flash device is not reset.
This can cause the flash device to still be busy writing or erasing when
the host controller boots and initializes the flash. The often results
in errors and the flash device not being initialized.

This fix polls the status register until the WIP flag is off before
initializing the flash device.

Fixes #51713

Signed-off-by: Gregers Gram Rygg <gregers.gram.rygg@nordicsemi.no>
This commit is contained in:
Gregers Gram Rygg 2022-10-26 16:01:30 +02:00 committed by Carles Cufí
parent f85eafe02c
commit c9e07fc385

View File

@ -1024,8 +1024,16 @@ static int spi_nor_configure(const struct device *dev)
return -ENODEV;
}
/* Might be in DPD if system restarted without power cycle. */
exit_dpd(dev);
/* After a soft-reset the flash might be in DPD or busy writing/erasing.
* Exit DPD and wait until flash is ready.
*/
acquire_device(dev);
rc = spi_nor_rdsr(dev);
if (rc > 0 && (rc & SPI_NOR_WIP_BIT)) {
LOG_WRN("Waiting until flash is ready");
spi_nor_wait_until_ready(dev);
}
release_device(dev);
/* now the spi bus is configured, we can verify SPI
* connectivity by reading the JEDEC ID.