Expand description
tag-monitor-test: tests the monitor interface.
Port of host/commandline/tag-monitor-test.cc. Drives the STM32L4
DebugMonitor handshake directly over LinkAdapt, without tagcoreโs
TagMonitor, as an independent check of the interface: reset into the
monitor, read the version, SHA string and buffer size, send MONITORSTART,
print what was read and end the session with MONITORSTOP. It follows the
same rules as TagMonitor:
- debug control is programmed before reset is released, because standby can power-cycle the core debug block (writes after that fault, ST-LINK status 0x81);
- DCRDR is both request and response mailbox, so a request is written only when MON_PEND and MON_REQ are clear, and a call waits for MON_REQ to clear before reading the result;
- C_MASKINTS is never left set, since it survives the halt release and stalls the firmware with every interrupt masked.
STM32L4 only: on an STM32U3, whose monitor is the shared block, it says so and exits before writing any debug register. Exits 0 once the handshake completes, 1 otherwise.
Usage: tag-monitor-test [-d] [-b BUS:DEVICE]. On success it prints the
monitor version, call-buffer size in bytes and the tagโs SHA string.
Option errors exit 2 (clap).
ยงHardware side effects
The attach resets the tag and writes DHCSR and DEMCR (Cortex-M debug registers) directly; the session ends with MONITORSTOP, after which the firmware clears its own debug state. A part whose DBGMCU ID code reads as neither an L4 nor a U3 is treated as an L4.
Structsยง
- Cli ๐
- tests the monitor interface
- Test
Monitor ๐ - The C++
TestMonitor: aLinkAdaptwith its own monitor call and attach sequence, and the state the attach reads.
Constantsยง
- C_
DEBUGEN ๐ - DHCSR: halting debug enable.
- C_HALT ๐
- DHCSR: halt request.
- C_
MASKINTS ๐ - DHCSR: mask PendSV, SysTick and external interrupts while stepping or halted.
- DBGKEY ๐
- Key that must accompany every DHCSR write, in bits 31:16.
- DCRDR ๐
- Debug Core Register Data Register, the monitorโs request and response mailbox.
- DEMCR ๐
- Debug Exception and Monitor Control Register.
- DHCSR ๐
- Debug Halting Control and Status Register (Armv7-M).
- L4_
DBGMCU_ ๐IDCODE - DBGMCU_IDCODE address on the STM32L4.
- MON_EN ๐
- DEMCR: enable the DebugMonitor exception.
- MON_
PEND ๐ - DEMCR: pend the DebugMonitor exception.
- MON_REQ ๐
- DEMCR: monitor request bit, used as โrequest outstandingโ by the host and cleared by the firmware when the result is in DCRDR.
- S_HALT ๐
- DHCSR: the core is halted (read only).
- TRCENA ๐
- DEMCR: enable the DWT and ITM trace blocks.
- U3_
DBGMCU_ ๐IDCODE - DBGMCU_IDCODE address on the STM32U3.
- VC_
CORERESET ๐ - DEMCR: vector catch on core reset; the firmware reads it as โa host is attachedโ.
Functionsยง
- main ๐
- Attaches through the raw handshake, prints what it read and ends the session with MONITORSTOP.
- ms ๐
- Shorthand for a
Durationofnmilliseconds. - plausible_
idcode ๐ - True if
idcodehas a real device ID (neither all zero nor all one). - select_
device ๐ - Finds the ST-LINK the arguments select, or exits:
options.ccโs rule, applied toLinkAdapt::availablesince this tool has noTag.