Skip to content

Commit

Permalink
stm32/main: Catch and report corrupted lfs filesystem at startup.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leech <[email protected]>
  • Loading branch information
pi-anl authored and Andrew Leech committed Nov 29, 2023
1 parent 8003704 commit 0fe810b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ports/stm32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,15 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
if (len != -1) {
// Detected a littlefs filesystem so create correct block device for it
mp_obj_t args[] = { MP_OBJ_NEW_QSTR(MP_QSTR_len), MP_OBJ_NEW_SMALL_INT(len) };
bdev = MP_OBJ_TYPE_GET_SLOT(&pyb_flash_type, make_new)(&pyb_flash_type, 0, 1, args);
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
bdev = MP_OBJ_TYPE_GET_SLOT(&pyb_flash_type, make_new)(&pyb_flash_type, 0, 1, args);
nlr_pop();
} else {
// Uncaught exception; len must be an invalid length.
mp_printf(&mp_plat_print, "MPY: corrupted filesystem\n");
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
}
}

#endif
Expand Down

0 comments on commit 0fe810b

Please sign in to comment.