Adding python files and folders to build

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
bborncr
Posts: 4
Joined: Wed Jun 29, 2022 2:33 pm

Adding python files and folders to build

Post by bborncr » Fri Jul 01, 2022 4:04 pm

I see that the "boot.py" file that is preinstalled in firmware builds is created in "modules/inisetup.py".
It there an easier way to add preinstalled folders and example files to the build?

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

Re: Adding python files and folders to build

Post by jimmo » Mon Jul 04, 2022 1:42 am

bborncr wrote:
Fri Jul 01, 2022 4:04 pm
It there an easier way to add preinstalled folders and example files to the build?
There are two ways to do this -- either you can "freeze" Python code into the firmware, or you can pre-load them onto the filesystem. Freezing is far superior because it means that the module executes from ROM and doesn't use any RAM to load the bytecode.

If you're customising the build (e.g. by adding frozen modules), the way to do this is to write a custom board definition (e.g. ports/PORT/boards/BOARD. Start with a copy of the existing one, and you can modify manifest.py to add your own files. Note that your own board definition directory doesn't have to live in the micropython repo.

See example board definitions here: https://github.com/micropython/micropyt ... ple-boards
See docs on manifest.py here: https://docs.micropython.org/en/latest/ ... ifest.html

Post Reply