The existing problem is BMDA + STLINK/V2-1 thinking it fails to cortexm_initial_halt() a MINDP stm32g071rb with an error message Halt via DHCSR(00030003): failure after 2028ms etc. which incurs said 2 seconds of delay during monitor swd_scan.
The PR solves this by gating the extra low_access when using STLINK_V2 backend type. Message becomes Halt via DHCSR(01030003): success after 2ms.
Inspecting PROBE loglevel traces indicates that, unlike BMPremote, stlinkv2 adapter firmware manages AP DRW + DP RDBUFF accesses behind the scenes, which are otherwise required for Cortex-M0/M0+ per specs. So the first read (from AP), which under plain line-level bitbangers returns garbage, here actually contains the data; and the second read (from DP) appears as zeroes. Ignore the "decreasing spam logline, it's not a part of this patch.*
stlink_raw_access: Attempting access to addr 010c via apsel 0
stlink_raw_access: addr 010c <- a05f0003
stlink_raw_access: Attempting access to addr 010c via apsel 0
stlink_raw_access: addr 010c -> 00030003
stlink_raw_access: Attempting access to addr 000c via apsel 65535
stlink_raw_access: addr 000c -> 00000000
cortexm_initial_halt: decreasing spam by sleeping for 100 ms
stlink_raw_access: Attempting access to addr 010c via apsel 0
stlink_raw_access: addr 010c <- a05f0003
stlink_raw_access: Attempting access to addr 010c via apsel 0
stlink_raw_access: addr 010c -> 00030003 # AP DRW returns the result early
stlink_raw_access: Attempting access to addr 000c via apsel 65535
stlink_raw_access: addr 000c -> 00000000 # DP RDBUFF was used
cortexm_initial_halt: decreasing spam by sleeping for 100 ms
stlink_mem_read from e000edf0 to 0x7ffe256a2944, len 4
Halt via DHCSR(00030003): failure after 2028ms
Try again with longer timeout or connect under reset
adiv5: Failed to prepare AP, results may be unpredictable
[x] My commit messages provide a useful short description of what the commits do
Closing issues
Tested on Nucleo-G071RB with STLINK/V2-1 firmware versions V2J33M25, V2J45M30, and a WeActStudio BluePillPlus stm32f103cb running Blackmagic Debug Firmware v1.10.2 (+ BluePill+ PCB patches for PB2 LED and SPI1). The latter displays expected MINDP operation in BMPremote logs. Affected targets would be any MINDP debuggable with a stlinkv2, including ST parts with Cortex-M0 (F0 family) and Cortex-M0+ (l0, g0, c0, u0).
Detailed description
cortexm_initial_halt()
a MINDP stm32g071rb with an error messageHalt via DHCSR(00030003): failure after 2028ms
etc. which incurs said 2 seconds of delay duringmonitor swd_scan
.Halt via DHCSR(01030003): success after 2ms
.Inspecting PROBE loglevel traces indicates that, unlike BMPremote, stlinkv2 adapter firmware manages AP DRW + DP RDBUFF accesses behind the scenes, which are otherwise required for Cortex-M0/M0+ per specs. So the first read (from AP), which under plain line-level bitbangers returns garbage, here actually contains the data; and the second read (from DP) appears as zeroes. Ignore the "decreasing spam logline, it's not a part of this patch.*
Your checklist for this pull request
Closing issues
Tested on Nucleo-G071RB with STLINK/V2-1 firmware versions V2J33M25, V2J45M30, and a WeActStudio BluePillPlus stm32f103cb running Blackmagic Debug Firmware v1.10.2 (+ BluePill+ PCB patches for PB2 LED and SPI1). The latter displays expected MINDP operation in BMPremote logs. Affected targets would be any MINDP debuggable with a stlinkv2, including ST parts with Cortex-M0 (F0 family) and Cortex-M0+ (l0, g0, c0, u0).