8000 stm32/storage: Make extended-block-device more configurable. · micropython/micropython@6936f41 · GitHub
[go: up one dir, main page]

Skip to content
.hEHvLI{min-width:0;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}/*!sc*/ .bmcJak{min-width:0;}/*!sc*/ .fyKNMY[data-size="medium"]{color:var(--fgColor-default,var(--color-fg-default,#1F2328));}/*!sc*/ .gUkoLg{-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}/*!sc*/ .dpBUfI{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}/*!sc*/ @media screen and (min-width:544px){.dpBUfI{-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;}}/*!sc*/ @media screen and (min-width:768px){.dpBUfI{-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;}}/*!sc*/ @media screen and (min-width:1012px){.dpBUfI{-webkit-flex-wrap:nowrap;-ms-flex-wrap:nowrap;flex-wrap:nowrap;}}/*!sc*/ .hKWjvQ{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}/*!sc*/ .cvdqJW{width:20px;height:20px;margin-right:8px;margin-top:-1px;margin-left:1px;}/*!sc*/ .dkaFxu{font-weight:600;white-space:nowrap;color:var(--fgColor-default,var(--color-fg-default,#1F2328));}/*!sc*/ .dkaFxu:hover{color:var(--fgColor-default,var(--color-fg-default,#1F2328));-webkit-text-decoration:underline;text-decoration:underline;}/*!sc*/ .irPhWZ{width:60px;}/*!sc*/ .dNbsEP{width:62px;}/*!sc*/ .kHfwUD{width:60px;height:22px;}/*!sc*/ .bHLmSv{position:absolute;inset:0 -2px;cursor:col-resize;background-color:transparent;-webkit-transition-delay:0.1s;transition-delay:0.1s;}/*!sc*/ .bHLmSv:hover{background-color:var(--bgColor-neutral-muted,var(--color-neutral-muted,rgba(175,184,193,0.2)));}/*!sc*/ .hqtbbn{bottom:0 !important;-webkit-clip:rect(1px,1px,1px,1px);clip:rect(1px,1px,1px,1px);-webkit-clip-path:inset(50%);clip-path:inset(50%);height:84px;position:absolute;width:320px;}/*!sc*/ data-styled.g1[id="Box-sc-g0xbh4-0"]{content:"hEHvLI,bmcJak,fyKNMY,gUkoLg,dpBUfI,hKWjvQ,cvdqJW,dkaFxu,irPhWZ,dNbsEP,kHfwUD,bHLmSv,hqtbbn,"}/*!sc*/ .brGdpi{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;-webkit-clip:rect(0,0,0,0);clip:rect(0,0,0,0);white-space:nowrap;border-width:0;}/*!sc*/ data-styled.g4[id="_VisuallyHidden__VisuallyHidden-sc-11jhm7a-0"]{content:"brGdpi,"}/*!sc*/ .jjwhNb{position:relative;display:inline-block;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}/*!sc*/ .jjwhNb::after{position:absolute;z-index:1000000;display:none;padding:0.5em 0.75em;font:normal normal 11px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";-webkit-font-smoothing:subpixel-antialiased;color:var(--tooltip-fgColor,var(--fgColor-onEmphasis,var(--color-fg-on-emphasis,#ffffff)));text-align:center;-webkit-text-decoration:none;text-decoration:none;text-shadow:none;text-transform:none;-webkit-letter-spacing:normal;-moz-letter-spacing:normal;-ms-letter-spacing:normal;letter-spacing:normal;word-wrap:break-word;white-space:pre;pointer-events:none;content:attr(aria-label);background:var(--tooltip-bgColor,var(--bgColor-emphasis,var(--color-neutral-emphasis-plus,#24292f)));border-radius:6px;opacity:0;}/*!sc*/ @-webkit-keyframes tooltip-appear{from{opacity:0;}to{opacity:1;}}/*!sc*/ @keyframes tooltip-appear{from{opacity:0;}to{opacity:1;}}/*!sc*/ .jjwhNb:hover::after,.jjwhNb:active::after,.jjwhNb:focus::after,.jjwhNb:focus-within::after{display:inline-block;-webkit-text-decoration:none;text-decoration:none;-webkit-animation-name:tooltip-appear;animation-name:tooltip-appear;-webkit-animation-duration:0.1s;animation-duration:0.1s;-webkit-animation-fill-mode:forwards;animation-fill-mode:forwards;-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in;-webkit-animation-delay:0s;animation-delay:0s;}/*!sc*/ .jjwhNb.tooltipped-no-delay:hover::after,.jjwhNb.tooltipped-no-delay:active::after,.jjwhNb.tooltipped-no-delay:focus::after,.jjwhNb.tooltipped-no-delay:focus-within::after{-webkit-animation-delay:0s;animation-delay:0s;}/*!sc*/ .jjwhNb.tooltipped-multiline:hover::after,.jjwhNb.tooltipped-multiline:active::after,.jjwhNb.tooltipped-multiline:focus::after,.jjwhNb.tooltipped-multiline:focus-within::after{display:table-cell;}/*!sc*/ .jjwhNb.tooltipped-s::after,.jjwhNb.tooltipped-se::after,.jjwhNb.tooltipped-sw::after{top:100%;right:50%;margin-top:6px;}/*!sc*/ .jjwhNb.tooltipped-se::after{right:auto;left:50%;margin-left:-16px;}/*!sc*/ .jjwhNb.tooltipped-sw::after{margin-right:-16px;}/*!sc*/ .jjwhNb.tooltipped-n::after,.jjwhNb.tooltipped-ne::after,.jjwhNb.tooltipped-nw::after{right:50%;bottom:100%;margin-bottom:6px;}/*!sc*/ .jjwhNb.tooltipped-ne::after{right:auto;left:50%;margin-left:-16px;}/*!sc*/ .jjwhNb.tooltipped-nw::after{margin-right:-16px;}/*!sc*/ .jjwhNb.tooltipped-s::after,.jjwhNb.tooltipped-n::after{-webkit-transform:translateX(50%);-ms-transform:translateX(50%);transform:translateX(50%);}/*!sc*/ .jjwhNb.tooltipped-w::after{right:100%;bottom:50%;margin-right:6px;-webkit-transform:translateY(50%);-ms-transform:translateY(50%);transform:translateY(50%);}/*!sc*/ .jjwhNb.tooltipped-e::after{bottom:50%;left:100%;margin-left:6px;-webkit-transform:translateY(50%);-ms-transform:translateY(50%);transform:translateY(50%);}/*!sc*/ .jjwhNb.tooltipped-multiline::after{width:-webkit-max-content;width:-moz-max-content;width:max-content;max-width:250px;word-wrap:break-word;white-space:pre-line;border-collapse:separate;}/*!sc*/ .jjwhNb.tooltipped-multiline.tooltipped-s::after,.jjwhNb.tooltipped-multiline.tooltipped-n::after{right:auto;left:50%;-webkit-transform:translateX(-50%);-ms-transform:translateX(-50%);transform:translateX(-50%);}/*!sc*/ .jjwhNb.tooltipped-multiline.tooltipped-w::after,.jjwhNb.tooltipped-multiline.tooltipped-e::after{right:100%;}/*!sc*/ .jjwhNb.tooltipped-align-right-2::after{right:0;margin-right:0;}/*!sc*/ .jjwhNb.tooltipped-align-left-2::after{left:0;margin-left:0;}/*!sc*/ data-styled.g5[id="Tooltip__TooltipBase-sc-17tf59c-0"]{content:"jjwhNb,"}/*!sc*/ .irithh{position:relative;overflow:hidden;-webkit-mask-image:radial-gradient(white,black);mask-image:radial-gradient(white,black);background-color:var(--bgColor-neutral-muted,var(--color-neutral-subtle,rgba(234,238,242,0.5)));border-radius:3px;display:block;height:1.2em;width:60px;}/*!sc*/ .irithh::after{-webkit-animation:crVFvv 1.5s infinite linear;animation:crVFvv 1.5s infinite linear;background:linear-gradient(90deg,transparent,var(--bgColor-neutral-muted,var(--color-neutral-subtle,rgba(234,238,242,0.5))),transparent);content:'';position:absolute;-webkit-transform:translateX(-100%);-ms-transform:translateX(-100%);transform:translateX(-100%);bottom:0;left:0;right:0;top:0;}/*!sc*/ .ihfxfT{position:relative;overflow:hidden;-webkit-mask-image:radial-gradient(white,black);mask-image:radial-gradient(white,black);background-color:var(--bgColor-neutral-muted,var(--color-neutral-subtle,rgba(234,238,242,0.5)));border-radius:3px;display:block;height:1.2em;width:62px;}/*!sc*/ .ihfxfT::after{-webkit-animation:crVFvv 1.5s infinite linear;animation:crVFvv 1.5s infinite linear;background:linear-gradient(90deg,transparent,var(--bgColor-neutral-muted,var(--color-neutral-subtle,rgba(234,238,242,0.5))),transparent);content:'';position:absolute;-webkit-transform:translateX(-100%);-ms-transform:translateX(-100%);transform:translateX(-100%);bottom:0;left:0;right:0;top:0;}/*!sc*/ .kRBfod{position:relative;overflow:hidden;-webkit-mask-image:radial-gradient(white,black);mask-image:radial-gradient(white,black);background-color:var(--bgColor-neutral-muted,var(--color-neutral-subtle,rgba(234,238,242,0.5)));border-radius:3px;display:block;height:1.2em;width:60px;height:22px;}/*!sc*/ .kRBfod::after{-webkit-animation:crVFvv 1.5s infinite linear;animation:crVFvv 1.5s infinite linear;background:linear-gradient(90deg,transparent,var(--bgColor-neutral-muted,var(--color-neutral-subtle,rgba(234,238,242,0.5))),transparent);content:'';position:absolute;-webkit-transform:translateX(-100%);-ms-transform:translateX(-100%);transform:translateX(-100%);bottom:0;left:0;right:0;top:0;}/*!sc*/ data-styled.g27[id="LoadingSkeleton-sc-695d630a-0"]{content:"irithh,ihfxfT,kRBfod,"}/*!sc*/ @-webkit-keyframes crVFvv{0%{-webkit-transform:translateX(-100%);-ms-transform:translateX(-100%);transform:translateX(-100%);}50%{-webkit-transform:translateX(100%);-ms-transform:translateX(100%);transform:translateX(100%);}100%{-webkit-transform:translateX(100%);-ms-transform:translateX(100%);transform:translateX(100%);}}/*!sc*/ @keyframes crVFvv{0%{-webkit-transform:translateX(-100%);-ms-transform:translateX(-100%);transform:translateX(-100%);}50%{-webkit-transform:translateX(100%);-ms-transform:translateX(100%);transform:translateX(100%);}100%{-webkit-transform:translateX(100%);-ms-transform:translateX(100%);transform:translateX(100%);}}/*!sc*/ data-styled.g53[id="sc-keyframes-crVFvv"]{content:"crVFvv,"}/*!sc*/

Commit 6936f41

Browse files
committed
stm32/storage: Make extended-block-device more configurable.
A board can now define the following to fully customise the extended block device interface provided by the storage sub-system: - MICROPY_HW_BDEV_BLOCKSIZE_EXT - MICROPY_HW_BDEV_READBLOCKS_EXT - MICROPY_HW_BDEV_WRITEBLOCKS_EXT - MICROPY_HW_BDEV_ERASEBLOCKS_EXT Signed-off-by: Damien George <damien@micropython.org>
1 parent a66bd7a commit 6936f41

File tree

4 files changed

+42
-39
lines changed

4 files changed

+42
-39
lines changed

ports/stm32/flashbdev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ int32_t flash_bdev_ioctl(uint32_t op, uint32_t arg) {
157157
return 0;
158158

159159
case BDEV_IOCTL_NUM_BLOCKS:
160+
// Units are FLASH_BLOCK_SIZE
160161
return FLASH_MEM_SEG1_NUM_BLOCKS + FLASH_MEM_SEG2_NUM_BLOCKS;
161162

162163
case BDEV_IOCTL_IRQ_HANDLER:

ports/stm32/spibdev.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ int32_t spi_bdev_ioctl(spi_bdev_t *bdev, uint32_t op, uint32_t arg) {
5959
}
6060
#endif
6161
return 0;
62-
63-
case BDEV_IOCTL_BLOCK_ERASE: {
64-
uint32_t basepri = raise_irq_pri(IRQ_PRI_FLASH); // prevent cache flushing and USB access
65-
mp_spiflash_erase_block(&bdev->spiflash, arg * MP_SPIFLASH_ERASE_BLOCK_SIZE);
66-
restore_irq_pri(basepri);
67-
return 0;
68-
}
6962
}
7063
return -MP_EINVAL;
7164
}
@@ -108,4 +101,19 @@ int spi_bdev_writeblocks_raw(spi_bdev_t *bdev, const uint8_t *src, uint32_t bloc
108101
return ret;
109102
}
110103

104+
int spi_bdev_eraseblocks_raw(spi_bdev_t *bdev, uint32_t block_num, uint32_t num_bytes) {
105+
int ret = 0;
106+
while (num_bytes >= MP_SPIFLASH_ERASE_BLOCK_SIZE) {
107+
uint32_t basepri = raise_irq_pri(IRQ_PRI_FLASH); // prevent cache flushing and USB access
108+
ret = mp_spiflash_erase_block(&bdev->spiflash, block_num * MP_SPIFLASH_ERASE_BLOCK_SIZE);
109+
restore_irq_pri(basepri);
110+
if (ret) {
111+
break;
112+
}
113+
block_num += 1;
114+
num_bytes -= MP_SPIFLASH_ERASE_BLOCK_SIZE;
115+
}
116+
return ret;
117+
}
118+
111119
#endif

ports/stm32/storage.c

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -234,24 +234,27 @@ int storage_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_bl
234234

235235
#ifdef MICROPY_HW_BDEV_SPIFLASH_EXTENDED
236236
// Board defined an external SPI flash for use with extended block protocol
237-
#define SPIFLASH (MICROPY_HW_BDEV_SPIFLASH_EXTENDED)
238-
#define PYB_FLASH_NATIVE_BLOCK_SIZE (MP_SPIFLASH_ERASE_BLOCK_SIZE)
239-
#define MICROPY_HW_BDEV_READBLOCKS_EXT(dest, bl, off, len) (spi_bdev_readblocks_raw(SPIFLASH, (dest), (bl), (off), (len)))
240-
#define MICROPY_HW_BDEV_WRITEBLOCKS_EXT(dest, bl, off, len) (spi_bdev_writeblocks_raw(SPIFLASH, (dest), (bl), (off), (len)))
237+
#define MICROPY_HW_BDEV_BLOCKSIZE_EXT (MP_SPIFLASH_ERASE_BLOCK_SIZE)
238+
#define MICROPY_HW_BDEV_READBLOCKS_EXT(dest, bl, off, len) \
239+
(spi_bdev_readblocks_raw(MICROPY_HW_BDEV_SPIFLASH_EXTENDED, (dest), (bl), (off), (len)))
240+
#define MICROPY_HW_BDEV_WRITEBLOCKS_EXT(src, bl, off, len) \
241+
(spi_bdev_writeblocks_raw(MICROPY_HW_BDEV_SPIFLASH_EXTENDED, (src), (bl), (off), (len)))
242+
#define MICROPY_HW_BDEV_ERASEBLOCKS_EXT(bl, len) \
243+
(spi_bdev_eraseblocks_raw(MICROPY_HW_BDEV_SPIFLASH_EXTENDED, (bl), (len)))
241244

242245
#elif (MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2) && MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
243246
// Board uses littlefs and internal flash, so enable extended block protocol on internal flash
244-
#define PYB_FLASH_NATIVE_BLOCK_SIZE (FLASH_BLOCK_SIZE)
247+
#define MICROPY_HW_BDEV_BLOCKSIZE_EXT (FLASH_BLOCK_SIZE)
245248
#define MICROPY_HW_BDEV_READBLOCKS_EXT(dest, bl, off, len) (flash_bdev_readblocks_ext((dest), (bl), (off), (len)))
246249
#define MICROPY_HW_BDEV_WRITEBLOCKS_EXT(dest, bl, off, len) (flash_bdev_writeblocks_ext((dest), (bl), (off), (len)))
247250
#endif
248251

249-
#ifndef PYB_FLASH_NATIVE_BLOCK_SIZE
250-
#define PYB_FLASH_NATIVE_BLOCK_SIZE (FLASH_BLOCK_SIZE)
252+
#ifndef MICROPY_HW_BDEV_BLOCKSIZE_EXT
253+
#define MICROPY_HW_BDEV_BLOCKSIZE_EXT (FLASH_BLOCK_SIZE)
251254
#endif
252255

253256
#if defined(MICROPY_HW_BDEV_READBLOCKS_EXT)
254-
// Size of blocks is PYB_FLASH_NATIVE_BLOCK_SIZE
257+
// Size of blocks is MICROPY_HW_BDEV_BLOCKSIZE_EXT
255258
int storage_readblocks_ext(uint8_t *dest, uint32_t block, uint32_t offset, uint32_t len) {
256259
return MICROPY_HW_BDEV_READBLOCKS_EXT(dest, block, offset, len);
257260
}
@@ -261,9 +264,7 @@ typedef struct _pyb_flash_obj_t {
261264
mp_obj_base_t base;
262265
uint32_t start; // in bytes
263266
uint32_t len; // in bytes
264-
#if defined(SPIFLASH)
265267
bool use_native_block_size;
266-
#endif
267268
} pyb_flash_obj_t;
268269

269270
// This Flash object represents the entire available flash, with emulated partition table at start
@@ -299,23 +300,21 @@ STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, siz
299300

300301
pyb_flash_obj_t *self = m_new_obj(pyb_flash_obj_t);
301302
self->base.type = &pyb_flash_type;
302-
#if defined(SPIFLASH)
303303
self->use_native_block_size = false;
304-
#endif
305304

306305
uint32_t bl_len = (storage_get_block_count() - FLASH_PART1_START_BLOCK) * FLASH_BLOCK_SIZE;
307306

308307
mp_int_t start = args[ARG_start].u_int;
309308
if (start == -1) {
310309
start = 0;
311-
} else if (!(0 <= start && start < bl_len && start % PYB_FLASH_NATIVE_BLOCK_SIZE == 0)) {
310+
} else if (!(0 <= start && start < bl_len && start % MICROPY_HW_BDEV_BLOCKSIZE_EXT == 0)) {
312311
mp_raise_ValueError(NULL);
313312
}
314313

315314
mp_int_t len = args[ARG_len].u_int;
316315
if (len == -1) {
317316
len = bl_len - start;
318-
} else if (!(0 < len && start + len <= bl_len && len % PYB_FLASH_NATIVE_BLOCK_SIZE == 0)) {
317+
} else if (!(0 < len && start + len <= bl_len && len % MICROPY_HW_BDEV_BLOCKSIZE_EXT == 0)) {
319318
mp_raise_ValueError(NULL);
320319
}
321320

@@ -340,10 +339,10 @@ STATIC mp_obj_t pyb_flash_readblocks(size_t n_args, const mp_obj_t *args) {
340339
else if (self != &pyb_flash_obj) {
341340
// Extended block read on a sub-section of the flash storage
342341
uint32_t offset = mp_obj_get_int(args[3]);
343-
if ((block_num * PYB_FLASH_NATIVE_BLOCK_SIZE) >= self->len) {
342+
if ((block_num * MICROPY_HW_BDEV_BLOCKSIZE_EXT) >= self->len) {
344343
ret = -MP_EFAULT; // Bad address
345344
} else {
346-
block_num += self->start / PYB_FLASH_NATIVE_BLOCK_SIZE;
345+
block_num += self->start / MICROPY_HW_BDEV_BLOCKSIZE_EXT;
347346
ret = MICROPY_HW_BDEV_READBLOCKS_EXT(bufinfo.buf, block_num, offset, bufinfo.len);
348347
}
349348
}
@@ -367,10 +366,10 @@ STATIC mp_obj_t pyb_flash_writeblocks(size_t n_args, const mp_obj_t *args) {
367366
else if (self != &pyb_flash_obj) {
368367
// Extended block write on a sub-section of the flash storage
369368
uint32_t offset = mp_obj_get_int(args[3]);
370-
if ((block_num * PYB_FLASH_NATIVE_BLOCK_SIZE) >= self->len) {
369+
if ((block_num * MICROPY_HW_BDEV_BLOCKSIZE_EXT) >= self->len) {
371370
ret = -MP_EFAULT; // Bad address
372371
} else {
373-
block_num += self->start / PYB_FLASH_NATIVE_BLOCK_SIZE;
372+
block_num += self->start / MICROPY_HW_BDEV_BLOCKSIZE_EXT;
374373
ret = MICROPY_HW_BDEV_WRITEBLOCKS_EXT(bufinfo.buf, block_num, offset, bufinfo.len);
375374
}
376375
}
@@ -390,11 +389,9 @@ STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_
390389
// Will be using extended block protocol
391390
if (self == &pyb_flash_obj) {
392391
ret = -1;
393-
#if defined(SPIFLASH)
394392
} else {
395-
// Switch to use native block size of SPI flash
393+
// Switch to use native block size of the underlying storage.
396394
self->use_native_block_size = true;
397-
#endif
398395
}
399396
}
400397
return MP_OBJ_NEW_SMALL_INT(ret);
@@ -411,10 +408,8 @@ STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_
411408
if (self == &pyb_flash_obj) {
412409
// Get true size
413410
n = storage_get_block_count();
414-
#if defined(SPIFLASH)
415411
} else if (self->use_native_block_size) {
416-
n = self->len / PYB_FLASH_NATIVE_BLOCK_SIZE;
417-
#endif
412+
n = self->len / MICROPY_HW_BDEV_BLOCKSIZE_EXT;
418413
} else {
419414
n = self->len / FLASH_BLOCK_SIZE;
420415
}
@@ -423,20 +418,19 @@ STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_
423418

424419
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE: {
425420
mp_int_t n = FLASH_BLOCK_SIZE;
426-
#if defined(SPIFLASH)
427421
if (self->use_native_block_size) {
428-
n = PYB_FLASH_NATIVE_BLOCK_SIZE;
422+
n = MICROPY_HW_BDEV_BLOCKSIZE_EXT;
429423
}
430-
#endif
431424
return MP_OBJ_NEW_SMALL_INT(n);
432425
}
433426

434427
case MP_BLOCKDEV_IOCTL_BLOCK_ERASE: {
435428
int ret = 0;
436-
#if defined(SPIFLASH)
429+
#if defined(MICROPY_HW_BDEV_ERASEBLOCKS_EXT)
437430
if (self->use_native_block_size) {
438-
mp_int_t block_num = self->start / PYB_FLASH_NATIVE_BLOCK_SIZE + mp_obj_get_int(arg_in);
439-
ret = spi_bdev_ioctl(SPIFLASH, BDEV_IOCTL_BLOCK_ERASE, block_num);
431+
mp_int_t block_num = self->start / MICROPY_HW_BDEV_BLOCKSIZE_EXT + mp_obj_get_int(arg_in);
432+
433+
ret = MICROPY_HW_BDEV_ERASEBLOCKS_EXT(block_num, MICROPY_HW_BDEV_BLOCKSIZE_EXT);
440434
}
441435
#endif
442436
return MP_OBJ_NEW_SMALL_INT(ret);

ports/stm32/storage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
enum {
3636
BDEV_IOCTL_INIT = 1,
3737
BDEV_IOCTL_SYNC = 3,
38-
BDEV_IOCTL_NUM_BLOCKS = 4,
39-
BDEV_IOCTL_BLOCK_ERASE = 6,
38+
BDEV_IOCTL_NUM_BLOCKS = 4, // units are FLASH_BLOCK_SIZE
4039
BDEV_IOCTL_IRQ_HANDLER = 7,
4140
};
4241

@@ -70,6 +69,7 @@ int spi_bdev_writeblocks(spi_bdev_t *bdev, const uint8_t *src, uint32_t block_nu
7069
// These raw functions bypass the cache and go directly to SPI flash
7170
int spi_bdev_readblocks_raw(spi_bdev_t *bdev, uint8_t *dest, uint32_t block_num, uint32_t block_offset, uint32_t num_bytes);
7271
int spi_bdev_writeblocks_raw(spi_bdev_t *bdev, const uint8_t *src, uint32_t block_num, uint32_t block_offset, uint32_t num_bytes);
72+
int spi_bdev_eraseblocks_raw(spi_bdev_t *bdev, uint32_t block_num, uint32_t num_bytes);
7373

7474
extern const struct _mp_obj_type_t pyb_flash_type;
7575
extern const struct _pyb_flash_obj_t pyb_flash_obj;

0 commit comments

Comments
 (0)
0