Support loading of .mpy files

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Support loading of .mpy files

Post by dhylands » Fri Oct 21, 2016 4:08 pm

Lornioiz wrote:
[So regular bytecode takes up RAM where frozen bytecode doesn't.
Thank you very much Dave,

That means that in a esp8266 I can import as much modules as I want (by the import statement) without using any ram if they are saved in the firmware? just curious, how severe is the speed penalty in doing so (I'm thinking about freezing as much of the application I can by splitting it in various modules)?
Without using any ram for the bytecode. The act of doing an import also executes the bytecode which may allocate RAM. I haven't played with the esp8266, so I'm not familiar enough to know whether there would be any speed penalty or how much it would be. On the pyboard there should be no penalty.

warren
Posts: 74
Joined: Tue Jul 12, 2016 5:47 pm

Re: Support loading of .mpy files

Post by warren » Tue Nov 08, 2016 3:09 pm

Thanks to the developers for the ongoing development work...

It would be #hugely# helpful if someone could just post some simple instructions:

-- How to compile to mpy files

-- Where to put the mpy files so that they get frozen into the firmware build...

I note that in the discussion on the original PR, Hosaka said "The mpy-cross commit is long awaited and it would be great to see this finally added! Some docs to go along with it for the esp8266 might be due as well."

( https://github.com/micropython/micropython/pull/2502 )

Did I miss something - are there already such docs for this hugely significant addition?

Although I suspect that I can figure this out , I really feel that uPython on the ESP8266 is not getting as enthusiastic an uptake as it should simply because it takes so much research time to find out things that to the developers / more advanced users are "obvious"..

Thanks in advance.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Support loading of .mpy files

Post by Roberthh » Tue Nov 08, 2016 7:28 pm

If you build the image, you can simply put your python sources in the modules subdirectory for that build, e.g. esp8266/modules or stmhal/modules. The compilation is then called by the Makefile. The compiler is mpy-cross in mircopython/mpy-cross. YOu have to make it before you create an image for the target platform.
mpy-cross can be used independently fro the make. You need that to create .mpy files for WiPy, where these are not integrated in the flash image. On WiPy, using .mpy file sis still an advantage, because you can use code that is too large for being compiled within Wipy itself.
You can also simply copy an .mpy file into the file systems of esp8266 or PyBoard, from where they can be imported for execution.
The difference: If you put the frozen bytecode into flash, they will consume way less RAM, because the code stays in flash. If you execute them from the file system, the code will be in RAM. On esp8266, code in flash runs a little bit slower.

warren
Posts: 74
Joined: Tue Jul 12, 2016 5:47 pm

Re: Support loading of .mpy files

Post by warren » Thu Nov 10, 2016 12:53 pm

Roberthh wrote:If you build the image, you can simply put your python sources in the modules subdirectory for that build,
I do beg your pardon, I now realise that I was not so clear. I thought that since the announcement of the mpy files possibility, I had to do something different from before...

I now see that nothing is different - what you explain is what I have been doing before - putting code into the 'modules' sub directory. It's just that now they are automatically pre-compiled when you MAKE.

Thanks - good stuff!

Post Reply