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 class                               | Why POSIX ports miss it              | How CircuitTwin catches it                       |
| --------------------------------------- | ------------------------------------ | ------------------------------------------------ |
| configMAX\_SYSCALL\_INTERRUPT\_PRIORITY | No NVIC priority grouping on host OS | Real Cortex-M BASEPRI + assert trap in GDB       |
| PendSV / SysTick starvation             | Host OS scheduler masks tick jitter  | Deterministic virtual-time signal trace          |
| FromISR API called from wrong priority  | Mocked ISRs skip NVIC state          | Immediate Fault / configASSERT capture           |
| Task stack overflow                     | Host stacks are multi-MB             | Deterministic 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 type                | Register signature            | CI verification                                             |
| ------------------------- | ----------------------------- | ----------------------------------------------------------- |
| Unprivileged SRAM write   | CFSR.DACCVIOL=1, MMFARValid=1 | Assert MemManage handler logs task ID and resets task       |
| Execute from SRAM/stack   | CFSR.IACCVIOL=1 (XN bit)      | Verify instruction fetch trap on non-executable heap        |
| Cortex-M33 stack overflow | CFSR.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

| Symptom                                        | Fix                                                                                                                                                          |
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 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 trace              | Verify configCPU\_CLOCK\_HZ matches the actual PLL clock configured in SystemInit().                                                                         |
| Non-deterministic queue race across runs       | Run ct test run --recheck and inspect --record trace/ for unguarded shared globals.                                                                          |
| MemManage escalates to HardFault               | Set SCB->SHCSR \|= SCB\_SHCSR\_MEMFAULTENA\_Msk before enabling the MPU.                                                                                      |
| MPU region fails to align on ARMv7-M           | Ensure base address is a multiple of the region size in the linker script.                                                                                   |

## Frequently asked questions

| Question                                                            | Answer                                                                                                               |
| ------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| 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

[Board: stm32f4-discovery](https://circuittwin.ai/boards/stm32f4-discovery) [Board: nucleo-f446re](https://circuittwin.ai/boards/nucleo-f446re) [Board: nucleo-f767zi](https://circuittwin.ai/boards/nucleo-f767zi) [Board: frdm-k64f](https://circuittwin.ai/boards/frdm-k64f) [Board: nucleo-l552ze](https://circuittwin.ai/boards/nucleo-l552ze) [Board: b-u585i-iot02a](https://circuittwin.ai/boards/b-u585i-iot02a) [Board: lpcxpresso55s69](https://circuittwin.ai/boards/lpcxpresso55s69) [Twin: MPU-6050](https://circuittwin.ai/twins/mpu-6050) [Twin: LIS3DH](https://circuittwin.ai/twins/lis3dh) [Twin: INA219](https://circuittwin.ai/twins/ina219) [Twin: ATECC608A](https://circuittwin.ai/twins/atecc608a) [Twin: W25Q128JV](https://circuittwin.ai/twins/w25q128jv) [Accuracy report](https://circuittwin.ai/docs/accuracy) [Determinism & --recheck](https://circuittwin.ai/docs/testing) [FreeRTOS headless CI guide](https://circuittwin.ai/guides/freertos-headless-testing)

## More in RTOS & Firmware Stacks

[Zephyr RTOS CI without hardware benches](https://circuittwin.ai/guides/zephyr-rtos-ci-without-hardware) [ESP-IDF CI simulation for ESP32, S3 & C3](https://circuittwin.ai/guides/esp-idf-ci-simulation) [PX4 Pixhawk 6C simulation on real ARM ELF](https://circuittwin.ai/guides/px4-pixhawk-6c-simulation) [Marlin 3D printer firmware testing in CI](https://circuittwin.ai/guides/marlin-firmware-testing-ci)

> ## Run this workflow on your own ELF
>
> Start free on CircuitTwin to run local board twins, fault matrices and CI checks with zero per-run credits.
>
> [Start now](https://app.circuittwin.ai/try) [Read the quickstart](https://circuittwin.ai/docs/quickstart) [Connect a coding agent](https://circuittwin.ai/docs/agents)
