Skip to the content.
« Previous Index Next »

Firmware Coding Standard — Error Handling & Fault Management (FreeRTOS)

1) Purpose

Define a consistent approach for detecting, reporting, and recovering from errors and faults. Ensure all failures are visible, bounded, and safely escalated.


2) Principles


3) Error Reporting & Status Codes


4) Fault Classes


5) Hooks & System-Level Faults


6) Watchdog Integration


7) Error Logging


8) Recovery & Escalation


9) Testing & Validation


10) Anti-Patterns


11) Review Checklist (Errors)


12) CI/Lint Gates


13) Example Patterns

Driver return check

fw_status_t st = drv_i2c_write(addr, buf, len, TIMEOUT_MS);
if (st != FW_OK) {
    LOG_ERROR("I2C", "write failed: %d", st);
    supervisor_notify(EVT_DRV_FAIL, st);
}

Stack overflow hook

void vApplicationStackOverflowHook(TaskHandle_t t, char *name) {
    LOG_CRIT("RTOS", "Stack overflow in %s", name);
    system_reset(SYS_RST_STACK);
}

Watchdog task

for (;;) {
    if (all_tasks_reported()) {
        watchdog_kick();
    } else {
        LOG_CRIT("WDT", "missed heartbeat");
        system_reset(SYS_RST_WATCHDOG);
    }
    vTaskDelay(pdMS_TO_TICKS(100));
}

« Previous Index Next »