From 87c2d74e1e2d66b49eff20d9a4e83364680a4fb7 Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Mon, 2 Nov 2026 16:26:04 +0100 Subject: [PATCH] feat: optionally reset ext flash before use Our ext flash has a rather peculiar 'feature' in that SPI sometimes locks up when first accessing the ext flash. Resetting the flash chip prior alleviates this problem. This is highly specific and I don't expect this to make it into wolfboot as is, but I'm hopeful we can come to some sort of solution where we don't need to patch every new wolfboot version. --- src/spi_flash.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/spi_flash.c b/src/spi_flash.c index 4a33b364ea..9fd32c447e 100644 --- a/src/spi_flash.c +++ b/src/spi_flash.c @@ -49,8 +49,10 @@ #define BYTE_WRITE 0x02 #define AUTOINC 0xAD #define EWSR 0x50 +#define RSTEN 0x66 #define EBSY 0x70 #define DBSY 0x80 +#define RST 0x99 #ifdef TEST_EXT_FLASH static int test_ext_flash(void); @@ -186,9 +188,28 @@ uint16_t spi_flash_probe(void) int i; spi_init(0,0); wait_busy(); + +#ifdef RESET_EXT_FLASH + /* Reset Flash chip as it doesn't always respond properly to first request */ + spi_cs_on(SPI_CS_PIO_BASE, SPI_CS_FLASH); + spi_write(RSTEN); + notused = spi_read(); + spi_cs_off(SPI_CS_PIO_BASE, SPI_CS_FLASH); + for (i = 0; i < 10; i++); + spi_cs_on(SPI_CS_PIO_BASE, SPI_CS_FLASH); + spi_write(RST); + notused = spi_read(); + spi_cs_off(SPI_CS_PIO_BASE, SPI_CS_FLASH); + for (i = 0; i < 18000; i++); + spi_cs_on(SPI_CS_PIO_BASE, SPI_CS_FLASH); spi_write(MDID); notused = spi_read(); + write_address(0); +#else + notused = spi_read(); +#endif + spi_write(0xFF); manuf = spi_read(); spi_write(0xFF);