Skip to the content.
« Previous Index Next »

Firmware Coding Standard — Driver & HAL Patterns (FreeRTOS)

1) Purpose

Define rules for building firmware drivers and hardware abstraction layers (HAL) that are deterministic, non-blocking, and consistent across the codebase.


2) Principles


3) Driver Architecture


4) API Rules


5) Error Handling


6) DMA Usage


7) Concurrency & Ownership


8) Testing


9) Anti-Patterns


10) Review Checklist (Drivers)


11) CI/Lint Gates


12) Example Pattern

UART TX (async)

// Application code
drv_uart_write_async(UART1, buf, len, DRV_TIMEOUT_MS);

// ISR
void UART1_IRQHandler(void) {
    BaseType_t hpw = pdFALSE;
    if (LL_USART_IsActiveFlag_TC(UART1)) {
        LL_USART_ClearFlag_TC(UART1);
        xTaskNotifyFromISR(uart_task_h, EVT_UART_TX_DONE, eSetBits, &hpw);
    }
    portYIELD_FROM_ISR(hpw);
}

// Driver task
static void uart_task(void *arg) {
    for (;;) {
        uint32_t ev;
        xTaskNotifyWait(0, UINT32_MAX, &ev, portMAX_DELAY);
        if (ev & EVT_UART_TX_DONE) handle_tx_done();
        if (ev & EVT_UART_RX_READY) handle_rx_ready();
    }
}

« Previous Index Next »