Running C++ code on the second core.

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Running C++ code on the second core.

Post by chibill » Mon Dec 14, 2020 4:33 am

Hello,

I am making this thread to track my attempts at running a C++ program on the second core and interacting with it thru Micropython.

In this case I am going to be trying to have https://github.com/bitluni/ESP32CompositeVideo running on the second core as a very basic Composite Video Text display. (Maybe something cooler in the future.)

I am going to assume I can just find the main function for micropython and shoe horn in the calls to set up a thread on the other processor. (I might switch which processor Micropython is on as I know the Video code needs to not be on the Core WIFI is on.) Then the rest of the issues will be setting up the thread safe interface between the two and having Micropython callable function to interact with it.

Before I do any of this I have to first get Micropython compiling on my server again so the next update may take some time.

chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Re: Running C++ code on the second core.

Post by chibill » Fri Dec 18, 2020 1:49 pm

I am now able to built micropython again. I will be doing some tests with running stuff on the other core from C.

One thing I have to figure out is how to use C++ code in a c module in Micropython.

chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Re: Running C++ code on the second core.

Post by chibill » Sat Dec 19, 2020 3:38 pm

So I found out how to make a cpp module in micropython but I have found that not even the example will compile for ESP32.
https://gist.github.com/wgaylord/55a4ea ... 115101decc

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: Running C++ code on the second core.

Post by stijn » Sat Dec 19, 2020 4:23 pm

Tell the compiler where mpconfigboard.h is, I've used this in the module's micropython.mk:

Code: Select all

CXXFLAGS_USERMOD += -I$(BOARD_DIR) -Wno-error=cpp -Wno-error=sign-compare
not sure if you need the last 2 flags, depends on your code.

chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Re: Running C++ code on the second core.

Post by chibill » Sat Dec 19, 2020 4:37 pm

That seems to have worked.

chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Re: Running C++ code on the second core.

Post by chibill » Sun Jan 24, 2021 3:33 am

So I am running into issues with StoreProhibited Errors. Any idea how to track down what exactly is causing this? Like I have the ESP Stack Trace but I am not sure how to use that from a Micropython standpoint.

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

Re: Running C++ code on the second core.

Post by jimmo » Mon Jan 25, 2021 12:12 am

If you have the esp stack trace then you can either cross-reference the addresses from firmware.map or use xtensa-esp32-elf-objdump with firmware.elf.

chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Re: Running C++ code on the second core.

Post by chibill » Mon Jan 25, 2021 8:44 pm

Okay. Also figured out my issue. Turns out it really helps to be compiling for the GENERIC-SPIRAM if your going to be doing something that requires that extra ram.

chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Re: Running C++ code on the second core.

Post by chibill » Fri Feb 26, 2021 8:20 pm

So I have made progress although I ran into an issue where the library I am trying to write an usermodule for uses C++ templating which when its included into the c shim causes the compiler to throw errors about the templating.

Also for some reason sometimes the C++ code can't see malloc and other functions that I know exist.

I was originally trying to port https://github.com/bitluni/ESP32CompositeVideo to be a usermodule but now I have moved to https://github.com/bitluni/ESP32Lib (Specifically the video parts) because the former has timing issues when the program is compiled with the cache-fix enabled causing the video to scroll down the screen.



Really hoping that in the future I could write this as a natmod if a way to access the IDF ever gets implmented.

Post Reply