Cross compiled module vs class inheritance

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
danielm
Posts: 167
Joined: Mon Oct 05, 2015 12:24 pm

Cross compiled module vs class inheritance

Post by danielm » Fri Nov 04, 2016 8:53 am

I am developing HVAC device controller board based on CC3200. Because of limited RAM resources I had to put most of the code into cross-compiled module containing one class which I instantiate in main.py and call function with main loop. Because of the fact that uploading .py files to Linux server, cross-compiling and downloading it to the MP host takes some time and also because not all error messages are displayed when errors are caused by cross-compiled code I removed main loop function from the cross-compiled module and created new class in main.py which is inherited from class from cross-compiled module and which defines the main loop function. When the main loop function will be fully developed, I will probably put it back into the class in cross-compiled module.

The question is - can I expect some issues from this approach?

User avatar
pythoncoder
Posts: 4665
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Cross compiled module vs class inheritance

Post by pythoncoder » Sat Nov 05, 2016 6:32 am

I can't give a definitive answer because I haven't done exactly what you're trying to do. However I use frozen bytecode (which is cross-compiled) on the Pyboard and routinely freeze stable code on big projects. I've subclassed frozen classes and had frozen modules import classes from regular modules and it all "just works". You could create a simple test case or use git to branch your project to try it and see if it works. I'd be surprised if it didn't.
Peter Hinch

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

Re: Cross compiled module vs class inheritance

Post by Roberthh » Sat Nov 05, 2016 7:37 am

I'm using this works-stream all the time, especially with ESP8266 and also for code embedded in flash. I have not observed that messages are not displayed. The only hiccup that happens from time to time is mpy-cross not being up-to-date. So I typically rebuild it after a repository update.

danielm
Posts: 167
Joined: Mon Oct 05, 2015 12:24 pm

Re: Cross compiled module vs class inheritance

Post by danielm » Sun Nov 13, 2016 6:44 pm

Thank you for your answers. I am working with CC3200 so unfortunately I cannot use frozen bytecode from flash. But it is good to know it works also in this case.
I am using this approach for several days and there were no issues directly related to inheriting classes from cross-compiled modules.

@pythoncoder, could you share some more info what do you mean by "big projects"? Are you developing some product based on MicroPython?

User avatar
pythoncoder
Posts: 4665
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Cross compiled module vs class inheritance

Post by pythoncoder » Mon Nov 14, 2016 11:13 am

@danielm I use the term "big" relative to the capabilities of the platform. I'm long retired and my projects are entirely amateur. My largest Pyboard project is this touch GUI https://github.com/peterhinch/micropython-tft-gui.git (a collaboration with @roberthh) which requires modules to be frozen to fit available RAM.

I've used frozen bytecode on other projects including the e-paper display for the Pyboard https://github.com/peterhinch/micropython-epaper.git and intend shortly to release a (hopefully generic) way to convert fonts to Python source which can then optionally be frozen as bytecode - all done except for the docs. So I've been a heavy user of frozen bytecode which I regard as an awesome feature of MicroPython :)

On the ESP8266 I attempted a project to use an ESP as an interface to bring stable MQTT to the Pyboard. Owing to the limited RAM on the ESP8266 this too required modules such as the scheduler https://github.com/peterhinch/Micrasopy ... eduler.gitto be frozen. Alas this project failed to achieve acceptable reliability owing to my lack of network experience. I abandoned it after three months effort and so have not posted code. However I can say with some confidence that frozen bytecode works fine on the ESP8266 (and of course the Pyboard).
Peter Hinch

Post Reply