1. 样例路径。
官方添加C模块例子在:micropython-1.19.1/examples/usercmodule路径中。
2.编译
make USER_C_MODULES=../../examples/usercmodule BOARD=MY_STM32F429DISC V=1
编译过程中可能遇到这个问题:
../../examples/usercmodule/cppexample/example.cpp:14:40: error: 'MP_QSTR_hellocpp' was not declared in this scope; did you mean 'MP_QSTR_help'?
14 | mp_obj_t tup[] = {sum, MP_ROM_QSTR(MP_QSTR_hellocpp)};
把cppexample文件夹中的 micropython.mk改为micropython.mk.bk
3.烧录firmware.hex。
查看模块:
help('modules')
![在这里插入图片描述](https://img-blog.csdnimg.cn/c9d4561387e94a2ba0fdddb952141841.png)
运行结果:
![在这里插入图片描述](https://img-blog.csdnimg.cn/3160cefb776c44598983d764257ac666.png)