Esp32 running simplefoc multicore?

Hey guys,

I am in the process of diving deep in the esp32 code and I’ve come accress of this tutorial for multicore code on the esp32:
https://randomnerdtutorials.com/esp32-dual-core-arduino-ide/

It seems pretty straight forward so I was wondering is there someone who has already tried this and was successful?
I’ve made few very simple tests and it seems to work well. I’ve put loopFOC in the second thread and run the move, the commander and everything else in the other. :smiley:
I’d love to include one simple example code in the library examples if someone has one to provide!

Thread safety in freeRTOS is an interesting topic, and accessing the same objects simultaneously by two threads generates certain levels of excitement that some may find challenging. We may be perfectly safe as long as the tasks are completely independent. The moment two tasks attempt to share an object, if not explicitly handled, the system behavior is very curious. Especially if this happens only very seldom during run-time, as in real-time applications, where the events are driven by outside signals overlaping infrequently.

I have tried it, with the guidance of that tutorial. My plan was to put all interrupts on Core 2 and the loop code on Core 1. I added some semaphores for data exchange. I had some issues where some standard Arduino libraries/functions would only run on Core 1 (with out changing the lib files), I can’t remember which ones.

The main reason I wanted to try it is that FreeRTOS does ~10us of house keeping every 1ms. In the end I just stopped using floating points and ran almost everything inside interrupts. The loop does the background code (OLED display, prints etc).

i did use dual cores on my ESP32 from time to time.
It’s quite efficient. Usaually I put the “UI” code into core0 together with Bluetooth and Wifi. And I put “real time time code” into the core1 which is used by default on arduino IDE.

here is an example with BLE communication together with orbit propagation and antenna motion (two steppers synchronized): https://cults3d.com/fr/mod%C3%A8le-3d/gadget/iss-and-leo-satellites-tracker

It would be fine to run simplefoc on the two cores !

JP

1 Like