mpy-cross general

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Posts: 12
Joined: Sun Apr 26, 2020 3:36 pm

mpy-cross general

Post by ttadam » Mon Nov 30, 2020 5:16 pm

Hello there,

I didn't find any general discussion about this this tool/method so I took the bravery and opened one.
Currently I am running into all kind of memory allocation issues, and my idea is to use precompiling, like mpy-cross.
The issue is that I don't really find a good tutorial/step-by-step guide where I understand how can run .mpy files instead of .py files on my esp32.

My other question that I found some hints that micropython also has mpy-cross library. Is it possible that esp32 does the precompiling, and just write a the .mpy files to flash. (I use github and OTA library, and it would easier to maintain a .py repo than a .mpy repository)


User avatar
Posts: 4792
Joined: Fri Jul 18, 2014 8:01 am
Location: UK

Re: mpy-cross general

Post by pythoncoder » Tue Dec 01, 2020 9:44 am

If you're not using architecture-specific options like assembler or the native or viper decorators, mpy-cross "just works". The .mpy file just needs to be copied to the target. Delete the .py file on the target. And it should just run.

If it doesn't please post the exact output when you try.

I didn't entirely follow the second part of your question. The point of mpy-cross is to avoid the need for the ESP32 to compile your code. This copes with the case where the target runs out of RAM during compilation. It can't help if your program uses too much RAM at runtime.

You must be doing something quite substantial to run out of RAM on an ESP32. The "nuclear option" is frozen bytecode which I've used extensively on ESP8266 and STM. This definitely helps with runtime problems but I've yet to find the need on an ESP32.
Peter Hinch

Post Reply