Increasing Code Storage Space on STM32F405 Board #16518
-
Hi everyone, I am working with a Pyboard STM32F405, and after flashing MicroPython, I am left with only about 90 kilobytes of free memory for storing code. This has proven to be quite limiting for my project, and I am looking for ways to increase this space by at least 2–3 times. Here’s what I’ve considered so far: Using external memory (e.g., an SD card or SPI Flash). However, for my project, it’s important that the code is stored and executed directly in the internal memory of the microcontroller. I’d greatly appreciate any advice or links to resources that could help me solve this issue! Thank you for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Hi daleka, the STM32F405 has 192 kB of RAM in total but only 128 kB are usable for Micropython (fully accessible by the CPU including for heap, stack, code execution). The other RAM (64 kB) is used for buffers (IO). There were successful attempts to use the other RAM for heap IIRC. |
Beta Was this translation helpful? Give feedback.
-
The easiest solution would be to use SD card. You will probably need "sdcard.py" or something similar. Now your main.py can look like this: import pyb, sdcard, os, sys
sd = sdcard.SDCard(pyb.SPI(1), pyb.Pin.board.X5)
pyb.mount(sd, '/sd')
os.chdir('/sd') # os.getcwd() == '/sd'
# import your app (myapp.py or myapp.mpy) from SDcard
from myapp import prog
prog() # and run it I hope this can be of some help. |
Beta Was this translation helpful? Give feedback.
-
Hi daleka, now I see. Two relevant discussions are here and here. Extending the approach by @saraverbeecke you might go with:
to have 176 + 64 + 64 = 304 kB of Flash for filesystem.
So even another 64 kB of flash (or more) should be possible with modest (or graver) restrictions on MP functionality and a dedicated build. |
Beta Was this translation helpful? Give feedback.
After this change the Pyboard works and with:
(from the docs) the flash filesystem displays a size of 304 (or 368) kB.
I did tests of the filesystem which passed. The test is in attached
fs_test.py
.After being successful with this I compiled a version with 368 kB of flash filesystem, that also passed the tests.
Test run and result: