summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/memory/spiflash.c12
-rw-r--r--drivers/memory/spiflash.h10
2 files changed, 19 insertions, 3 deletions
diff --git a/drivers/memory/spiflash.c b/drivers/memory/spiflash.c
index 09ab7157b..b4133fe2f 100644
--- a/drivers/memory/spiflash.c
+++ b/drivers/memory/spiflash.c
@@ -31,6 +31,10 @@
#include "py/mphal.h"
#include "drivers/memory/spiflash.h"
+#if defined(CHECK_DEVID)
+#error "CHECK_DEVID no longer supported, use MICROPY_HW_SPIFLASH_DETECT_DEVICE instead"
+#endif
+
#define QSPI_QE_MASK (0x02)
#define USE_WR_DELAY (1)
@@ -198,11 +202,13 @@ void mp_spiflash_init(mp_spiflash_t *self) {
mp_hal_delay_ms(1);
#endif
- #if defined(CHECK_DEVID)
- // Validate device id
+ #if MICROPY_HW_SPIFLASH_DETECT_DEVICE
+ // Attempt to detect SPI flash based on its JEDEC id.
uint32_t devid;
int ret = mp_spiflash_read_cmd(self, CMD_RD_DEVID, 3, &devid);
- if (ret != 0 || devid != CHECK_DEVID) {
+ ret = mp_spiflash_detect(self, ret, devid);
+ if (ret != 0) {
+ // Could not read device id.
mp_spiflash_release_bus(self);
return;
}
diff --git a/drivers/memory/spiflash.h b/drivers/memory/spiflash.h
index a22742fc6..d98047c89 100644
--- a/drivers/memory/spiflash.h
+++ b/drivers/memory/spiflash.h
@@ -34,6 +34,11 @@
#define MICROPY_HW_SPIFLASH_CHIP_PARAMS (0)
#endif
+// Whether to enable detection of SPI flash during initialisation.
+#ifndef MICROPY_HW_SPIFLASH_DETECT_DEVICE
+#define MICROPY_HW_SPIFLASH_DETECT_DEVICE (0)
+#endif
+
#define MP_SPIFLASH_ERASE_BLOCK_SIZE (4096) // must be a power of 2
enum {
@@ -91,6 +96,11 @@ typedef struct _mp_spiflash_t {
void mp_spiflash_init(mp_spiflash_t *self);
void mp_spiflash_deepsleep(mp_spiflash_t *self, int value);
+#if MICROPY_HW_SPIFLASH_DETECT_DEVICE
+// A board/port should define this function to perform actions based on the JEDEC id.
+int mp_spiflash_detect(mp_spiflash_t *spiflash, int ret, uint32_t devid);
+#endif
+
// These functions go direct to the SPI flash device
int mp_spiflash_erase_block(mp_spiflash_t *self, uint32_t addr);
int mp_spiflash_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *dest);