Page 1 of 1
Native machine code in .mpy files : question
Posted: Fri Apr 16, 2021 9:05 am
by picpic020961
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
Re: Native machine code in .mpy files : question
Posted: Fri Apr 16, 2021 4:52 pm
by russ_h
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.
Re: Native machine code in .mpy files : question
Posted: Wed Apr 28, 2021 7:36 pm
by picpic020961
Bonjour Russ ,
Some news about this subject ?
Regards
Re: Native machine code in .mpy files : question
Posted: Thu Apr 29, 2021 8:03 pm
by russ_h
Not yet.