Can Micropython and C modules share the same FAT filesystem?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
allspace123
Posts: 6
Joined: Mon Mar 21, 2022 10:55 am

Can Micropython and C modules share the same FAT filesystem?

Post by allspace123 » Sun Apr 03, 2022 12:49 am

For ESP32, Can Micropython(script) and C modules share(access) the same FAT filesystem? (C modules are the extension modules for Micropython)

If yes:
- Do they (Micropython and C modules) need do mounting seperately?
- Will it cause any access competition issue? for example, both Micropython task and C module task try to write the same directory.

I guess if the backend of MicroPython's FAT support relies on ESP32 C API, then there should be no issue with the cases above.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Can Micropython and C modules share the same FAT filesystem?

Post by dhylands » Mon Apr 04, 2022 5:07 am

The C code can use the same filesystem but it needs to use use the python functions to read/write/open/close the file and not use the c runtime library (I.e. fread/fwrite/fopen/fclose).

An example of how to do this can be found in the mpfile.c file from this commit: https://github.com/dhylands/micropython ... e1e0f0c21b (which was never merged into the mainline).

allspace123
Posts: 6
Joined: Mon Mar 21, 2022 10:55 am

Re: Can Micropython and C modules share the same FAT filesystem?

Post by allspace123 » Thu Apr 07, 2022 4:12 am

Thank you! After read more code, I also realized it is not easy to share the same FS.

Both ESP-IDF and MicroPython ship their own FATFS implementation (although they are from the same upstream). This makes FS sharing not easy. And it looks like the FATFS for MicroPython does not recognize Wearing Level feature.

It would be great if the proposed C API can be magered to mainstream. Otherwise, we have to make C app and MicroPython script use seperate FS.

Post Reply