Disabling Flash file system

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
burtbick
Posts: 5
Joined: Thu Aug 20, 2020 9:41 pm

Disabling Flash file system

Post by burtbick » Thu Oct 22, 2020 4:15 pm

Hi,
A new requirement that was just presented is to disable the Flash file system in Micropython while keeping the SD card support.
Is there an easy way (e.g. conditional compile) to do this in Micropython at present? If so where should I look? There's nothing that I've spotted yet in mpconfigboard.h that looks like it might address this issue.

Defining MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0) in our mpconfigboard.h would seem to be a potential candidate but I'm hitting a build error.

This is Micropython 1.12 ..
When I build with internal flash storage disabled this also causes MICROPY_HW_ENABLE_STORAGE to become undefined and this causes a problem because pyb_flash_type is being referenced in the code but now is conditionally compiled out, along with its related functions at least one of which is being called.

Has anyone else hit this issue, and if so how did you resolve it? Just thought I'd ask before digging into the code to work out the best solution.

Thanks,

User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: Disabling Flash file system

Post by rcolistete » Thu Oct 22, 2020 8:20 pm

Pyboard v1.1 ? Pyboard D SF2/3/6 ?
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

burtbick
Posts: 5
Joined: Thu Aug 20, 2020 9:41 pm

Re: Disabling Flash file system

Post by burtbick » Thu Oct 22, 2020 9:22 pm

Sorry, I should have added that this is a custom PCB but pretty much based on the PyBoards. Specifically the stm32h75x series. The board is working well, with LCD display, camera, keypad and a bunch other other special features so it is just the need to disable the flash file system while retaining the SD card support.

Thanks,
Burt

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Disabling Flash file system

Post by jimmo » Fri Oct 23, 2020 12:10 am

burtbick wrote:
Thu Oct 22, 2020 4:15 pm
When I build with internal flash storage disabled this also causes MICROPY_HW_ENABLE_STORAGE to become undefined and this causes a problem because pyb_flash_type is being referenced in the code but now is conditionally compiled out, along with its related functions at least one of which is being called.
I've only spent about 2 minutes looking into this, but yes, like you say if you don't enable a block device (usually either internal flash or configuring an external spiflash bdev), then MICROPY_HW_ENABLE_STORAGE is disabled (because, somewhat confusingly, "storage" is about providing the pyb.Flash() interface -- pyb_flash_type). I'm surprised anything depends on pyb_flash_type if MICROPY_HW_ENABLE_STORAGE is disabled.

There are a few boards that do this (e.g. the F091 Nucleo, and the L07x boards).

But the SDCard and the VFS stuff is independent of the internal block device support. So you don't technically need any of this to support the SD Card.

When you say " is being referenced in the code" where are the references? (The linker should be telling you this)

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Disabling Flash file system

Post by jimmo » Fri Oct 23, 2020 12:16 am

OK I took a slightly closer look.

I suspect the issue you're seeing is usbd_msc_interface.c which expects to be able to make the internal flash available over USB MSC.

The simple option is to disable MSC (which you likely don't want anyway?) via MICROPY_HW_USB_MSC. Perhaps if you felt like sending a PR to usbd_msc_interface.c to conditionally access the pyb_flash_type based on MICROPY_HW_ENABLE_STORAGE (similar to how the same file uses MICROPY_HW_ENABLE_SDCARD).

In addition, if you haven't already, you should be setting MICROPY_HW_HAS_FLASH to 0. I wonder if some of the places that use MICROPY_HW_HAS_FLASH (e.g. modpyb.c) to conditionally enable pyb_flash_type should actually be using MICROPY_HW_ENABLE_STORAGE.

Anyway, with the following in mpconfigboard.h, I can build (for example) PYBV11:

Code: Select all

#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0)
#define MICROPY_HW_HAS_FLASH        (0)
#define MICROPY_HW_USB_MSC          (0)

burtbick
Posts: 5
Joined: Thu Aug 20, 2020 9:41 pm

Re: Disabling Flash file system

Post by burtbick » Fri Oct 23, 2020 2:50 pm

Thanks that saves me a bunch of time digging, so I'll do some tests with that configuration.

One last question, setting HAS_FLASH to 0 would that impact the ability to read/write flash from the app. One other requirement they have is to use a section of flash for some persistent data. My vote was to use the SPI flash that is on the board for this but they want to use the internal flash for that option.

Thanks again,
Burt

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Disabling Flash file system

Post by jimmo » Sat Oct 24, 2020 4:44 am

burtbick wrote:
Fri Oct 23, 2020 2:50 pm
One last question, setting HAS_FLASH to 0 would that impact the ability to read/write flash from the app. One other requirement they have is to use a section of flash for some persistent data. My vote was to use the SPI flash that is on the board for this but they want to use the internal flash for that option.
Ah so in that case you do want to be able to use pyb.Flash, you just don't want it to be used for an internal filesystem. This would be easy, except that it sounds like you want to use the filesystem on the exernal flash, then the way things are organised it kind of assumes you therefore want pyb.Flash to then be the external spiflash. (i.e. there is only one flash bdev, and it's _either_ internal or external).

The very simple thing that would work but not particularly optimal would be to disable the filesystem on the internal spiflash (which I think is pretty much just a matter of preventing main() from attempting to creating/mount the filesystem). This would give your code an (unmounted) pyb.Flash that you could use for whatever purpose.

Then you could implement a spiflash driver in Python, and use that as the block device to mount the filesystem from Python. You'd need a frozen boot.py to implement this (as there won't be a filesystem at boot to load it from). (FWIW, this is a lot like how the ESP32 port works). You could also do the reverse, and implement a simple internal flash driver in Python.

Maybe there's an easy way... I guess what you kind of want is to have the C firmware able to provide _both_ a pyb.InternalSpiFlash and pyb.ExternalSpiFlash class (and pyb.Flash would be whatever the default one was). I don't have an easy way to look into this now but I will take a look early next week. Might be worth raising this as a issue/feature-request on github.com/micropython/micropython.

burtbick
Posts: 5
Joined: Thu Aug 20, 2020 9:41 pm

Re: Disabling Flash file system

Post by burtbick » Sat Oct 24, 2020 3:55 pm

Thanks,

Actually I found out that they are using the low level functions in flash.c to handle writing to the locations that they want to use for storage, so we don't need pyb.Flash to do that.

And the SD card access is working so far unless there was something else that I need to watch out for. At least reading files from the SD card is working. Haven't tested writing yet but I would expect that to work if it is reading OK.

But it would probably be good to offer some additional configuration options for this. SPI Flash is just being used to hold a binary blob at this point so they don't need any kind of file system for that either.

Burt

Post Reply