New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for ESP32 #5
Comments
I have close to zero experience with ESP32 and it's build, but at first sight the errors in that gist seem to originate from the ESP headers not being valid C++. But I'm not sure if it makes any sense trying to build a shared library for ESP: does it support dynamic loading? I.e. does it have a working implementation of dlfcn.h? That doesn't explain the problem with the staticlib target though, but I also don't know a lot about about Makefiles so cannot decipher that error. If you're genuinely interested in getting this to work, I can have a look into it though. But you'll have to help me out a bit then: how do I setup a build environment for ESP32? |
@stinos - thank you so much for offering to help I'm unsure whether ESP32 supports dynamic linking I'd be very happy to help you get set up with ESP-IDF for testing micropython-wrap with it Which platform are you building on? I'm testing here on Ubuntu (WSL) |
dlfcn.h is a system header i.e. comes with compiler and/or OS, it's not part of MicroPython: https://linux.die.net/man/3/dlopen I can build on WSL or standard Ubuntu, anything which works. I missed your pevious comment wrt SRC_USERMOD_CPP though; so please lay out as detailed as possible what your build environment looks like and what you utlimately want to do (I assume wrapping some C++ library? Which one?). I'd be happy to spend some time on this because I have a feeling that if it works for ESP32 most problems for other microcontroller ports will also be solved. However, I don't exactly have a lot of time so cannot make promises when that will happen :) |
Ah I'm sorry that comment was on the wrong issue. I'll remove it here The c++ library which I'm trying to wrap is Tensorflow Lite Micro for inference locally on the ESP32
There are notes on how this code looks at: So I presume something like
To build for esp32 get the correct version of esp-idf running: git clone https://github.com/espressif/esp-idf.git --depth 1
cd esp-idf
git pull origin 4c81978a3e2220674a432a588292a4c860eef27b
git checkout 4c81978a3e2220674a432a588292a4c860eef27b
git submodule init
git submodule update --recursive
./install.sh
source ./export.sh esp-idf paths will now be correctly set (just repeat the final step there next time you start a new bash session) build the mpy-cross compiler (can't remember where you do this) make -C mpy-cross now if you go to the |
btw .. |
@elliotwoods was looking into this, but as you figured it does require changes to the core makefiles to get C++ code compiled (for the unix port I'm circumventing that because the compilation is fairly simple and requires only a couple of extra flags/include directories - in other words, the Makefile here is really only for the unix port or something similar enough). Moreover I cannot even build the example user C module per the instructions in cmodules.rst, so that makes it pretty hard to do much for this issue. However I did build the test code (module.cpp) into an ESP32 application by adding the file manually, so my initial idea ('if you have a C++ compiler it should work') still seems to hold. Didn't test it as I don't have an ESP32 though. Diff against current master:
Then build with
Let me know if this is useful. |
@elliotwoods ok today, out of nowhere, I could build 'user C modules' again so here's an alternative solution:
|
I had some success building CPP also, but using custom build scripts to make the cpp files and some hacks of the existing micropython makefiles. Howeveer I didn't get it working with your build process / library Sadly since i got this working I've moved onto something else so don't have much time right now to check your solution (reading through it here, i think i need to spend more time to fully understand it) however i can test your firmware on my esp32 if you want me to test your module here runs correctly |
And thank you again for looking into this! I really like your library and hope to use it for future projects when I'm wrapping for micropython |
@elliotwoods ok, no problem. See files here. If you can run something like
it's good. |
it fails to boot and keeps restarting I'm trying with firmware.bin which is the standard thing i usually upload
|
using command |
I've never seen that happen before my partitions.csv looks like this:
|
@elliotwoods thanks for trying this out; as I don't have any experience with such issues nor ESP32 I don't really know what to do here; keep in mind this is a build for the 'GENERIC' board definition, maybe that is an issue? Anyway might be easier if you build locally: pull esp32-c++ branch of this repository, and esp32-c++ branch from my MicroPython fork https://github.com/stinos/micropython which (a least for me) work out of the box after having followed your instructions to get the esp SDK as above. Then with a directory structure like
cd to the ports/esp32 directory and build with (possibly add a board definition etc)
|
Alright! I’ll check that tomorrow. Out of office now (Seoul GMT+8) |
getting the same issue building here |
removing the |
Hmm, that's strange, as I'm only a couple of commits away from master I'd also think it's a MicrpPython problem then. Can you create an issue for it? |
i'm trying current master now to check... (old master does work here) |
and your branch of micropython works when i pull the latest micropython/micropython master |
seems related.. trying this |
Revisiting this now (setting up from scratch on a new computer)... Ending today on this error when building (when it gets to the qstr):
I notice that on line 274 of the However, perhaps this is not being applied at the QSTR build stage? |
forcing the flag works (as in it builds)
This causes many warnings in the output of course every c file compiled throws a warning |
So you cloned everything from scratch, checked out esp32-C++ branches, used same SHA for ESP sdk as you mentioned above? Just so I can try to reproduce this - could be that I never did a clean in between trying things and QTR generation didn't kick in or so. Adding c++ flags to CFLAGS is expected to fail. |
Yes you're correct. I:
It does build and succeed with the |
Ok thanks for the info. I'll try to sort this out as soon as time permits, might be a couple of days. Note in the gist you linked to you're using a different SHA than the one mentioned above, not sure if that is the problem though. |
oh waiit - i need a specific SHA for ESPIDF. |
i presume that's the SHA for v4.0 of ESP-IDF in my comment above (whilst i've been trying on v3.x today) |
Tried this again here after cleaning sources (with the v4.0 SHA) and the compiler also emits the warning:
but it doesn't lead to any errors and the build continues until completion. |
ok! that builds and links |
I had to change the partitions.csv in the
The factory partition doesn't have to be quite this large, but this leaves a little extra for the user's C++ code+libraries |
re: the warning before about the std library |
Aha, nice! |
Thank you so much! I guess some things to share this goodness further could be:
|
Makes sense; first point is easy enough. Second point is doable with a make flag to remain compatible with the current situation. Third point: I already have an open PR agains Microython for the QSTR generation part. The rest is rather specific to ESP32 but indeed doesn't hurt to start discussion from that. |
@elliotwoods I've worked on this a bit and there's now a PR for MicroPython for C++ support, and I changed the esp32-c++ branch here to work against that. Can you test this if you have some time? So that's the usercmodule-c++ bracnh from my MicroPython repository, and the esp32-c++ branch from this one (needs pull --rebase because I overwrote the previsuo commits). Then I didn't include the partitions.csv changes though; would there be a way to be able to customize that from the command line? Or does everyone really has to manually edit the file? Seems worth raising an issue for that. |
Hi @stinos |
No worries, not urgent at all! |
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: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
The text was updated successfully, but these errors were encountered: