Skip to content
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

how to use esp32 example #9

Closed
hstarmans opened this issue Feb 17, 2022 · 6 comments
Closed

how to use esp32 example #9

hstarmans opened this issue Feb 17, 2022 · 6 comments

Comments

@hstarmans
Copy link

hstarmans commented Feb 17, 2022

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?

@hstarmans hstarmans changed the title wrapping c++ library how to use esp32 example Feb 17, 2022
@stinos
Copy link
Owner

stinos commented Feb 18, 2022

import upywraptest is the one, the Makefile is for building the tests.
I can't tell why that doesn't work for you, can you provide more information? MicroPython version used, does the compiler log say 'including user C module from ...', can you see it compiles tests/module.c and tests/module.cpp?

@hstarmans
Copy link
Author

hstarmans commented Feb 18, 2022

I checked out Micropython at Hash 64180f0 date november 23, 2020.
You created the Makefile for micropython-wrap dac3338 on december 10, 2020.
Running the micropython-wrap makefile results in a directory build-usercmod in micropython/ports/esp32.
It creates two binaries; firmware.bin and application.bin. I flash the firmware.bin to the esp32.

Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
Building with ESP IDF v3
Writing build-usercmod/firmware.bin to the board
esptool.py v2.8
Serial port /dev/ttyUSB0

The binary works and I can connect to the esp32.
import upywraptest does not work.
Micropython-wrap does not work with the current master. It fails.. The makefile changed a lot.
This was the make file around december 2020
This is the current makefile.
With the latest master your makefile runs into the following error;

Including User C Module(s) from /home/hexastorm/projects/micropython-wrap/Makefile
CMake Error at /home/hexastorm/projects/micropython-wrap/Makefile:11:
  Parse error.  Expected "(", got unquoted argument with text "=".
Call Stack (most recent call first):
  /home/hexastorm/projects/micropython/py/usermod.cmake:42 (include)
  main/CMakeLists.txt:10 (include)


-- Configuring incomplete, errors occurred!
See also "/home/hexastorm/projects/micropython/ports/esp32/build-usercmod/CMakeFiles/CMakeOutput.log".

To summarize;

  • did you test the code on a ESP32?
  • why doesn't it work if I flash the firmware.bin from build-usercmod

Finally, I assume that with your toolchain I can compile with C++ so do not have to define extern c everywhere.
The problem with the CPP example in micropython is that it doesn't scale well. I am not sure how to wrap something like TMCStepper, it seems to me I have to wrap all C++ code in extern c blocks which is a non-starter.

@stinos
Copy link
Owner

stinos commented Feb 20, 2022

Running the micropython-wrap makefile results in a directory build-usercmod in micropython/ports/esp32.

Can you doublecheck it effectively compiles both the .c and .cpp file in the tests/ directory? Either from the log of by introducing a compiler error in the files.
I'd also need to know the exact version of the ESP SDK you're using (I can only try to reproduce this if I have the same version of everything).

Btw do the micropython example modules work for you? Something like make USER_C_MODULES=../../examples/usercmodule

With the latest master your makefile runs into the following error;
CMake Error at /home/hexastorm/projects/micropython-wrap/Makefile:11

That's actually MicroPython running into an error, it seems to be trying to use CMake to build a (gnu make) Makefile, that's never going to work. I'll have a look how to make that work with the most recent version of everything.

did you test the code on a ESP32?

At one point yes, see see #5 (comment)

it seems to me I have to wrap all C++ code in extern c blocks which is a non-starter.

That's not the case, only the code which needs to go into the C module directly needs to be wrapped in extern "c". See tests/module.cpp for instance. The micropython example is just done like that for simplicity. The function body could have been a separete 'pure' C++ function called from the C function.

@hstarmans
Copy link
Author

Stinos, my limited understanding of the interaction between c and c++ seems indeed to be the issue. I will work further with the example from micropython master.

@stinos
Copy link
Owner

stinos commented Feb 22, 2022

Let me know if you'd get back to this and still have problems.

@hstarmans
Copy link
Author

hstarmans commented Feb 22, 2022

@stinos , I made a Micropython wrapper for TMCStepper, see https://github.com/hstarmans/micropythonwebserver .
It allows you to call a function which then sets up the settings for the motor drivers which i use in my laser scanner. This is the only thing I need at the moment.
It compiles and most likely works. Still need to test it on actual hardware. Thanks for you time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants