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 blockCommon CubeMX bugTwin detection
MX_DMA_Init() orderCalled after MX_SPI/ADC_Init()DMA transfer never completes; suite times out cleanly
SystemClock_Config()HSE crystal vs ST-LINK MCO bypass mismatchTimeout 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

SymptomFix
DMA callback HAL_UART_TxCpltCallback never runsCheck that MX_DMA_Init() runs before peripheral init and DMAx_Streamy_IRQHandler calls HAL_DMA_IRQHandler().
HAL_Delay() hangs foreverVerify SysTick_Handler() calls HAL_IncTick() and SysTick priority is higher than the calling ISR.

Frequently asked questions

QuestionAnswer
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

More in RTOS & Firmware Stacks