Skip to content

Commit e8b4b3a

Browse files
committed
samd: Harmonize the flash driver interfaces.
- Move the block device API out of samd_flash.c - Rename the internal functions and objects to ...samd_mcuflash_.... - Use the internal flash for the file system only if no external flash is defined. - Change _boot.py accordingly. - Set the respective flag in mpconfigboard.h where needed. Saves about 300 bytes of code.
1 parent c7afb1d commit e8b4b3a

File tree

6 files changed

+170
-203
lines changed

6 files changed

+170
-203
lines changed

ports/samd/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ SRC_C += \
100100
mphalport.c \
101101
pendsv.c \
102102
pin_af.c \
103-
samd_flash.c \
104103
samd_isr.c \
104+
samd_mcuflash.c \
105105
samd_qspiflash.c \
106106
samd_soc.c \
107107
spiflash.c \

ports/samd/modsamd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "pin_af.h"
3333
#include "samd_soc.h"
3434

35-
extern const mp_obj_type_t samd_flash_type;
35+
extern const mp_obj_type_t samd_mcuflash_type;
3636
#ifdef MICROPY_HW_QSPIFLASH
3737
extern const mp_obj_type_t samd_qspiflash_type;
3838
#endif
@@ -76,8 +76,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(samd_pininfo_obj, samd_pininfo);
7676

7777
STATIC const mp_rom_map_elem_t samd_module_globals_table[] = {
7878
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_samd) },
79-
{ MP_ROM_QSTR(MP_QSTR_Flash), MP_ROM_PTR(&samd_flash_type) },
8079
{ MP_ROM_QSTR(MP_QSTR_pininfo), MP_ROM_PTR(&samd_pininfo_obj) },
80+
#if MICROPY_HW_MCUFLASH
81+
{ MP_ROM_QSTR(MP_QSTR_MCUflash), MP_ROM_PTR(&samd_mcuflash_type) },
82+
#endif
8183
#ifdef MICROPY_HW_QSPIFLASH
8284
{ MP_ROM_QSTR(MP_QSTR_QSPIflash), MP_ROM_PTR(&samd_qspiflash_type) },
8385
#endif

ports/samd/modules/_boot.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,25 @@
2020
progsize = 256
2121
flashfs = True
2222
del SPI, Pin, spi
23+
elif hasattr(samd, "MCUflash"):
24+
bdev = FlashBdev(samd.MCUflash())
25+
progsize = 32 # which is the default
26+
flashfs = True
2327
except:
2428
pass
2529

26-
if not flashfs:
27-
bdev = FlashBdev(samd.MCUflash())
28-
progsize = 32 # which is the default
2930

3031
# Try to mount the filesystem, and format the flash if it doesn't exist.
31-
fs_type = uos.VfsLfs2 if hasattr(uos, "VfsLfs2") else uos.VfsLfs1
32+
if flashfs:
33+
fs_type = uos.VfsLfs2 if hasattr(uos, "VfsLfs2") else uos.VfsLfs1
3234

33-
try:
34-
vfs = fs_type(bdev, progsize=progsize)
35-
except:
36-
fs_type.mkfs(bdev, progsize=progsize)
37-
vfs = fs_type(bdev, progsize=progsize)
38-
uos.mount(vfs, "/")
39-
del vfs, fs_type
35+
try:
36+
vfs = fs_type(bdev, progsize=progsize)
37+
except:
38+
fs_type.mkfs(bdev, progsize=progsize)
39+
vfs = fs_type(bdev, progsize=progsize)
40+
uos.mount(vfs, "/")
41+
del vfs, fs_type, progsize, bdev, flashfs
4042

43+
del uos, gc, samd, FlashBdev
4144
gc.collect()
42-
del uos, gc, samd, progsize, bdev, FlashBdev, flashfs

ports/samd/mpconfigport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@
109109

110110
#define MP_STATE_PORT MP_STATE_VM
111111

112+
// Use internal flash for the file system if external flash is not used for it.
113+
#if !defined(MICROPY_HW_QSPIFLASH) && !(defined(MICROPY_HW_SPIFLASH) && defined(MICROPY_HW_SPIFLASH_ID))
114+
#define MICROPY_HW_MCUFLASH (1)
115+
#endif
116+
112117
// Miscellaneous settings
113118
__attribute__((always_inline)) static inline void enable_irq(uint32_t state) {
114119
__set_PRIMASK(state);

ports/samd/samd_flash.c

Lines changed: 0 additions & 188 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy