Skip to content

stm32: program the ST SWO/SWTF trace blocks for H7 SWO (issue-41) - #56

Merged
emrainey merged 1 commit into
developfrom
issue-41
Aug 13, 2026
Merged

stm32: program the ST SWO/SWTF trace blocks for H7 SWO (issue-41)#56
emrainey merged 1 commit into
developfrom
issue-41

Conversation

@emrainey

Copy link
Copy Markdown
Owner

Summary

Closes #41. Programs the ST Serial Wire Output path on the STM32H7 so the Cortex-M7 ITM trace stream reaches the SWO pin (PB3 / TRACESWO). On the H7 the ARM CoreSight TPIU does not drive the SWO pin — the ST SWO (0x5C003000) and SWTF funnel (0x5C004000) blocks do.

What changed

  • New register headers stm32/h7xx/Swo.hpp + SwoTraceFunnel.hpp (hand-written, peripheralyzer style, offsets static_asserted), UNITTEST RAM globals, and linker PROVIDEs for both debug blocks.
  • enable_serial_wire_output(trace_clock, baud) (H7 debug.cpp): enables DBGMCU TRACECLKEN/D1DBGCKEN/D3DBGCKEN, unlocks SWO/SWTF (0xC5ACCE55), selects Async-NRZ, programs SWO_CODR from TRACECK (= PLL1R), enables the SWTF. F4 gets a documented no-op (its standard TPIU drives SWO).
  • ClockTree.trace: computed in clocks.cpp (PLL1R on H7, sysclk on F4) and the vendor call invoked from clocks() — required because module archives are scanned once before jarnax, so vendor symbols referenced only from configure.cpp never link (same issue as early_power, FIXME at clocks.cpp:38).
  • BoardContext: PB3 configured as TRACESWO (AF0, very-high speed).
  • Demo: periodic SWO-OK marker on the SWO System port for verification.
  • Tests: 10 new gtest cases over the UNITTEST globals.

Verification

  • M4/M7 cross (+ -ci) and host llvm/clang presets build clean; on-host-native-gcc excluded (documented Darwin-only failure).
  • Hardware (Nucleo-H753ZI), single-session breakpoint dump at cortex::system::main():
    • DBGMCU_CR = 0x00700007 (trace/debug clocks on)
    • SWO_CODR = 0x2b → 100 MHz / 2.24 MBaud
    • SWO_SPPR = 2 → AsyncNRZ (UART)
    • SWTF_CTRL = 0x301 → ENSO enabled

Note: a J-Link reconnect rewrites DBGMCU_CR to 0x07, unclocking the D3 debug domain — register reads are only valid within a single debug session (see GOTCHAS.md).

Follow-ups

Program the ST Serial Wire Output path on the H7 so the Cortex-M7 ITM trace
reaches the SWO pin (PB3/TRACESWO). The ARM CoreSight TPIU does not drive the
pin on the H7; the ST SWO (0x5C003000) and SWTF funnel (0x5C004000) do.

AI (opencode, model big-pickle, 128k context) implemented:
- Hand-written peripheralyzer-style Swo.hpp/SwoTraceFunnel.hpp register
  headers (offsets static_assert'd) + UNITTEST RAM globals + linker PROVIDEs
  for both debug blocks.
- initialize::enable_serial_wire_output() in the H7 debug.cpp: enables the
  DBGMCU trace port clocks (TRACECLKEN/D1DBGCKEN/D3DBGCKEN), unlocks the
  SWO/SWTF blocks (0xC5ACCE55), selects Async-NRZ, programs SWO_CODR from
  TRACECK (= PLL1R, 100 MHz) and enables the SWTF. F4 gets a documented no-op
  (its standard TPIU drives SWO).
- clocks.cpp now computes ClockTree.trace (PLL1R on H7, sysclk on F4) and
  calls enable_serial_wire_output() from the vendor clocks(): module archives
  are scanned once before jarnax, so vendor symbols referenced only from
  configure.cpp are never extracted (same issue as early_power, FIXME at
  clocks.cpp:38).
- BoardContext: PB3 as TRACESWO (AF0, very-high speed, push-pull).
- Demo emits a periodic SWO-OK marker on the SWO System port.
- 10 new gtest cases over the UNITTEST globals (DBGMCU bits, unlock values,
  CODR, protocol, ENSO); host llvm + clang pass.

Human: board pin bring-up decisions and review.

Verified: M4/M7 cross (+ci variants) and host llvm/clang presets build clean;
hardware shows DBGMCU_CR=0x00700007, SWO_CODR=0x2b (100 MHz / 2.24 MBaud),
SWO_SPPR=2 (AsyncNRZ), SWTF_CTRL=0x301 at cortex::system::main() entry.
@emrainey
emrainey merged commit f620835 into develop Aug 13, 2026
4 checks passed
@emrainey emrainey self-assigned this Aug 13, 2026
@emrainey
emrainey deleted the issue-41 branch August 13, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant