0

I'm using ESP32 with MicroPython with Mu. I need more flash space for my code and normally I would select "Huge APP" in the Arduino menu and that would remove the OTA and spiffs.

How can I do that with MicroPython firmware? I can imagine, it will be possible through the terminal, with esptool.py or Ampy, but can't figure it out.

Thanks

3 Answers 3

4

There is no easy way to change the partitions in MicroPython. You will need to modify the partition table and compile MicroPython from source. Here is how you can set up a MicroPython build environment using Ubuntu 20.04.2. You can use the Windows Subsystem for Linux version 2's Ubuntu 20.04.2 as well.

Update and upgrade Ubuntu using apt-get if you are using a new install of Ubuntu or the Windows Subsystem for Linux.

sudo apt-get -y update
sudo apt-get -y upgrade

Use apt-get to install the required build tools.

sudo apt-get -y install build-essential libffi-dev git pkg-config cmake virtualenv python3-pip python3-virtualenv

Use git to clone the esp-idf SDK repo & install -- this will take a while.

git clone --recursive https://github.com/espressif/esp-idf.git
cd esp-idf/
./install.sh

Source the esp-idf export.sh script to set the required environment variables. It's important that you source the file and not run it using ./export.sh. You will need to source this file before compiling MicroPython.

source export.sh
cd ..

Use git to clone the MicroPython repo.

git clone https://github.com/micropython/micropython.git

Update the git submodules and compile the MicroPython cross-compiler

cd micropython/
git submodule update --init
cd mpy-cross/
make
cd ..
cd ports/esp32

You can change the ESP32 partition sizes by editing the partitions.csv file in ports/esp32. There are a few things you should be aware of when changing the partitions.csv file. The factory partition is where the MicroPython application resides. This partition must be large enough for the MicroPython firmware and it must be placed at offsets aligned to 0x10000 (64K). The vfs partition is where the virtual file system is located.

The generic partitions.csv file is configured for a 4MB flash device and looks like this:

Default partitions.csv file contents

# Notes: the offset of the partition table itself is set in
# $IDF_PATH/components/partition_table/Kconfig.projbuild.
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 0x180000,
vfs,      data, fat,     0x200000, 0x200000,

The factory partition starts at 0x10000 (aligned to 64K as required) and has a size of 0x180000. This places the end of the factory partition at (0x10000 + 0x180000) or 0x190000. The next partition is the vfs partition, it starts at 0x200000 (2MB) and has a size of 0x200000 (2MB). This leaves 0x200000 - 0x190000 = 0x70000 or 448K bytes of unused flash between the end of the factory partition and the start of the vfs partition. Adding the unused flash to the factory partition results in a new factory partition size of 0x180000 + 0x70000 = 0x1F0000 or 64K less than 2MB.

Modified partitions.csv file contents

# Notes: the offset of the partition table itself is set in
# $IDF_PATH/components/partition_table/Kconfig.projbuild.
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 0x1F0000,
vfs,      data, fat,     0x200000, 0x200000,

If more 'factory' flash space is required, you can decrease the size of the vfs partition and increase it's offset by the same amount then add the newly freed space to the factory partition.

Modified partitions.csv file contents for a 3MB factory partition and a 960K virtual file system partition.

# Notes: the offset of the partition table itself is set in
# $IDF_PATH/components/partition_table/Kconfig.projbuild.
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 0x300000,
vfs,      data, fat,     0x310000, 0xF0000,

Once you have your partition sizes worked out, build the MicroPython firmware.

make all

The firmware.bin file will be in the build-GENERIC directory. If you have been running other firmware or have modified the partition table you must erase before you flash the new firmware to your device. Set PORT= to the ESP32's usb serial port.

make PORT=/dev/ttyUSB0 erase
make PORT=/dev/ttyUSB0 deploy

At this point you should have MicroPython running on your ESP32 device using the new partition sizes. You can connect to the REPL over the usb port using:

make PORT=/dev/ttyUSB0 monitor
Sign up to request clarification or add additional context in comments.

2 Comments

would you possibly also add a good partition table for 16MB flash / spiram?
As of 2025 there is no partitions.csv file there. There are some default files for various flash sizes, but that begs the question how you tell the µPy build process how large your flash is.
1

I have been messing around with the same thing just not really there yet.

I have found an option here for different firmware stuff : https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo

There are some pre built firmware options you can select and I have found most of their stuff really useful.

If that is not what you are looking for I think you are going to need to change the partition layout with an option in esptool.

Make sure the ESP you are using has the correct flash size allocations obviously first. ( Some can have external chips I have found, not sure what board you are using )

I have never done that before so I am not qualified to give you info on it.

1 Comment

the LoBo fork was great, but is currently quite stale and not maintained any more. most (but not all) features have now found their way into better maintained families.
0

the simplest option is to use an ESP32 with SPIRAM and use one of the firmwares that support that.
While LoBo was the first, this is now well supported by most MicroPython families.

https://micropython.org/download/esp32/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.