Toolchain bindings in mpy files

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
pulkin
Posts: 49
Joined: Tue Feb 19, 2019 10:22 pm

Toolchain bindings in mpy files

Post by pulkin » Tue Mar 02, 2021 8:24 pm

Hi,

How do I create mpy module with bindings to IDF API? What needs to be included into Makefile or example?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Toolchain bindings in mpy files

Post by jimmo » Wed Mar 03, 2021 5:45 am

pulkin wrote:
Tue Mar 02, 2021 8:24 pm
How do I create mpy module with bindings to IDF API? What needs to be included into Makefile or example?
Unfortunately .mpy files cannot access any functions other than what's in dynruntime.h. At this stage they're mostly intended for writing high performance self-contained functionality in C.

The problem is that the IDF functions don't actually exist on the device at runtime (because only the ones used by hte micropython firmware will be linked into the final binary). Additionally, your .mpy file knows nothing about the layout of the code in the micropython firmware - the only thing it knows is the location of the functions in dynruntime.h (via a lookup table).

On a full operating system, this is all solved by the linker and loader, but MicroPython (for space and efficiency reasons) doesn't have this.

For more details (and a proposed solution), see https://github.com/micropython/micropython/pull/5711

Post Reply