Skip to content

Commit 8236d18

Browse files
committed
stmhal/main: Allocate flash's VFS struct on the heap to trace root ptrs.
1 parent f07a56f commit 8236d18

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

stmhal/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ void SystemClock_Config(void);
6565

6666
pyb_thread_t pyb_thread_main;
6767
fs_user_mount_t fs_user_mount_flash;
68-
mp_vfs_mount_t mp_vfs_mount_flash;
6968

7069
void flash_error(int n) {
7170
for (int i = 0; i < n; i++) {
@@ -219,12 +218,17 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
219218
} else if (res == FR_OK) {
220219
// mount sucessful
221220
} else {
221+
fail:
222222
printf("PYB: can't mount flash\n");
223223
return false;
224224
}
225225

226226
// mount the flash device (there should be no other devices mounted at this point)
227-
mp_vfs_mount_t *vfs = &mp_vfs_mount_flash;
227+
// we allocate this structure on the heap because vfs->next is a root pointer
228+
mp_vfs_mount_t *vfs = m_new_obj_maybe(mp_vfs_mount_t);
229+
if (vfs == NULL) {
230+
goto fail;
231+
}
228232
vfs->str = "/flash";
229233
vfs->len = 6;
230234
vfs->obj = MP_OBJ_FROM_PTR(vfs_fat);

0 commit comments

Comments
 (0)