How to properly increase FLASH_FS on pyboardv11?

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
ltmerlin
Posts: 34
Joined: Fri Jun 28, 2019 12:34 pm

How to properly increase FLASH_FS on pyboardv11?

Post by ltmerlin » Fri May 22, 2020 10:17 am

Can someone point me in the right direction to increase the FLASH_FS of the pyboardv11?

If have changed the origin of the FLASH_TEXT and the corresponding LENGTHs in stm32f405.ld file:

Code: Select all

/* Specify the memory areas */
MEMORY
{
    FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K /* entire flash */
    FLASH_ISR (rx)  : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */
    FLASH_FS (rx)   : ORIGIN = 0x08004000, LENGTH = 496K
    FLASH_TEXT (rx) : ORIGIN = 0x080A0000, LENGTH = 384K
    CCMRAM (xrw)    : ORIGIN = 0x10000000, LENGTH = 64K
    RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 128K
}
What do I have to change in the flashbdev.c file since I don't know what sector size I need to use... The original file has:

Code: Select all

#define FLASH_MEM_SEG1_NUM_BLOCKS (224) // sectors 1,2,3,4: 16k+16k+16k+64k=112k
I changed it to:

Code: Select all

#define FLASH_MEM_SEG1_NUM_BLOCKS (1248) // sectors 1,2,3,4,5,6,7,8: 16k+16k+16k+64k+128k+128k+128k+128k=624
and built it but the PYFLASH storage volume, as it appears when resetting the device after flash, still states the standard available pyboard size.

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

Re: How to properly increase FLASH_FS on pyboardv11?

Post by dhylands » Fri May 22, 2020 5:18 pm

See: viewtopic.php?f=3&t=3702&p=22627&p22627#p22627

You can't just increase the filesystem size i the flash blocks aren't the right sizes.

ltmerlin
Posts: 34
Joined: Fri Jun 28, 2019 12:34 pm

Re: How to properly increase FLASH_FS on pyboardv11?

Post by ltmerlin » Sun May 24, 2020 8:55 pm

thanks, I indeed had to look at the sector sizes.

I also had to change this in the flashbdev.c:

Code: Select all

#define FLASH_MEM_SEG1_NUM_BLOCKS (992) // sectors 1,2,3,4,5,6,7: 16k+16k+16k+64k+128k+128k+128k=496k
I'm not sure why I had to double the value (here 496k) to 992 to get the right number of blocks...

chrismas9
Posts: 148
Joined: Wed Jun 25, 2014 10:07 am

Re: How to properly increase FLASH_FS on pyboardv11?

Post by chrismas9 » Sun May 31, 2020 4:22 pm

You can't just keep extending the number of flash sectors on the F4 because the sectors 6 and higher are 128KB and the cache is only 64KB. There is a mechanism in flashbdev.c to use 64KB from each of sectors 6 and 7. Have a look at the F413 port which shows how to get the largest filesystem on F4. You will need to copy the memory layout in the .ld file, mpconfigboard.mk and flashbdev.c

Filesystem blocks are 512 bytes so to get the number of blocks divide the fs size by 512, eg 112K / 512 = 224.

ltmerlin
Posts: 34
Joined: Fri Jun 28, 2019 12:34 pm

Re: How to properly increase FLASH_FS on pyboardv11?

Post by ltmerlin » Mon Jun 01, 2020 4:36 pm

thanks for the explanation.

the F413 has:

Code: Select all

MEMORY
{
    FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K /* entire flash */
    FLASH_ISR (rx)  : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */
    FLASH_FS (rx)   : ORIGIN = 0x08004000, LENGTH = 176K /* sectors 1,2,3 are 16K, 4 is 64K, 5 is 128K (64K used) for filesystem */
    FLASH_FS2 (rx)  : ORIGIN = 0x08040000, LENGTH = 128K /* sector 6 is 128K (64K used) for filesystem, Total filesystem 240K */
    FLASH_TEXT (rx) : ORIGIN = 0x08060000, LENGTH = 640K /* sectors 7,8,9,10,11  are 128K*/
    SRAM2 (xrw)     : ORIGIN = 0x10000000, LENGTH = 64K
    RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 256K
}
and in the flashbdev.c:

Code: Select all

#define CACHE_MEM_START_ADDR (0x10000000) // SRAM2 data RAM, 64k
#define FLASH_SECTOR_SIZE_MAX (0x10000) // 64k max, size of SRAM2
#define FLASH_MEM_SEG1_START_ADDR (0x08004000) // sector 1
#define FLASH_MEM_SEG1_NUM_BLOCKS (352) // sectors 1,2,3,4,5: 16k+16k+16k+64k+64k(of 128k)=176k
#define FLASH_MEM_SEG2_START_ADDR (0x08040000) // sector 6
#define FLASH_MEM_SEG2_NUM_BLOCKS (128) // sector 6: 64k(of 128k). Filesystem 176K + 64K = 240K
Strangely it "seems" to work for larger values on the STM32F405 when I use:

Code: Select all

MEMORY
{
    FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K /* entire flash */
    FLASH_ISR (rx)  : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */
    FLASH_FS (rx)   : ORIGIN = 0x08004000, LENGTH = 496K
    FLASH_TEXT (rx) : ORIGIN = 0x08080000, LENGTH = 512K
    CCMRAM (xrw)    : ORIGIN = 0x10000000, LENGTH = 64K
    RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 128K
}
with flashbdev.c:

Code: Select all

#define CACHE_MEM_START_ADDR (0x10000000) // CCM data RAM, 64k
#define FLASH_SECTOR_SIZE_MAX (0x10000) // 64k max, size of CCM
#define FLASH_MEM_SEG1_START_ADDR (0x08004000) // sector 1#define FLASH_MEM_SEG1_NUM_BLOCKS (992) // sectors 1,2,3,4,5,6,7: 16k+16k+16k+64k+128k+128k+128k=496k
Is this possible?

chrismas9
Posts: 148
Joined: Wed Jun 25, 2014 10:07 am

Re: How to properly increase FLASH_FS on pyboardv11?

Post by chrismas9 » Tue Jun 02, 2020 4:48 pm

uPy may report the large fs size based on numblocks, but it won't work. Have you tried filling the fs with files, then editing or replacing them? When you try to change a 512 byte sector in a 128KB flash block the whole 128KB has to be backed up in cache RAM while the block is erased. Then the new sector data is written along with all the other sectors from the cache. Since there is only 64KB cache you can't erase/write a 128KB block. Due to the way uPy calculates the next sector address you can only use a half sector (64KB used or 128KB) at the end of a sequence of flash blocks - the last block of FLASH_FS and one block in FLASH_FS2.

You can't get more fs than the F413 port without extending the number of half blocks allowed, either by adding FLASH_FS3, etc or changing the way uPy calculates addresses when the cache is smaller than the block.

ltmerlin
Posts: 34
Joined: Fri Jun 28, 2019 12:34 pm

Re: How to properly increase FLASH_FS on pyboardv11?

Post by ltmerlin » Sat Jun 06, 2020 7:26 pm

Ok that makes sense!
Thanks for you reply. Your suggestions work and indeed when filling the FS with my first suggested build settings it does really strange things :D

Post Reply