STM32F429 Flash Memory Size

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
codyhanks
Posts: 16
Joined: Thu Nov 30, 2017 7:30 pm

STM32F429 Flash Memory Size

Post by codyhanks » Thu Mar 29, 2018 10:30 pm

I have a custom board for the STM32F429. I have copied the STM32F429-DISC folder to make a new board, updated the mpconfig.h,pins.csv. Changes to the USB used, input and output pins, LEDs ...

The question is this, I have tried both STLink "Hex" and DFU loading the compiled code I am still only seeing the 95k of flash space for files.
I have looked in the ".ld" file it shows the flash size of 2048k, I have not modified any additional files, is there something that needs to be defined or what changes would need to be made to get the additional space to show up?
thanks.

Drako
Posts: 12
Joined: Thu Oct 19, 2017 9:28 am

Re: STM32F429 Flash Memory Size

Post by Drako » Tue Apr 03, 2018 6:27 am

The filesystem is created by micropython on startup.

The file flashbdev.c is defines at which adress and how many blocks are used for the file system. (Previously it was located in the storage.c)

Code: Select all

#elif defined(STM32F429xx)

#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 (224) // sectors 1,2,3,4: 16k+16k+16k+64k=112k
You might have to define the flash sectors, if the predefined setup doesn't fit your MCU, or you change the nDBANK settings. This is located at the file flash.c

This is how I edited mine to fit my needs:

Code: Select all

// Added by MD
// Flash layout nDBANK = 1  - 1MB
//static const flash_layout_t flash_layout[] = {
//    { 0x08000000, 0x08000, 4 },
//    { 0x08020000, 0x20000, 1 },
//    { 0x08040000, 0x40000, 3 },
//};
// Flash layout nDBANK = 1  - 2MB
//static const flash_layout_t flash_layout[] = {
//    { 0x08000000, 0x08000, 4 },
//    { 0x08020000, 0x20000, 1 },
//    { 0x08040000, 0x40000, 7 },
//};
// Flash layout nDBANK = 0  - 2MB
//static const flash_layout_t flash_layout[] = {
//    { 0x08000000, 0x02000, 4 },
//    { 0x08010000, 0x10000, 1 },
//    { 0x08020000, 0x20000, 7 },
//    { 0x08100000, 0x02000, 4 },
//    { 0x08110000, 0x10000, 1 },
//    { 0x08120000, 0x20000, 7 },
//};
// Flash layout nDBANK = 0 - 1MB
static const flash_layout_t flash_layout[] = {
    { 0x08000000, 0x02000, 4 },
    { 0x08010000, 0x10000, 1 },
    { 0x08020000, 0x20000, 3 },
    { 0x08080000, 0x00000, 4 },                                         // DummyBanks to skip sectors 8 - 11 that do not exsist, because they are numbered from 1 - 7 and then 12 - 19
    { 0x08080000, 0x02000, 4 },
    { 0x08090000, 0x10000, 1 },
    { 0x080A0000, 0x20000, 3 },
    { 0x08100000, 0x00000, 4 },                                         // DummyBanks to skip sectors 20 - 23 that do not exsist, because they are numbered from 1 - 7 and then 12 - 19 (do we need this?)
};
The linker sript defines where the micropython firmware is located in the Flash. It also defindes a file system part ("FLASH_FS") which is not used as far as I know. But it helps to see where the firmware ends and the filesystem start so it doesn't get corrupted.

Code: Select all

MEMORY
{
    FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K
    FLASH_ISR (rx)  : ORIGIN = 0x08000000, LENGTH = 32K
    FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 640K                
    FLASH_FS (r)    : ORIGIN = 0x08008000, LENGTH = 96K
    FLASH_FS2 (r)   : ORIGIN = 0x080C0000, LENGTH = 256K           
    DTCM (xrw)      : ORIGIN = 0x20000000, LENGTH = 128K 
    RAM (xrw)       : ORIGIN = 0x20020000, LENGTH = 384K 
}
When you change this, you can increase the fileystem size. When I remember correctly, micropython can use a maximum flash page size of 128 KB. So to maximze the filewsystem size I had to change the MCU nDBANK settings, which also changes the flash loayout of the device.

Do not forget to either clear the flah completly when changing the filesystem settings or reinit the filesystem of the pyboard. I made this mistake at first. (see at post viewtopic.php?f=3&t=3702&p=22612#p22612)

Hope this helps a little.

codyhanks
Posts: 16
Joined: Thu Nov 30, 2017 7:30 pm

Re: STM32F429 Flash Memory Size

Post by codyhanks » Tue Apr 03, 2018 11:40 pm

I think I found and made the changes for now V1.9.3 in the file flashbdev.c in the section for the STM32F429xx I added the two lines from prior post by dhylands

"If you set FLASH_MEM_SEG2_NUM_BLOCKS to 224 and FLASH_MEM_SEG2_START_ADDR to 0x8100000 then you'd get double the filesystem size."

then in the
".ld" file

This got me to the 208K flash drive space

Post Reply