Fix OpenOCD debug in STM32CubeIDE for clones, like CS32F103 on Linux
Find st_scripts
directory for OpenOCD with file mem_helper.tcl
, or other file with scripts, in plugins directory of STM32CubeIDE
Append to file
proc _find_target {apnum} {
foreach t [target names] {
if {[$t cget -ap-num] == $apnum && [$t cget -type] == "mem_ap"} {
return $t
}
}
foreach t [target names] {
if {[$t cget -ap-num] == $apnum && [$t cget -type] == "cortex_m"} {
return $t
}
}
foreach t [target names] {
if {[$t cget -type] == "cortex_m"} {
return $t
}
}
return [target current]
}
# Reads memory after MEM-AP
proc ReadMemAP {apbaseaddr address items flags} {
echo [format "ReadMemAP 0x%08X 0x%08X 0x%08X 0x%08X" $apbaseaddr $address $items $flags]
if {$apbaseaddr == 0x00 && $address == 0xE00FFFD0 && $items == 0x08 && $flags == 0x00} {
return "O.K.:0x00000000,0x00000000,0x00000000,0x00000000,0x00000010,0x00000004,0x0000000a,0x00000000"
}
set dap [[target current] cget -dap]
set apsel [expr {$apbaseaddr >> 24}]
set value "O.K.:"
set separator ""
for {set i 0} {$i < $items} {incr i} {
lappend value $separator 0x[lindex [[_find_target $apsel] mdw $address] 1]
incr address 4
set separator ","
}
echo [format "%s" [join $value ""]]
return [join $value ""]
}
# Reads the specified CoreSight DAP-AP register
proc ReadAPEx {apbaseaddr regaddr} {
echo [format "ReadAPEx 0x%08X 0x%08X" $apbaseaddr $regaddr]
if {$apbaseaddr == 0x00 && $regaddr == 0xF8} {
return "O.K.:0xE00FF003"
}
set dap [[target current] cget -dap]
set apsel [expr {$apbaseaddr >> 24}]
set value [$dap apreg $apsel $regaddr]
echo [format "O.K.:0x%08X" $value]
return [format "O.K.:0x%08X" $value]
}
Find openocd binary in plugins directory and patch with HEX editor: replace all ReadAPEx
string to other, like ReadAPEw
.