RTOS Fundamentals

Definition

Real-time: is doing something within a specified time constraint

Types of real-time system

RTOS-Based firmware:

RTOS-Based software:

Jitter

What is Jitter?:

Is the delay between an event being triggered and being detected.

image 10.png

💡 Note that if a system has a maximum amount of jitter the system is considered determistic

Interrupts

💡 In ARM cortex-M, when two interrupts occur one before the other finish executing, the CPU does not restore context to the pre-interrupt state, it continues in the same state and executes the next ISR.

DMA: Direct Memory Access

Preemptive / Cooperative

Preemptive: The OS can interrupt a running task to assign CPU time to another.
(ISR have highest priority and they can stop any task.)
Cooperative: voluntarily giving control to each other.

semaphores vs mutexes

Semaphores: they are a way to manage access to a shared resource between multiple tasks, using a system that is similar to having a pass, and only who has the pass can access the shared resource.

e.g.: let’s say we have 3 tasks with priorities A > B > C,
where A, B, C share a resource.

_attachments/Pasted image 20260531145454.png

A, wait for the semaphore
C has the semaphore task B C returns the semaphore

Do you see the problem?
Because C has a lower priority than A & B, so B will execute before C, thus delaying task A.

—> Thus the need Mutexes

Mutex: Similar to a semaphore but with one simple difference, that is priority change

e.g. if the mutex is being held by a task C, that has a lower priority then task A, the Scheduler will change the priority of task C momentarily (until task C releases the mutex)

_attachments/Pasted image 20260531153015.png

mutex = binary semaphore + priority change

ROM (Read Only Memory)

How to go about choosing the size of the ROM when you don't know how much to need??

  1. Select a family of MCUs that has multiple flash sizes and compatible footprints.
  2. Start developing on the MCU that has the biggest flash size so you are not limited and give yourself the flexibility to develop and add features.
  3. After knowing the ROM size you need, choose the right MCU.

Tip: When changing to another MCU, make sure to check peripheral assignments between models, pin compatible doesn’t always mean peripheral compatible.

RAM (Read Access Memory)

a large amount of RAM is needed when dealing with large buffers for data, complex networking stacks, deep buffers, GUI's, and any interpreted languages that run a VM (like micropython and lua)

note: that each Task in FreeRTOS requires its own stack + min of 512 bytes on Cortex-M

the use of external RAM:

CPU Clock Rate

price: (BOM: bill of material)

Availability

Note about hardware regarding DMA:
DMA: Direct memory access, is extremely useful in situations like high bandwidth or highly event-driven code is used.

how freertos handler multiple tasks execution on cpu with multiple cores

FreeRTOS can use multiple cores, but how it does so depends on the port and SoC.

Two models you’ll see:

How FreeRTOS SMP schedules:

Notes for your setup:

Example: pin a task to cores 0 and 1 in an SMP port:

// ...create the task first...
TaskHandle_t h = NULL;
xTaskCreate(MyTask, "t", 1024, NULL, tskIDLE_PRIORITY + 1, &h);

// Allow task to run on cores 0 and 1 (bitmask)
UBaseType_t mask = (1U << 0) | (1U << 1);
vTaskCoreAffinitySet(h, mask);

Key takeaway: FreeRTOS doesn’t run a single task on multiple cores simultaneously; it runs different tasks concurrently on different cores, preemptively, honoring priorities and (optional) core affinity.