Skip to content

Commit 8a43a41

Browse files
committed
unix: Enable VfsFat support.
1 parent e9be6a3 commit 8a43a41

File tree

6 files changed

+52
-0
lines changed

6 files changed

+52
-0
lines changed

py/py.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ PY_O_BASENAME = \
170170
../extmod/modussl.o \
171171
../extmod/modurandom.o \
172172
../extmod/fsusermount.o \
173+
../extmod/vfs_fat.o \
173174
../extmod/moduos_dupterm.o \
174175

175176
# prepend the build destination prefix to the py object files

unix/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,14 @@ SRC_C = \
144144
moduselect.c \
145145
alloc.c \
146146
coverage.c \
147+
fatfs_port.c \
147148
$(SRC_MOD)
148149

150+
STMHAL_SRC_C = \
151+
stmhal/diskio.c \
152+
stmhal/ffconf.c \
153+
stmhal/file.c
154+
149155
# Include builtin package manager in the standard build (and coverage)
150156
ifeq ($(PROG),micropython)
151157
SRC_C += $(BUILD)/_frozen_upip.c
@@ -160,11 +166,14 @@ endif
160166
LIB_SRC_C = $(addprefix lib/,\
161167
$(LIB_SRC_C_EXTRA) \
162168
utils/printf.c \
169+
fatfs/ff.c \
170+
fatfs/option/ccsbcs.c \
163171
)
164172

165173
OBJ = $(PY_O)
166174
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
167175
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
176+
OBJ += $(addprefix $(BUILD)/, $(STMHAL_SRC_C:.c=.o))
168177

169178
include ../py/mkrules.mk
170179

unix/fatfs_port.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "lib/fatfs/ff.h"
2+
#include "lib/fatfs/diskio.h"
3+
4+
DWORD get_fattime(void) {
5+
return 0;
6+
}

unix/modos.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
#include "py/objtuple.h"
4040
#include "extmod/misc.h"
4141

42+
// Can't include this, as FATFS structure definition is required,
43+
// and FatFs header defining it conflicts with POSIX.
44+
//#include "extmod/fsusermount.h"
45+
MP_DECLARE_CONST_FUN_OBJ(fsuser_mount_obj);
46+
MP_DECLARE_CONST_FUN_OBJ(fsuser_umount_obj);
47+
MP_DECLARE_CONST_FUN_OBJ(fsuser_mkfs_obj);
48+
extern const mp_obj_type_t mp_fat_vfs_type;
49+
4250
#ifdef __ANDROID__
4351
#define USE_STATFS 1
4452
#endif
@@ -228,6 +236,14 @@ STATIC const mp_rom_map_elem_t mp_module_os_globals_table[] = {
228236
{ MP_ROM_QSTR(MP_QSTR_getenv), MP_ROM_PTR(&mod_os_getenv_obj) },
229237
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mod_os_mkdir_obj) },
230238
{ MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&mod_os_ilistdir_obj) },
239+
#if MICROPY_FSUSERMOUNT
240+
{ MP_ROM_QSTR(MP_QSTR_vfs_mount), MP_ROM_PTR(&fsuser_mount_obj) },
241+
{ MP_ROM_QSTR(MP_QSTR_vfs_umount), MP_ROM_PTR(&fsuser_umount_obj) },
242+
{ MP_ROM_QSTR(MP_QSTR_vfs_mkfs), MP_ROM_PTR(&fsuser_mkfs_obj) },
243+
#endif
244+
#if MICROPY_VFS_FAT
245+
{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
246+
#endif
231247
#if MICROPY_PY_OS_DUPTERM
232248
{ MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&mp_uos_dupterm_obj) },
233249
#endif

unix/mpconfigport.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@
112112
#define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr
113113
#define MICROPY_MACHINE_MEM_GET_WRITE_ADDR mod_machine_mem_get_addr
114114

115+
#define MICROPY_FATFS_ENABLE_LFN (1)
116+
#define MICROPY_FATFS_RPATH (2)
117+
// Can't have less than 3 values because diskio.h uses volume numbers
118+
// as volume types and PD_USER == 2.
119+
#define MICROPY_FATFS_VOLUMES (3)
120+
#define MICROPY_FATFS_MAX_SS (4096)
121+
#define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
122+
#define MICROPY_FSUSERMOUNT (1)
123+
#define MICROPY_VFS_FAT (1)
124+
115125
// Define to MICROPY_ERROR_REPORTING_DETAILED to get function, etc.
116126
// names in exception messages (may require more RAM).
117127
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
@@ -254,6 +264,8 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
254264
#define MICROPY_PORT_ROOT_POINTERS \
255265
const char *readline_hist[50]; \
256266
mp_obj_t keyboard_interrupt_obj; \
267+
/* for user-mountable block device (max fixed at compile time) */ \
268+
struct _fs_user_mount_t *fs_user_mount[MICROPY_FATFS_VOLUMES]; \
257269
void *mmap_region_head; \
258270

259271
// We need to provide a declaration/definition of alloca()

unix/qstrdefsport.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ Q(getenv)
4545
Q(mkdir)
4646
Q(ilistdir)
4747
Q(errno)
48+
#if MICROPY_FSUSERMOUNT
49+
Q(vfs_mount)
50+
Q(vfs_umount)
51+
Q(vfs_mkfs)
52+
#endif
53+
#if MICROPY_VFS_FAT
54+
Q(VfsFat)
55+
#endif
4856
#if MICROPY_PY_OS_DUPTERM
4957
Q(dupterm)
5058
#endif

0 commit comments

Comments
 (0)