Page 1 of 1

.py in flash problem

Posted: Wed Feb 12, 2020 4:04 am
by stackYuan
Hi, I just want to make .py into the MCU's flash instantly without port communications (within 'preloaded' into flash when I'm flashing MCUs).
But I can't figure out how to do so,,, I searched things like "frozen, freeze" or something can make it happen, and I didn't get any examlpe or method to deal with that. :(
how can I make .py transferred into .c like cpython or whatever to make it happen? Or how can I make .py into .mpy and preincluded in my project, without port comm can still run .mpy?

Re: .py in flash problem

Posted: Wed Feb 12, 2020 6:54 am
by jimmo
Hi,

It sounds like what you want is to "freeze" your Python code into the firmware, so that the firmware image includes everything. The way this works is you need to build MicroPython from source, and define (or modify) a manifest.py file that includes your Python files. An example of this is the TinyPico board (ports/esp32/boards/TINYPICO) which includes some default libraries when you build the firmware.

The general idea is that:
- You build with "make BOARD=FOO", where FOO is a directory ports/PORT/boards/FOO.
- Inside FOO/mpconfigboard.mk, it says which FROZEN_MANIFEST to use, which is a Python script that tells the build what to include.
- Generally this tells it to look in PORT/modules, so a simple way to get this to work is to put your Python files there, but it's best to define your own board config. (Note that a board config can be outside of the main repo, so you can version it separately if you want).

Alternatively you can build a firmware image that includes a pre-built filesystem. There was some discussion of that here : viewtopic.php?f=16&t=6677