Skip to content

Introduce Zephyr Filesystem VFS interface #17084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

VynDragon
Copy link
Contributor

@VynDragon VynDragon commented Apr 6, 2025

Summary

Adds VFS interface for Zephyr filesystems

Testing

Basic tests on nrf52840, would recommend thorough testing.

15/08/2025: also tested on rp2040.

@VynDragon VynDragon force-pushed the Zephyr_FS branch 3 times, most recently from 95e18a8 to 6b7d85f Compare April 6, 2025 16:39
Copy link

github-actions bot commented Apr 6, 2025

Code size report:


@VynDragon VynDragon changed the title Zephyr fs Introduce Zephyr Filesystem VFS interface Apr 6, 2025
@projectgus projectgus self-requested a review April 8, 2025 05:30
@jonnor
Copy link
Contributor

jonnor commented May 7, 2025

What is needed to set this up on a device? Any limitations, or can one use any file-system operations from Python like on other ports?

@VynDragon
Copy link
Contributor Author

VynDragon commented May 8, 2025

Basically you need to setup a fstab and then format it (format can be done via mpy like normal fs, you may need to enable format ability on zephyr side): https://docs.zephyrproject.org/latest/services/file_system/index.html

After that it works like any mpy fs.

@VynDragon
Copy link
Contributor Author

rebased on main

Allows using Zephyr RTOS File system drivers and share files with Zephyr

Signed-off-by: Vdragon <mail@massdriver.space>
@VynDragon
Copy link
Contributor Author

VynDragon commented Aug 15, 2025

Added guardrail for automount / mkfs.

Here is to use it on rp2040, this was for a 16MB rp2040 board so adapt the sizes to yours.

boards/rpi_pico.conf:

# Disable floating point hardware.
CONFIG_FPU=n

# Configure serial console over USB CDC ACM.
CONFIG_USB_DEVICE_STACK_NEXT=y
CONFIG_USBD_CDC_ACM_CLASS=y
CONFIG_UART_LINE_CTRL=y

# Disable networking.
CONFIG_NETWORKING=n

# Hardware features.
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_I2C=y
CONFIG_I2C_TARGET=y
CONFIG_SPI=y

# MicroPython config.
CONFIG_MICROPY_HEAP_SIZE=100608
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
CONFIG_FILE_SYSTEM_MKFS=y

boards/rpi_pico.overlay:

/*
 * Copyright (c) 2025 Damien P. George
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/ {
	chosen {
		/* Use USB CDC ACM as the console. */
		zephyr,console = &cdc_acm_uart0;
	};

	fstab {
		compatible = "zephyr,fstab";
		lfs21: lfs21 {
			compatible = "zephyr,fstab,littlefs";
			mount-point = "/flash";
			partition = <&storage_partition>;
			read-size=<16>;
			prog-size=<4096>;
			cache-size=<4096>;
			lookahead-size=<32>;
			block-cycles=<4>;
		};
	};
};

/* Delete defined partitions and make a layout matching the rp2 port RPI_PICO configuration. */
/delete-node/ &code_partition;
&flash0 {
	reg = <0x10000000 DT_SIZE_M(16)>;
	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		/* Code slot: 640 KiB - 0x100 placed after second-stage bootloader. */
		code_partition: partition@100 {
			label = "code-partition";
			reg = <0x00000100 (DT_SIZE_K(640) - 0x100)>;
			read-only;
		};

		/* Storage slot: 1408 KiB placed after code_partition. */
		storage_partition: partition@a0000 {
			label = "storage";
			reg = <0x000a0000 DT_SIZE_M(2)>;
		};
	};
};

&zephyr_udc0 {
	cdc_acm_uart0: cdc_acm_uart0 {
		compatible = "zephyr,cdc-acm-uart";
	};
};

&i2c1 {
	clock-frequency = <I2C_BITRATE_STANDARD>;
	status = "okay";
	pinctrl-0 = <&i2c1_default>;
	pinctrl-names = "default";
};

In mpy:

import zephyr
zfs = zephyr.FS(zephyr.FS.fstab()[0])
vfs.mount(zfs, "/zephyr")

Be aware you may have to disable the automatic vfs mounting in main or umount manually, because mpy's vfs will detect zephyr's and take ownership of it through its own vfs system so /flash is likely to be occupied.

Edit: and i mean the vfs.mount name, the '/flash' in the overlay is the name used in the fstab on zephyr side, not useful mpy side except when creating the class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants