MicroPython external C modules

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
Herve
Posts: 3
Joined: Tue Jun 04, 2019 3:46 pm

MicroPython external C modules

Post by Herve » Tue Jun 04, 2019 3:53 pm

Hi everybody.
I have an esp32 and i would like to add external C modules.
I followed this instructions : https://docs.micropython.org/en/latest/ ... dules.html
The compilation work but it's impossible to import the module in the prompt microPython.


>>> import example
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'example'


If anybody has a solution or a idea, i take it.

Thanks all.

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

Re: MicroPython external C modules

Post by jimmo » Tue Jun 04, 2019 10:18 pm

Are you able to post your code (e.g. to github).

Can you verify that your module is definitely being linked into the final firmware image (e.g. use nm or objdump).

Herve
Posts: 3
Joined: Tue Jun 04, 2019 3:46 pm

Re: MicroPython external C modules

Post by Herve » Wed Jun 05, 2019 8:20 am

I found the solution.

The command : " make USER_C_MODULES=../../../modules CFLAGS_EXTRA=-DMODULE_EXAMPLE_ENABLED=1 all " dosen't work.
You need to add " #define MODULE_EXAMPLE_ENABLED (1) " to the mpconfigport.h and do " " make USER_C_MODULES=../../../modules all" and now it's work !!

Thanks for your answer and sorry to distrubed you.

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

Re: MicroPython external C modules

Post by jimmo » Thu Jun 06, 2019 10:17 am

Herve wrote:
Wed Jun 05, 2019 8:20 am
The command : " make USER_C_MODULES=../../../modules CFLAGS_EXTRA=-DMODULE_EXAMPLE_ENABLED=1 all " dosen't work.
Are you using ESP32 by any chance?

For some reason the ESP32 makefile doesn't use CFLAGS_EXTRA. I don't have an ESP32 board or the ESP32 toolchain set up but maybe you could send a PR?

Post Reply