Skip to the content.

Index


🛠 Firmware Coding Quick Reference

This page distills key rules and patterns from the full standards. For checklists and CI gates, see Review Checklist.

1. Memory & Resource Management

Anti-patterns: dynamic alloc after init, stack arrays >1KB, DMA in .bss.


2. Tasking & Scheduling

Anti-patterns: polling loops, multi-purpose tasks, blocking in critical section.


3. Inter-Task Communication (IPC)

Anti-patterns: infinite waits, binary semaphore as mutex, busy-loop polling.


4. Drivers & Hardware

Anti-patterns: blocking in ISR/driver, protocol logic in ISR, dynamic alloc in driver.


5. Timing & Reliability

Anti-patterns: direct tick compares, busy-wait, direct watchdog kick from tasks.


6. Quality, Process & Safety

Anti-patterns: manual-only testing, ignoring failed tests, missing Doxygen/comments.


7. Logging, Security & Lifecycle

Anti-patterns: direct printf, debug in prod, hardcoded credentials, missing version info.


Handy Snippets

Static queue:

static StaticQueue_t qcb; static uint8_t qstore[LEN*ITEM];
static QueueHandle_t q;
q = xQueueCreateStatic(LEN, ITEM, qstore, &qcb); configASSERT(q);

Periodic task:

const TickType_t T = pdMS_TO_TICKS(10); TickType_t next = xTaskGetTickCount();
for (;;) { next += T; do_work(); vTaskDelayUntil(&next, T); }

Notify from ISR:

BaseType_t hpw = pdFALSE; vTaskNotifyGiveFromISR(taskH, &hpw); portYIELD_FROM_ISR(hpw);

Wrap-safe timeout:

TickType_t start = xTaskGetTickCount();
while ((TickType_t)(xTaskGetTickCount() - start) < pdMS_TO_TICKS(200)) { if (ready()) break; }

Doxygen function header:

/**
 * @brief Send data over UART
 * @param buf   Pointer to TX buffer
 * @param len   Number of bytes
 * @return FW_OK on success, FW_ERR_TIMEOUT on timeout
 */
fw_status_t drv_uart_send(const uint8_t *buf, size_t len);

Rule of thumb: Deterministic, event-driven, measured, and documented.

For review checklists, CI gates, and common mistakes, see Review Checklist.


Index