Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module pre-compile to fix some import errors #19

Merged
merged 5 commits into from
Feb 7, 2023
Merged

Conversation

n-elia
Copy link
Owner

@n-elia n-elia commented Feb 7, 2023

Due to the lack of memory, some boards are not able to properly load this module.

As explained in the official MicroPython docs, when a module is imported, MicroPython compiles the code to bytecode which is then executed by the MicroPython virtual machine. The bytecode is stored in RAM and the compiler itself temporarily requires RAM! Thus, the situation can arise where there is insufficient RAM to run the compiler. In this case the import statement will produce a memory exception.

A viable solution is to precompile modules, such that the compiler will not need RAM space. MicroPython has a cross compiler capable of compiling Python modules to bytecode (mpy-cross). The resulting bytecode file has a .mpy extension and it may be copied to the filesystem and imported in the usual way.

A better option is to make your own firmware and implement the module as frozen bytecode, because on most platforms this saves even more RAM as the bytecode is run directly from flash rather than being stored in RAM.

This PR introduces a GitHub Workflow that pre-compiles the module and uploads the .mpy files as artifacts.

@n-elia n-elia merged commit 9f70485 into main Feb 7, 2023
@n-elia n-elia deleted the add-freezed-module branch February 7, 2023 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant