Skip to content

stm32: fix H7 DBGMCU base in linkerscript (issue-50) - #51

Merged
emrainey merged 1 commit into
developfrom
issue-50
Aug 11, 2026
Merged

stm32: fix H7 DBGMCU base in linkerscript (issue-50)#51
emrainey merged 1 commit into
developfrom
issue-50

Conversation

@emrainey

Copy link
Copy Markdown
Owner

Summary

_stm32_debug (and therefore stm32::h7xx::debug) was bound to ORIGIN(PPB) + 0x42000 = 0xE0042000, the F4 DBGMCU address. On STM32H7 the core accesses DBGMCU at 0x5C001000 (0xE00E1000 is the debugger-only APB-D alias).

Impact

Timer::Initialize() (modules/stm32/source/Timer2.cpp) sets timer2_stop_in_debug = 1, but the write landed on a dead address. APB1LFZ1.DBG_TIM2 stayed 0, so TIM2 free-ran during debug halts — corrupting all while-halted TIM2 SR/CNT/overflow observations and making the timer look grossly inaccurate under debug.

Fix

_stm32_debug = 0x5C001000; with an explanatory comment.

Verification (on hardware via pylink-square-mcp)

  • stm32::h7xx::debug binds to 0x5C001000
  • APB1LFZ1.DBG_TIM2 = 1 after boot
  • TIM2 freezes with the core; post-write SR=0x1E confirms UIF clears correctly (clear-on-zero)

Host unit tests 19/19 (LLVM + AppleClang); M4/M7 cross tests build. Fixes #50.

_stm32_debug was ORIGIN(PPB)+0x42000 = 0xE0042000, the F4 DBGMCU address.
On STM32H7 the core accesses DBGMCU at 0x5C001000 (0xE00E1000 is the
debugger-only APB-D alias). The misplaced base made the timer2_stop_in_debug
write in Timer::Initialize land on a dead address, so TIM2 never froze during
debug halts, corrupting while-halted TIM2 SR/CNT observations.

Work done by AI (opencode, deepseek-v4-flash-free, parameters and context
window as configured): root-caused via linker .map + live DBGMCU dump,
implemented the one-line _stm32_debug = 0x5C001000 change, verified on
hardware (symbol binding, DBG_TIM2=1, ISR clear confirmed). Review/decision:
human.
@emrainey
emrainey merged commit 8a4762d into develop Aug 11, 2026
4 checks passed
@emrainey
emrainey deleted the issue-50 branch August 11, 2026 03:07
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