stinos / micropython-wrap Goto Github PK
View Code? Open in Web Editor NEWAPI for interop between C/C++ and MicroPython
License: MIT License
API for interop between C/C++ and MicroPython
License: MIT License
Following the instructions to integrate and build with Micropython custom fork, I used the sample code from micropython-wrap's readme to try and add the module and sample Makefile lines from the fork's readme to assemble the shared library. I also changed the name of the registration function to initxxx()
and init_xxx()
in my attempts to get it to work.
.so file is in the ~/.micropython/lib directory, micropython unix port is built, but the module is not accessible. There's definitely something I'm missing.
Probably an exhaustive Hello World tutorial would help.
The various make
options fail to complete or pass on Ubuntu 20.04.
Prep:
clone micropython
Build works. All tests pass.
Download the wrapper:
clone micropython-wrapper (beside micropython repo)
make sharedlib
: builds
make staticlib
" fails with the same include error multiple times:
In file included from ./mpconfigport.h:31,
from ../../py/mpconfig.h:62,
from ../../py/obj.h:31,
from /home/jeff/code/micropython-wrap/tests/cmodule.c:1:
variants/standard/mpconfigvariant.h:34: error: "MICROPY_MODULE_BUILTIN_INIT" redefined [-Werror]
34 | #define MICROPY_MODULE_BUILTIN_INIT (0)
|
<command-line>: note: this is the location of the previous definition
In file included from ./mpconfigport.h:31,
from ../../py/mpconfig.h:62,
from ../../py/obj.h:31,
from ../../py/opmethods.c:27:
variants/standard/mpconfigvariant.h:34: error: "MICROPY_MODULE_BUILTIN_INIT" redefined [-Werror]
34 | #define MICROPY_MODULE_BUILTIN_INIT (0)
|
<command-line>: note: this is the location of the previous definition
... repeats many, many times
make testsharelib
: builds, but all tests fail:
MICROPY_MICROPYTHON=../micropython/ports/unix/micropython \
python3 ../micropython/tests/run-tests.py --keep-path -d /home/jeff/code/micropython-wrap/tests/py
FAIL /home/jeff/code/micropython-wrap/tests/py/class.py
FAIL /home/jeff/code/micropython-wrap/tests/py/classref.py
FAIL /home/jeff/code/micropython-wrap/tests/py/context.py
FAIL /home/jeff/code/micropython-wrap/tests/py/cpp.py
FAIL /home/jeff/code/micropython-wrap/tests/py/classnt.py
FAIL /home/jeff/code/micropython-wrap/tests/py/finalizer.py
FAIL /home/jeff/code/micropython-wrap/tests/py/exception.py
FAIL /home/jeff/code/micropython-wrap/tests/py/errorcode.py
FAIL /home/jeff/code/micropython-wrap/tests/py/map.py
FAIL /home/jeff/code/micropython-wrap/tests/py/qualifier.py
FAIL /home/jeff/code/micropython-wrap/tests/py/nargs.py
FAIL /home/jeff/code/micropython-wrap/tests/py/tuple.py
FAIL /home/jeff/code/micropython-wrap/tests/py/function.py
FAIL /home/jeff/code/micropython-wrap/tests/py/optional.py
FAIL /home/jeff/code/micropython-wrap/tests/py/numeric.py
FAIL /home/jeff/code/micropython-wrap/tests/py/string.py
FAIL /home/jeff/code/micropython-wrap/tests/py/variables.py
FAIL /home/jeff/code/micropython-wrap/tests/py/vector.py
18 tests performed (169 individual testcases)
0 tests passed
18 tests failed: class classnt classref context cpp errorcode exception finalizer function map nargs numeric optional qualifier string tuple variables vector
make: *** [Makefile:98: testsharedlib] Error 1
Dear @stinos,
thank you very much for conceiving and maintaining this fine piece of software.
I am currently thinking about whether it might be possible to use it in order to bring the excellent TinyGSM library to the world of MicroPython.
Within [1], you are saying that it has been tested on Unix and Windows, so I am wondering if there would be a chance to also use it on the ESP32 port for MicroPython.
I am aware there surely will be some intrinsic things to care about regarding runtime interaction with FreeRTOS and such aka. "the devil is in the details" when actually starting this endeavor. I just wanted to bring up the idea in general and to get some feedback whether you believe the undertaking could be feasible in general.
Thanks already for taking the time!
With kind regards,
Andreas.
Hello - thank you for providing this awesome solution for adding capabilities to micropython. I have cloned the repo and used "make teststaticlib" successfully. I wanted to move on to an uncomplicated class to use as practice before implementing a more complicated class. However, I'm having trouble implementing this on even the uncomplicated class. I've tried to correct my code based on the compiler errors displayed. But, I'm still missing something.
The uncomplicated class I would like to practice wrapping is from https://github.com/sdumetz/coordinates/tree/master/src
The header file is:
#ifndef _Coordinates_h
#define Coordinates_h
#include "math.h"
#ifndef PI
#define PI 3.1415926535897932384626433832795
#endif
class Coordinates {
public:
// start value, start speed, update confidence, evolution confidence
Coordinates(float x = 0, float y = 0);
void fromCartesian(float x, float y);
void fromPolar(float r, float phi);
float getR() {
return r;
};
float getAngle() {
return phi;
};
float getX() {
return x;
};
float getY() {
return y;
};
private:
float r;
float phi;
float x;
float y;
};
#endif
Could you help point me in the right direction on how I can wrap this class? Maybe I can write up a tutorial based on the help that you give me. Once I get the right idea, I'm hoping to create a few more tutorials to help those interested.
Thank You
Trying to use this lib, it seems it is only compatible with an old version of micropython where mp_obj_fun_builtin_fixed_t
and mp_obj_fun_builtin_fixed_t
where still part of py/obj.h
So I was wondering which version of micropython works with this lib and how big was the delta to make it work against a recent micropython.
Hi everyone.
I noticed issue #5. I work with micropython under Ubuntu. Some installation commands in ubuntu_install.zip
I can compile examples from esp-idf and mpy-cross from micropython.
I try to compile micropython ESP32 port with modules.
modules.zip
The directory structure is:
$(HOME)/
| esp-idf
| micropython
| micropython-wrap
| modules
I added
INC += -I$(HOME)
to the micropython/ports/esp32/Makefile.
The micropython-wrap is switched to ESP32-C++ branch.
The micropython is switched to git hash (v3.3): 9e70825d1e1cbf7988cf36981774300066580ea7.
The 'example' module and 'temperature_conversion' module are compiled well and work after flashing 'firmware.bin' to the ESP32 generic board.
(build-venv) pc@ubuntu:~/micropython/ports/esp32$ make USER_C_MODULES=../../../modules all
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
Including User C Module from ../../../modules/temperature_conversion
Including User C Module from ../../../modules/example
Building with ESP IDF v3
GEN build-GENERIC/genhdr/qstrdefs.collected.h
QSTR not updated
GEN build-GENERIC/genhdr/compressed.collected
Compressed data not updated
AR build-GENERIC/esp-idf/esp32/libesp32.a
LINK build-GENERIC/application.elf
text data bss dec hex filename
1099596 278868 37380 1415844 159aa4 build-GENERIC/application.elf
Create build-GENERIC/application.bin
esptool.py v2.8
Create build-GENERIC/firmware.bin
bootloader 21344
partitions 3072
application 1378592
total 1444128
Compiling with 'foo' module gets errors:
(build-venv) pc@ubuntu:~/micropython/ports/esp32$ make USER_C_MODULES=../../../modules all
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
Including User C Module from ../../../modules/foo
Including User C Module from ../../../modules/temperature_conversion
Including User C Module from ../../../modules/example
Building with ESP IDF v3
GEN build-GENERIC/genhdr/qstrdefs.collected.h
QSTR not updated
GEN build-GENERIC/genhdr/compressed.collected
Compressed data not updated
CC ../../../modules/foo/foo.c
In file included from /home/pc/micropython-wrap/detail/frompyobj.h:4:0,
from /home/pc/micropython-wrap/detail/callreturn.h:4,
from /home/pc/micropython-wrap/functionwrapper.h:4,
from ../../../modules/foo/foo.c:1:
/home/pc/micropython-wrap/detail/micropython.h:7:8: error: expected identifier or '(' before string constant
extern "C"
^
In file included from /home/pc/micropython-wrap/detail/frompyobj.h:4:0,
from /home/pc/micropython-wrap/detail/callreturn.h:4,
from /home/pc/micropython-wrap/functionwrapper.h:4,
from ../../../modules/foo/foo.c:1:
/home/pc/micropython-wrap/detail/micropython.h:24:17: fatal error: cmath: No such file or directory
#include <cmath>
^
compilation terminated.
make: *** [../../py/mkrules.mk:63: build-GENERIC/foo/foo.o] Error 1
I see cmath files.
They notated with:
// -- C++ -- C forwarding header.
Where can I add the include path?
Thanks.
Hello,
Does this wrapper support keyword arguments in functions as described here?
The closest I've found is optional variables, but that dosen't provide the same level of verbosity when passing arguments.
Thanks!
I ran make usercmodule MICROPYTHON_PORT_DIR=../micropython/ports/esp32
This creates a new binary, i flashed the binary to the chip, but how do i use the usercmodule?
I tried to import mod, foo, upywraptest etc. but it does not work?
Hey there
I noticed issue #3 , however that issue is closed and yet I don't think that support for ESP32 is resolved, so I'm adding a new issue here. If indeed this does work on ESP32, then this might become an instructive log of how to do that. Otherwise, I hope we can find the issues :).
When simply trying to call make MICROPYTHON_PORT_DIR=../micropython/ports/esp32
we get:
make -C ../micropython/ports/esp32 BUILD=build MICROPY_PY_BTREE=0 MICROPY_PY_FFI=0 MICROPY_PY_USSL=0 MICROPY_PY_AXTLS=0 MICROPY_FATFS=0 MICROPY_PY_THREAD=0 USER_C_MODULES=/mnt/c/dev/micropython-wrap CFLAGS_EXTRA="-DMODULE_UPYWRAPTEST_ENABLED=1 -DMICROPY_MODULE_BUILTIN_INIT=1" build/genhdr/qstrdefs.generated.h
make[1]: Entering directory '/mnt/c/dev/micropython/ports/esp32'
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
Including User C Module from /mnt/c/dev/micropython-wrap/tests
Building with ESP IDF v4
fatal: No names found, cannot describe anything.
../../py/mkrules.mk:80: *** mixed implicit and normal rules: deprecated syntax
../../py/mkrules.mk:116: *** mixed implicit and normal rules: deprecated syntax
make[1]: *** No rule to make target '%.c,', needed by 'build/genhdr/qstr.i.last'. Stop.
make[1]: Leaving directory '/mnt/c/dev/micropython/ports/esp32'
Makefile:49: recipe for target 'staticlib' failed
make: *** [staticlib] Error 2
when trying with sharedlib
it will start to complain about missing includes.
It's easy enough to add these to the include path.
After that we then receive many many many errors:
https://gist.github.com/elliotwoods/c2378981fdb1b154b37d111f58eaaa4c
(This may be what you're referring to with but the problem is dynruntime.h does not yet implement the complete API and as such micropython-wrap won't compile with it.
)
In my case I'm just trying to build the tests first and then will try with my own code.
I've also made an issue over at:
micropython/micropython#6233
Thank you
Elliot
Hi All,
I have done fleet previsioning for AWS IOT with Mbedtls library, Now i have move to Wolfssl library, so can you please provide the appropiate SDK or PKCS11 library. It will be great if we get the sample exaple of PKCS11 with wolfssl.
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.