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.
pull/982/head
Dirk Van Haerenborgh 2026-11-02 16:26:04 +01:00 committed by Daniele Lacamera
parent 3df34a3a77
commit be4f4366ce
1 changed files with 21 additions and 0 deletions

View File

@ -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);