Skip to content

Commit

Permalink
stm32/main: Support SD cards without a partition table.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Mar 22, 2022
1 parent 75d2bfc commit 63c7593
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ports/stm32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,24 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
#if MICROPY_HW_SDCARD_MOUNT_AT_BOOT
STATIC bool init_sdcard_fs(void) {
bool first_part = true;
for (int part_num = 1; part_num <= 4; ++part_num) {
for (int part_num = 1; part_num <= 5; ++part_num) {
// create vfs object
fs_user_mount_t *vfs_fat = m_new_obj_maybe(fs_user_mount_t);
mp_vfs_mount_t *vfs = m_new_obj_maybe(mp_vfs_mount_t);
if (vfs == NULL || vfs_fat == NULL) {
break;
}
vfs_fat->blockdev.flags = MP_BLOCKDEV_FLAG_FREE_OBJ;
sdcard_init_vfs(vfs_fat, part_num);
if (part_num == 5) {
if (!first_part) {
break;
}
// partitions 1-4 couldn't be mounted, so try FATFS auto-detect mode
// which will work if there is no partition table, just a filesystem
sdcard_init_vfs(vfs_fat, 0);
} else {
sdcard_init_vfs(vfs_fat, part_num);
}

// try to mount the partition
FRESULT res = f_mount(&vfs_fat->fatfs);
Expand Down

0 comments on commit 63c7593

Please sign in to comment.