From e7edf0783e945f4107dcc7f68543ed05e92189a4 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 9 Apr 2025 21:30:17 +1000 Subject: [PATCH] drivers/memory/spiflash: Allow a board/port to configure chip params. This commit allows the user of this driver to dynamically configure the SPI flash chip parameters. For this, enable `MICROPY_HW_SPIFLASH_CHIP_PARAMS` and then set the `mp_spiflash_t::chip_params` element to point to a valid `mp_spiflash_chip_params_t` struct. Signed-off-by: Damien George --- drivers/memory/spiflash.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/memory/spiflash.h b/drivers/memory/spiflash.h index edd7d4933..a22742fc6 100644 --- a/drivers/memory/spiflash.h +++ b/drivers/memory/spiflash.h @@ -29,6 +29,11 @@ #include "drivers/bus/spi.h" #include "drivers/bus/qspi.h" +// Whether to enable dynamic configuration of SPI flash through mp_spiflash_chip_params_t. +#ifndef MICROPY_HW_SPIFLASH_CHIP_PARAMS +#define MICROPY_HW_SPIFLASH_CHIP_PARAMS (0) +#endif + #define MP_SPIFLASH_ERASE_BLOCK_SIZE (4096) // must be a power of 2 enum { @@ -66,8 +71,20 @@ typedef struct _mp_spiflash_config_t { #endif } mp_spiflash_config_t; +#if MICROPY_HW_SPIFLASH_CHIP_PARAMS +typedef struct _mp_spiflash_chip_params_t { + uint32_t jedec_id; + uint8_t memory_size_bytes_log2; + uint8_t qspi_prescaler; + uint8_t qread_num_dummy; +} mp_spiflash_chip_params_t; +#endif + typedef struct _mp_spiflash_t { const mp_spiflash_config_t *config; + #if MICROPY_HW_SPIFLASH_CHIP_PARAMS + const mp_spiflash_chip_params_t *chip_params; + #endif volatile uint32_t flags; } mp_spiflash_t;