n-elia / MAX30102-MicroPython-driver

A Maxim MAX30102 driver ported to MicroPython. It should also work for MAX30105.
MIT License
56 stars 21 forks source link

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

Closed n-elia closed 1 year ago

n-elia commented 1 year ago

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.