zephyr: Enable fatfs.

Enables the fatfs filesystem in the zephyr port.

Example usage with an SD card on the mimxrt1050_evk board:

import zephyr, os
bdev = zephyr.DiskAccess('SDHC')
os.VfsFat.mkfs(bdev)
os.mount(bdev, '/sd')
with open('/sd/hello.txt','w') as f:
    f.write('Hello world')
print(open('/sd/hello.txt').read())
This commit is contained in:
Maureen Helm 2019-12-19 16:00:00 -06:00 committed by Damien George
parent a0440b01ea
commit 2d7ec8e704
3 changed files with 18 additions and 1 deletions

View File

@ -17,6 +17,8 @@ OUTDIR_PREFIX = $(BOARD)
MICROPY_HEAP_SIZE = 16384 MICROPY_HEAP_SIZE = 16384
FROZEN_DIR = scripts FROZEN_DIR = scripts
MICROPY_VFS_FAT ?= 1
# Default target # Default target
all: all:
@ -48,6 +50,7 @@ SRC_C = main.c \
machine_pin.c \ machine_pin.c \
uart_core.c \ uart_core.c \
zephyr_storage.c \ zephyr_storage.c \
lib/timeutils/timeutils.c \
lib/utils/stdout_helpers.c \ lib/utils/stdout_helpers.c \
lib/utils/printf.c \ lib/utils/printf.c \
lib/utils/pyexec.c \ lib/utils/pyexec.c \
@ -61,7 +64,7 @@ SRC_QSTR += $(SRC_C)
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
CFLAGS = $(Z_CFLAGS) \ CFLAGS = $(Z_CFLAGS) \
-std=gnu99 -fomit-frame-pointer -DNDEBUG -DMICROPY_HEAP_SIZE=$(MICROPY_HEAP_SIZE) $(CFLAGS_EXTRA) $(INC) -std=gnu99 -fomit-frame-pointer -DNDEBUG -DMICROPY_HEAP_SIZE=$(MICROPY_HEAP_SIZE) $(CFLAGS_MOD) $(CFLAGS_EXTRA) $(INC)
include $(TOP)/py/mkrules.mk include $(TOP)/py/mkrules.mk

View File

@ -28,6 +28,10 @@
#include "extmod/vfs.h" #include "extmod/vfs.h"
#if MICROPY_VFS_FAT
#include "extmod/vfs_fat.h"
#endif
#if MICROPY_PY_UOS #if MICROPY_PY_UOS
STATIC const mp_rom_map_elem_t uos_module_globals_table[] = { STATIC const mp_rom_map_elem_t uos_module_globals_table[] = {
@ -47,6 +51,9 @@ STATIC const mp_rom_map_elem_t uos_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) }, { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) }, { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) },
#endif #endif
#if MICROPY_VFS_FAT
{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
#endif
}; };
STATIC MP_DEFINE_CONST_DICT(uos_module_globals, uos_module_globals_table); STATIC MP_DEFINE_CONST_DICT(uos_module_globals, uos_module_globals_table);

View File

@ -84,6 +84,13 @@
#define MICROPY_VFS (1) #define MICROPY_VFS (1)
#define MICROPY_READER_VFS (MICROPY_VFS) #define MICROPY_READER_VFS (MICROPY_VFS)
// fatfs configuration used in ffconf.h
#define MICROPY_FATFS_ENABLE_LFN (1)
#define MICROPY_FATFS_LFN_CODE_PAGE 437 /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
#define MICROPY_FATFS_USE_LABEL (1)
#define MICROPY_FATFS_RPATH (2)
#define MICROPY_FATFS_NORTC (1)
// Saving extra crumbs to make sure binary fits in 128K // Saving extra crumbs to make sure binary fits in 128K
#define MICROPY_COMP_CONST_FOLDING (0) #define MICROPY_COMP_CONST_FOLDING (0)
#define MICROPY_COMP_CONST (0) #define MICROPY_COMP_CONST (0)