[Blackpill STM32F407 / SZM32F411] Available Flash Memory for Programs

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
rruf
Posts: 6
Joined: Sat Mar 14, 2020 8:04 pm

[Blackpill STM32F407 / SZM32F411] Available Flash Memory for Programs

Post by rruf » Sat Apr 18, 2020 5:44 pm

Hi,
i was getting started using a Blackboard with STM32F411, which has 512kB Flash. However, after uploading Micropython there was only about 45 kByte Flash left for own programs. I know i can add an external Flash chip to this board, but let's neglect that at the moment.
Hence, i bought another black board, with the STM32F407VGT6 onboard. This MCU has 1Mbyte Flash available, so i was hoping there would be more Flash left this time. However, it is only about 90 kByte which is still a little less.
Is there any tweaking available with Micropython, so i can get more Flash memory for my programs? And why does the port for STM32F407VGT6 use so much Flash for its own (compared to STM32F411 port)? The port was downloaded from Mike Causer's github, so maybe he's got an answer for that question.
Regards,
Raphael

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

Re: [Blackpill STM32F407 / SZM32F411] Available Flash Memory for Programs

Post by dhylands » Sat Apr 18, 2020 8:49 pm

It depends on the linker map that you're using.

If you look in the board file's mkconfigboard.mk file, you'll see a line something like this one:
https://github.com/micropython/micropyt ... oard.mk#L4

If we then go and look in the stm32f405.ld file, we'll see this:
https://github.com/micropython/micropyt ... 405.ld#L11

I suspect that the .ld file your board is using isn't setup for the 1Mb flash.

You should be able to confirm this as well by looking in the firmware.map file that will be in your build-BOARDNAME directory. Search for FLASH_TEXT and you should see something like:

Code: Select all

Memory Configuration

Name             Origin             Length             Attributes
FLASH            0x0000000008000000 0x0000000000100000 xr
FLASH_ISR        0x0000000008000000 0x0000000000004000 xr
FLASH_FS         0x0000000008004000 0x000000000001c000 xr
FLASH_TEXT       0x0000000008020000 0x00000000000e0000 xr
CCMRAM           0x0000000010000000 0x0000000000010000 xrw
RAM              0x0000000020000000 0x0000000000020000 xrw
*default*        0x0000000000000000 0xffffffffffffffff

which shows the FLASH_TEXT section as being e0000 which is 896K.

rruf
Posts: 6
Joined: Sat Mar 14, 2020 8:04 pm

Re: [Blackpill STM32F407 / SZM32F411] Available Flash Memory for Programs

Post by rruf » Sun Apr 19, 2020 9:17 am

Ok, thank you a lot. Actually, this port of Mike Causer uses the same linker file that you mentioned (stm32f405.ld), so the numbers in the map-file were also as you predicted. What i did then was to change FLASH_FS section from 112 to 496 and FLASH_TEXT section from 896 to 512 in hope to get more memory for the file system. It did reflect in the new map-file, however on the device the same small memory as before is available.
Am I missing something?

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

Re: [Blackpill STM32F407 / SZM32F411] Available Flash Memory for Programs

Post by jimmo » Sun Apr 19, 2020 12:37 pm

How are you measuring the available storage size?

FWIW, I think you also need to make a corresponding change to ports/stm32/flashbdev.c, specifically FLASH_MEM_SEG1_NUM_BLOCKS

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: [Blackpill STM32F407 / SZM32F411] Available Flash Memory for Programs

Post by mcauser » Mon Apr 20, 2020 3:15 am

On the F411 board, I demonstrated in the readme attaching an external W25Q128 16MB SPI flash module. The particular breakout I was using only supported SPI mode, instead of the faster QSPI mode. Still, 4, 8 or 16MB more to play with. In mpconfigboard.h you can toggle between using the onboard flash or use an external flash chip. There is space on the bottom of a board to solder on a flash chip. I had the recommended flash chips, but on modules, and since they broke out all of the pins of the flash footprint, I just used the external flash breakout modules.

Each of those "black" (MCUDev) boards have a W25Q16 (2MB) Winbond SPI flash chip onboard.
In my board defs, you can configure in mpconfigboard.h whether you want to use the SPI flash as a block device and mount it or use the flash on the STM32 chip. See bdev.c

I don't have a board def for the VGT6. I do for the VET6, ZET6 and ZGT6. Should be pretty similar.

rruf
Posts: 6
Joined: Sat Mar 14, 2020 8:04 pm

Re: [Blackpill STM32F407 / SZM32F411] Available Flash Memory for Programs

Post by rruf » Mon Apr 20, 2020 12:16 pm

Jimmo:
I am looking at the space indicated by Windows explorer. It always shows a little less than it should be, i guess the missing memory is for the file system setup itself.
I was able to gain some more memory by editing flashbdev.c as you supposed. However, i am unsure which of the Flash blocks i can use for the FS memory and which are for MP itself (have to check the linker script again). Also, i read somewhere, that the allocated flash pages must not be bigger than CCMRAM section. The pity is, the higher number flash pages are bigger than that, so i can only use them partially i guess? In total i am having now about 220kByte available which is an improvement, yet i hoped for something like 512kByte. Is there any way to figure out how much memory is required by MP (without frozen code) itself?

Mike:
I am aware of the possibilities of having/adding external flash on both boards, but i wanted to go without it first. The thing is, i can hardly imagine having external flash will not severly impair performance. I have not tested this however, still waiting for more units to arrive. Also, there might be some implications regarding the other SPI peripherals of the MCU if you are using external flash, but i haven't checked that either.
Actually, you do have a port for VGT6, see here:

https://github.com/mcauser/MCUDEV_DEVEBOX_F407VGT6

That is exactly one of the boards i am using.

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

Re: [Blackpill STM32F407 / SZM32F411] Available Flash Memory for Programs

Post by jimmo » Mon Apr 20, 2020 12:29 pm

rruf wrote:
Mon Apr 20, 2020 12:16 pm
Also, i read somewhere, that the allocated flash pages must not be bigger than CCMRAM section.
Yes this is true... these microcontrollers weren't really designed to run filesystems on their embedded flash. In order to write a block, it has to read the whole sector into RAM, modify just the block, then write the whole sector back.
rruf wrote:
Mon Apr 20, 2020 12:16 pm
Is there any way to figure out how much memory is required by MP (without frozen code) itself?
When you compile the firmware, the very last thing it prints out is the size:

Code: Select all

LINK build-particle_xenon/firmware.elf
   text	   data	    bss	    dec	    hex	filename
 149088	     40	   4548	 153676	  2584c	build-particle_xenon/firmware.elf

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: [Blackpill STM32F407 / SZM32F411] Available Flash Memory for Programs

Post by mcauser » Tue Apr 21, 2020 12:15 am

If you have that DevEBox board, that little W25Q16 chip above the micro SD slot is the 16MB SPI Flash. It's wired to SPI1, leaving SPI2 and 3 free for use by other devices. It's CS pin is exposed on A15, so you could have other SPI devices on the SPI1 bus.

RDA
Posts: 9
Joined: Fri Oct 30, 2020 9:55 am

Re: [Blackpill STM32F407 / SZM32F411] Available Flash Memory for Programs

Post by RDA » Sun Dec 06, 2020 7:27 pm

This looks like a really cool option and personally I think the option to choose your memory size by adding your "own" is great. As for compiling the code, I assume its a linux "only"? Or would it compile on windows with gcc-arm? As you probably guessed, im not really experieced with this. I put a set of boards in order and want to clear out some of the details before they arrive. All info much appreciated.

Post Reply