Page 2 of 2

Re: How to properly increase FLASH_FS on pyboardv11?

Posted: Thu Sep 24, 2020 11:45 am
by SmartTech
Is there any way to increase pyboard PBV11 flash drive?

Re: How to properly increase FLASH_FS on pyboardv11?

Posted: Fri Sep 25, 2020 12:54 am
by jimmo
SmartTech wrote:
Thu Sep 24, 2020 11:45 am
Is there any way to increase pyboard PBV11 flash drive?
The chip has a fixed amount of flash that needs to be used for firmware and filesystem. You can't increase this internal storage, however you could add an external spiflash chip and put the filesystem on there instead.

However, the MicroPython firmware assumes that it should reserve 112kiB for the filesystem, allowing 896kiB for the MicroPython firmware (including any frozen modules).

The PYBV11 firmware only needs about ~400k, so **in theory** there's a fair bit that can be reallocated to the filesystem. However, it's more complicated than that...

On the F405 you have the following sectors

0: 16kiB
1: 16kiB
2: 16kiB
3: 16kiB

4: 64kiB

5: 128kiB
6: 128kiB
7: 128kiB

8: 128kiB
9: 128kiB
10: 128kiB
11: 128kiB

The default layout is to put the bootloader in sector 0, the filesystem in sectors 1,2,3,4 (112kiB), and the firmware in the remaining sectors (5,6,7,8,9,10,11).

But the issue is that (on STM32F4) you can only erase on a whole-sector boundary, but our filesystems (FAT, LFS) work on much smaller block sizes. So that means you need a in-RAM cache that is as big as the largest sector so that you can do read-update-write to the whole sector. Unfortunately, we only have 64kiB of RAM available for a cache (in CCMRAM) so that means we're limited to just using the sectors that are 64kiB or smaller (i.e. 0-4) for the filesystem.

If you need more space for Python code, I suggest freezing the Python code instead (which will make it part of the firmware). For other resources (such as images or data files), then you can also freeze them into the firmware too -- see https://github.com/micropython/micropyt ... -562918657

Re: How to properly increase FLASH_FS on pyboardv11?

Posted: Fri Sep 25, 2020 1:11 am
by jimmo
Note: If you were prepared to waste half of the 128kiB sectors, you could treat them like 64kiB sectors. (i.e. edit the layout defined at the top of stm32/flash.c). So MicroPython would think they were 64kiB sectors and ignore the top half.

A simpler example is of doing this with just sector 11 is in the top of stm32/flashbdev.c (line 51). If you enable that, then modify the linker script to make FLASH_TEXT 128kiB smaller, then you'll get an extra 64kiB of filesystem.

Re: How to properly increase FLASH_FS on pyboardv11?

Posted: Thu Oct 15, 2020 8:59 am
by SmartTech
Sorry for the late reply, but your suggestion was really simple and quick to do. I should have looked few line below! I would still like to know why I can't add other section as it was suggested in the beginning of this issue. Their is still half of the memory not used, but 64KB more is enough for my need for now.

Thanks for your help jimmo!