drivers/memory/spiflash: Add MICROPY_HW_SPIFLASH_ENABLE_CACHE option.

This only needs to be enabled if a board uses FAT FS on external SPI flash.
When disabled (and using external SPI flash) 4k of RAM can be saved.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2020-12-17 16:59:54 +11:00
parent 061cb1a73a
commit e43a74a4db
7 changed files with 27 additions and 0 deletions

View File

@@ -287,6 +287,8 @@ int mp_spiflash_write(mp_spiflash_t *self, uint32_t addr, size_t len, const uint
/******************************************************************************/
// Interface functions that use the cache
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
void mp_spiflash_cached_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *dest) {
if (len == 0) {
return;
@@ -509,3 +511,5 @@ int mp_spiflash_cached_write(mp_spiflash_t *self, uint32_t addr, size_t len, con
mp_spiflash_release_bus(self);
return 0;
}
#endif // MICROPY_HW_SPIFLASH_ENABLE_CACHE

View File

@@ -38,6 +38,7 @@ enum {
struct _mp_spiflash_t;
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
// A cache must be provided by the user in the config struct. The same cache
// struct can be shared by multiple SPI flash instances.
typedef struct _mp_spiflash_cache_t {
@@ -45,6 +46,7 @@ typedef struct _mp_spiflash_cache_t {
struct _mp_spiflash_t *user; // current user of buf, for shared use
uint32_t block; // current block stored in buf; 0xffffffff if invalid
} mp_spiflash_cache_t;
#endif
typedef struct _mp_spiflash_config_t {
uint32_t bus_kind;
@@ -59,7 +61,9 @@ typedef struct _mp_spiflash_config_t {
const mp_qspi_proto_t *proto;
} u_qspi;
} bus;
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
mp_spiflash_cache_t *cache; // can be NULL if cache functions not used
#endif
} mp_spiflash_config_t;
typedef struct _mp_spiflash_t {
@@ -75,9 +79,11 @@ int mp_spiflash_erase_block(mp_spiflash_t *self, uint32_t addr);
void mp_spiflash_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *dest);
int mp_spiflash_write(mp_spiflash_t *self, uint32_t addr, size_t len, const uint8_t *src);
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
// These functions use the cache (which must already be configured)
void mp_spiflash_cache_flush(mp_spiflash_t *self);
void mp_spiflash_cached_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *dest);
int mp_spiflash_cached_write(mp_spiflash_t *self, uint32_t addr, size_t len, const uint8_t *src);
#endif
#endif // MICROPY_INCLUDED_DRIVERS_MEMORY_SPIFLASH_H