Native machine code in .mpy files : question

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
picpic020961
Posts: 15
Joined: Thu Feb 18, 2021 4:24 pm

Native machine code in .mpy files : question

Post by picpic020961 » Fri Apr 16, 2021 9:05 am

Bonjour,

in this link , how to make c module as .mpy file. this file is then 'import' in micropython repl : fine and easy.

https://docs.micropython.org/en/latest/ ... tml#natmod

is it possible for all c module ? for example

https://github.com/russhughes/st7789_mpy

avoid to generate firmware.bin and flash.

thanks for informations.

Regards

User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: Native machine code in .mpy files : question

Post by russ_h » Fri Apr 16, 2021 4:52 pm

I tried, when the native modules were released, but I was not able to make it work. I ran into to the linker limitation described in the docs:
Linker limitation: the native module is not linked against the symbol table of the full MicroPython firmware. Rather, it is linked against an explicit table of exported symbols found in mp_fun_table (in py/nativeglue.h), that is fixed at firmware build time. It is thus not possible to simply call some arbitrary HAL/OS/RTOS/system function, for example.

New symbols can be added to the end of the table and the firmware rebuilt. The symbols also need to be added to tools/mpy_ld.py’s fun_table dict in the same location. This allows mpy_ld.py to be able to pick the new symbols up and provide relocations for them when the mpy is imported. Finally, if the symbol is a function, a macro or stub should be added to py/dynruntime.h to make it easy to call the function.
I have not tried to build the driver as a native module since. I'll look into it.

picpic020961
Posts: 15
Joined: Thu Feb 18, 2021 4:24 pm

Re: Native machine code in .mpy files : question

Post by picpic020961 » Wed Apr 28, 2021 7:36 pm

Bonjour Russ ,
Some news about this subject ?
Regards

User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: Native machine code in .mpy files : question

Post by russ_h » Thu Apr 29, 2021 8:03 pm

Not yet.

Post Reply