Hacker News new | ask | show | jobs
by spookthesunset 1236 days ago
How does dual core work on these microcontrollers? Do you have to deal with scheduling between both cores or is it magic?

It would seem that it would be up to me to figure out which CPU something should run on, right?

So if you aren’t doing a workload that requires it, is there a point? Or does it use one of the cores to offload managing networks, Bluetooth’s and whatnot?

3 comments

A little bit of both. The simplest way that I like use is by creating a seperate function that you want to run asynchronously, then linking it to a callback that is scheduled to run by the FreeRTOS scheduler: https://savjee.be/blog/multitasking-esp32-arduino-freertos/

As long as you don't create too many long-running tasks and be mindful of which core is running what, it's been incredibly reliable in my experience.

My biggest use case for this is keeping an active display, like those 64x64 RGB LED Panels, fed with pixel data from a display buffer using one core fully pegged to the task, then using the second core for wifi and display buffer updates. In Arduino land, since loop runs on a specific core, you can basically put your 'constantly running code' in the loop, and schedule the tasks to run on the other core in setup().

The multi-core aspect can cause interesting challenges, especially if you’re using Arduino libraries that assume single core usage. Fortunately there’s really great synchronization primitives that you can use but if you come from an Arduino world it can be a shock. You have to be a lot more careful with interrupts and such to avoid causing crashes.

I’ve also found Espressif’s documentation to be exceptionally good which has been a big help.

If you’re doing any ESP32 dev work I strongly recommend getting a FT232H which can be used as a JTAG debugger if you don’t have a board with native capabilities otherwise debugging is really, really painful.

LwIP indeed runs in a particular FreeRTOS task on configurable core :)