Skip to content

Commit 626d6c9

Browse files
committed
stm32/storage: Introduce MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE cfg.
This config variable controls whether to support storage on the internal flash of the MCU. It is enabled by default and should be explicitly disabled by boards that don't want internal flash storage.
1 parent d1c4bd6 commit 626d6c9

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

ports/stm32/flashbdev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "flash.h"
3535
#include "storage.h"
3636

37-
#if !defined(MICROPY_HW_SPIFLASH_SIZE_BITS)
37+
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
3838

3939
// Here we try to automatically configure the location and size of the flash
4040
// pages to use for the internal storage. We also configure the location of the
@@ -265,4 +265,4 @@ bool flash_bdev_writeblock(const uint8_t *src, uint32_t block) {
265265
return true;
266266
}
267267

268-
#endif // !defined(MICROPY_HW_SPIFLASH_SIZE_BITS)
268+
#endif // MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE

ports/stm32/mpconfigboard_common.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
/*****************************************************************************/
3333
// Feature settings with defaults
3434

35+
// Whether to enable storage on the internal flash of the MCU
36+
#ifndef MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
37+
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (1)
38+
#endif
39+
3540
// Whether to enable the RTC, exposed as pyb.RTC
3641
#ifndef MICROPY_HW_ENABLE_RTC
3742
#define MICROPY_HW_ENABLE_RTC (0)
@@ -136,6 +141,13 @@
136141
#error Unsupported MCU series
137142
#endif
138143

144+
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
145+
// Provide block device macros if internal flash storage is enabled
146+
#define MICROPY_HW_BDEV_IOCTL flash_bdev_ioctl
147+
#define MICROPY_HW_BDEV_READBLOCK flash_bdev_readblock
148+
#define MICROPY_HW_BDEV_WRITEBLOCK flash_bdev_writeblock
149+
#endif
150+
139151
// Enable hardware I2C if there are any peripherals defined
140152
#if defined(MICROPY_HW_I2C1_SCL) || defined(MICROPY_HW_I2C2_SCL) \
141153
|| defined(MICROPY_HW_I2C3_SCL) || defined(MICROPY_HW_I2C4_SCL)

ports/stm32/storage.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@
3434
#include "storage.h"
3535
#include "irq.h"
3636

37-
#if !defined(MICROPY_HW_SPIFLASH_SIZE_BITS)
38-
39-
// Use internal flash as the storage medium
40-
#define MICROPY_HW_BDEV_IOCTL flash_bdev_ioctl
41-
#define MICROPY_HW_BDEV_READBLOCK flash_bdev_readblock
42-
#define MICROPY_HW_BDEV_WRITEBLOCK flash_bdev_writeblock
43-
44-
#endif
45-
4637
#define FLASH_PART1_START_BLOCK (0x100)
4738

4839
static bool storage_is_initialised = false;

0 commit comments

Comments
 (0)