RTOS & Firmware Stacks

# STM32CubeHAL clock tree and DMA CI

Re-running CubeMX overwrites user clock tweaks or reorders MX\_DMA\_Init(). Catch every broken init order in headless CI.

A classic STM32CubeHAL bug happens when CubeMX generates MX\_USART2\_Init() or MX\_ADC1\_Init() before MX\_DMA\_Init(). The DMA clock is still off, every DMA register write is silently dropped, and transfers never fire.

Running your CubeHAL ELF on NUCLEO-F103RB, NUCLEO-F446RE, NUCLEO-F767ZI or NUCLEO-H743ZI2 twins verifies the real RCC startup sequence, DMA transfer-complete IRQs and peripheral oracles on every commit.

## CubeHAL regressions caught in CI

| Init block            | Common CubeMX bug                          | Twin detection                                        |
| --------------------- | ------------------------------------------ | ----------------------------------------------------- |
| MX\_DMA\_Init() order | Called after MX\_SPI/ADC\_Init()           | DMA transfer never completes; suite times out cleanly |
| SystemClock\_Config() | HSE crystal vs ST-LINK MCO bypass mismatch | Timeout on RCC\_CR\_HSERDY flagged immediately        |
| HAL\_MspInit()        | Missing \_\_HAL\_RCC\_GPIOx\_CLK\_ENABLE() | Pin transitions never appear on virtual bus           |

## Local CLI workflow

Shell - run STM32CubeHAL build on twin

```
cmake --build build/Debug
ct run --json --board nucleo-f767zi build/Debug/cubehal_app.elf
```

## Suite & fault configuration

tests/cubehal.suite.yaml

```
version: 1
board: nucleo-f767zi
firmware: build/Debug/cubehal_app.elf
tests:
  - name: clock-and-dma-smoke
    timeout_ms: 2000
    expect:
      console_contains: "DMA_TX_COMPLETE"
      exit_code: 0
```

## CI pipeline integration

.github/workflows/cubehal-ci.yml

```
name: STM32CubeHAL CI
on: [push, pull_request]
jobs:
  cubehal:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: cmake -B build -DCMAKE_TOOLCHAIN_FILE=cmake/gcc-arm-none-eabi.cmake && cmake --build build
      - uses: circuittwin/action@v1
        with:
          suite: tests/cubehal.suite.yaml
```

## Troubleshooting checklist

| Symptom                                           | Fix                                                                                                                |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| DMA callback HAL\_UART\_TxCpltCallback never runs | Check that MX\_DMA\_Init() runs before peripheral init and DMAx\_Streamy\_IRQHandler calls HAL\_DMA\_IRQHandler(). |
| HAL\_Delay() hangs forever                        | Verify SysTick\_Handler() calls HAL\_IncTick() and SysTick priority is higher than the calling ISR.                |

## Frequently asked questions

| Question                                              | Answer                                                                                                      |
| ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| Does CircuitTwin need a special CubeHAL mock library? | No. Compile unmodified ST STM32CubeHAL C sources with arm-none-eabi-gcc and run the resulting ELF directly. |

## Related boards & component twins

[Board: nucleo-f767zi](https://circuittwin.ai/boards/nucleo-f767zi) [Board: nucleo-f103rb](https://circuittwin.ai/boards/nucleo-f103rb) [Board: nucleo-f446re](https://circuittwin.ai/boards/nucleo-f446re) [Board: nucleo-h743zi2](https://circuittwin.ai/boards/nucleo-h743zi2) [Twin: MPU-6050](https://circuittwin.ai/twins/mpu-6050) [Twin: INA219](https://circuittwin.ai/twins/ina219) [Twin: W25Q128JV](https://circuittwin.ai/twins/w25q128jv) [STM32 HAL peripheral oracles](https://circuittwin.ai/docs/board-dashboard)

## More in RTOS & Firmware Stacks

[Zephyr RTOS CI without hardware benches](https://circuittwin.ai/guides/zephyr-rtos-ci-without-hardware) [FreeRTOS headless testing in CI](https://circuittwin.ai/guides/freertos-headless-testing) [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)

> ## 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)
