.py in flash problem

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
stackYuan
Posts: 1
Joined: Wed Feb 12, 2020 3:48 am

.py in flash problem

Post by stackYuan » Wed Feb 12, 2020 4:04 am

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?

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

Re: .py in flash problem

Post by jimmo » Wed Feb 12, 2020 6:54 am

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

Post Reply