RTOS & Firmware Stacks

FreeRTOS headless testing in CI

Test real FreeRTOS scheduler preemption, PendSV/SysTick timing and task check-signals on Cortex-M board twins.

Host POSIX ports of FreeRTOS replace PendSV, BASEPRI masking and NVIC interrupt nesting with pthreads—hiding priority-inversion bugs and configMAX_SYSCALL_INTERRUPT_PRIORITY mistakes until you flash silicon.

CircuitTwin runs the real FreeRTOS Cortex-M ELF end to end, with FreeRTOS full-demo check-task timing traces measured within 1% of the pass period (see /docs/accuracy for published board and kernel records).

FreeRTOS failure classes caught on twins

Bug classWhy POSIX ports miss itHow CircuitTwin catches it
configMAX_SYSCALL_INTERRUPT_PRIORITYNo NVIC priority grouping on host OSReal Cortex-M BASEPRI + assert trap in GDB
PendSV / SysTick starvationHost OS scheduler masks tick jitterDeterministic virtual-time signal trace
FromISR API called from wrong priorityMocked ISRs skip NVIC stateImmediate Fault / configASSERT capture
Task stack overflowHost stacks are multi-MBDeterministic corruption caught via reverse-step

Local CLI workflow

Shell — run FreeRTOS demo ELF
ct run --json --board stm32f4-discovery --record trace/ build/freertos_app.elf
ct test run --json --recheck tests/freertos.suite.yaml

Suite & fault configuration

tests/freertos.suite.yaml
version: 1
board: stm32f4-discovery
firmware: build/freertos_app.elf
tests:
  - name: check-task-steady-period
    timeout_ms: 5000
    expect:
      console_contains: "PASS: all tasks healthy"
      exit_code: 0
  - name: sensor-task-i2c-fault-isolation
    faults:
      - at_ms: 300
        bus: I2C1
        kind: nack
        address: 0x68
        count: 5
    expect:
      console_contains: "WATCHDOG_FED"

CI pipeline integration

.github/workflows/freertos-ci.yml
name: FreeRTOS Twin CI
on: [push, pull_request]
jobs:
  freertos:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: make -j
      - uses: circuittwin/action@v1
        with:
          suite: tests/freertos.suite.yaml
          junit-out: results/freertos.xml

FreeRTOS MPU isolation and stack-guard CI

Prove that an unprivileged FreeRTOS task triggers MemManage instead of silently corrupting kernel memory.

Configuring MPU_RBAR and MPU_RASR regions is error-prone. One wrong sub-region bit or power-of-two alignment mistake leaves privileged SRAM writable from user tasks.

CircuitTwin models Cortex-M MPU permissions and ARMv8-M stack limit registers (MSPLIM/PSPLIM on STM32L5, STM32U5 and LPC55S69), so negative-control security tests can assert exact MemManage or UsageFault CFSR bits in CI.

Memory-protection checks

Fault typeRegister signatureCI verification
Unprivileged SRAM writeCFSR.DACCVIOL=1, MMFARValid=1Assert MemManage handler logs task ID and resets task
Execute from SRAM/stackCFSR.IACCVIOL=1 (XN bit)Verify instruction fetch trap on non-executable heap
Cortex-M33 stack overflowCFSR.STKOF=1 (ARMv8-M)Verify hardware PSPLIM trap before adjacent globals corrupt
Shell - run FreeRTOS MPU negative-control suite
ct test run --json --junit results/mpu.xml tests/freertos-mpu.suite.yaml
tests/freertos-mpu.suite.yaml
version: 1
board: nucleo-l552ze
firmware: build/freertos_mpu_test.elf
tests:
  - name: unprivileged-write-traps-memmanage
    timeout_ms: 2000
    expect:
      console_contains: "MEMMANAGE_DACCVIOL_CAUGHT"
      exit_code: 0

Troubleshooting checklist

SymptomFix
Scheduler hangs on first vTaskStartScheduler()Check that SVC_Handler, PendSV_Handler and SysTick_Handler are mapped to vPortSVCHandler, xPortPendSVHandler and xPortSysTickHandler in the vector table.
HardFault inside xQueueSendFromISR()Set NVIC interrupt priority numerically >= configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY.
Check task period drifts in traceVerify configCPU_CLOCK_HZ matches the actual PLL clock configured in SystemInit().
Non-deterministic queue race across runsRun ct test run --recheck and inspect --record trace/ for unguarded shared globals.
MemManage escalates to HardFaultSet SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk before enabling the MPU.
MPU region fails to align on ARMv7-MEnsure base address is a multiple of the region size in the linker script.

Frequently asked questions

QuestionAnswer
Which boards support hardware stack-limit checking (MSPLIM/PSPLIM)?ARMv8-M Cortex-M33 boards including NUCLEO-L552ZE, B-U585I-IOT02A, LPCXpresso55S69 and Raspberry Pi Pico 2 (RP2350).

Related boards & component twins

More in RTOS & Firmware Stacks