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
ct run --json --board stm32f4-discovery --record trace/ build/freertos_app.elf
ct test run --json --recheck tests/freertos.suite.yamlSuite & fault configuration
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
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.xmlFreeRTOS 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 |
ct test run --json --junit results/mpu.xml tests/freertos-mpu.suite.yamlversion: 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: 0Troubleshooting 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). |