Running tasks in an RTOS on a multicore system can seem daunting at first. Many processors have unique architectures that you must keep in mind when writing programs that use more than one core. We examine the FreeRTOS port for the ESP32 (known as ESP-IDF) and how to synchronize tasks on both cores.
The solution to the challenge can be found here: https://www.digikey.com/en/maker/projects/introduction-to-rtos-solution-to-part-12-multicore-systems/369936f5671d4207a2c954c0637e7d50
Code for this video series (including demonstrations, challenges, and solutions) can be found here: https://github.com/ShawnHymel/introduction-to-rtos
Programming a multicore system can be separated into two paradigms: asymmetric multiprocessing (AMP) and symmetric multiprocessing (SMP). AMP requires a primary core running an operating system to schedule tasks in other (secondary) cores. In SMP, the OS runs on all cores, and the scheduler is free to pull tasks from a shared list.
ESP-IDF is the port of FreeRTOS for the ESP32, and it supports SMP. The ESP32 is a dual-core system (although, single-core variants exist). We look at how the ESP32 architecture is configured and how each core can access memory, resources, and interrupts.
In ESP-IDF, we have the option of pinning tasks to a core (so that only that core may run a particular task) or setting a task to “no affinity” (so that the task can run in either core). Using “no affinity” is easier to implement and optimizes CPU utilization and load balancing without much effort. However, it becomes difficult to determine when certain tasks will run, which makes predicting deadlines tougher. As a result, many embedded developers prefer to pin tasks to cores, as it allows for a higher level of determinism.
We show how to run tasks on either core in the ESP32 as well as set them to “no affinity.” Kernel objects (e.g. queues, mutexes, and semaphores) work across cores without any modification, as the ESP32’s cores share memory.
Introduction to RTOS Part 1 – What is a Real-Time Operating System (RTOS)? – https://youtu.be/F321087yYy4
Introduction to RTOS Part 2 – Getting Started with FreeRTOS – https://youtu.be/JIr7Xm_riRs
Introduction to RTOS Part 3 – Task Scheduling – https://youtu.be/95yUbClyf3E
Introduction to RTOS Part 4 – Memory Management – https://youtu.be/Qske3yZRW5I
Introduction to RTOS Part 5 – Queue – https://youtu.be/pHJ3lxOoWeI
Introduction to RTOS Part 6 – Mutex – https://youtu.be/I55auRpbiTs
Introduction to RTOS Part 7 – https://youtu.be/5JcMtbA9QEE
Introduction to RTOS Part 8 – https://youtu.be/b1f1Iex0Tso
Introduction to RTOS Part 9 – https://youtu.be/qsflCf6ahXU
Introduction to RTOS Part 10 – https://youtu.be/hRsWi4HIENc
Introduction to RTOS Part 11 – https://youtu.be/C2xKhxROmhA
Introduction to RTOS Part 12 – https://youtu.be/LPSHUcH5aQc
Maker.io – https://www.digikey.com/en/maker
Digi-Key’s Blog – TheCircuit https://www.digikey.com/en/blog
Connect with Digi-Key on Facebook https://www.facebook.com/digikey.electronics/
And follow us on Twitter https://twitter.com/digikey