dirtyjtag / DirtyJTAG

JTAG probe firmware
MIT License
464 stars 70 forks source link

Dongle programming documentation for the CK32-based clones (of the stlinkv2 clones) #83

Closed brainstorm closed 3 years ago

brainstorm commented 3 years ago

Following the instructions on stlinkv2-swd on a CK32 clone:

IMG_1125 IMG_1124

I get this:

$ openocd -f interface/stlink.cfg -f target/stm32f1x.cfg
Open On-Chip Debugger  v0.10.0-esp32-20201202-2-g7e342cad (2021-01-02-23:47)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 1000 kHz
Info : STLINK V2J29S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.135834
Warn : UNEXPECTED idcode: 0x2ba01477
Error: expected 1 of 1: 0x1ba01477

Which is easily solved by modifying interfaces/stlink.cfg accordingly, let's create a new file under target call it stlink-ck32.cfg:

--- stm32f1x.cfg    2021-01-28 22:55:43.000000000 +1100
+++ ck32.cfg    2021-01-28 22:55:55.000000000 +1100
@@ -39,7 +39,7 @@
       set _CPUTAPID 0x3ba00477
    } {
       # this is the SW-DP tap id not the jtag tap id
-      set _CPUTAPID 0x1ba01477
+      set _CPUTAPID 0x2ba01477
    }
 }

Trying again with the CK32 TAPID:

$ openocd -f interface/stlink.cfg -f target/ck32.cfg
Open On-Chip Debugger  v0.10.0-esp32-20201202-2-g7e342cad (2021-01-02-23:47)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 1000 kHz
Info : STLINK V2J29S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.135834
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Info : accepting 'telnet' connection on tcp/4444
target halted due to debug-request, current mode: Thread
xPSR: 0x81000000 pc: 0x0800128e msp: 0x200007d8
Info : device id = 0x20036410
Info : flash size = 64kbytes

Then following the official documentation for unlocking works fine:

$ telnet localhost 4444
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> halt
target halted due to debug-request, current mode: Thread
xPSR: 0x81000000 pc: 0x0800128e msp: 0x200007d8
> stm32f1x unlock 0
device id = 0x20036410
flash size = 64kbytes
stm32x unlocked.
INFO: a reset or power cycle is required for the new settings to take effect.

> reset
> exit
Connection closed by foreign host.

And also following the flashing docs for STlink v2 via SWD, one should see the following messages:

$ st-flash write dirtyjtag.stlinkv2.bin 0x8000000
st-flash 1.6.0
2021-01-28T20:40:19 INFO common.c: Loading device parameters....
2021-01-28T20:40:19 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2021-01-28T20:40:19 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
2021-01-28T20:40:19 INFO common.c: Attempting to write 8504 (0x2138) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08002000 erased
2021-01-28T20:40:19 INFO common.c: Finished erasing 9 pages of 1024 (0x400) bytes
2021-01-28T20:40:19 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2021-01-28T20:40:19 INFO flash_loader.c: Successfully loaded flash loader in sram
  9/9 pages written
2021-01-28T20:40:19 INFO common.c: Starting verification of write complete
2021-01-28T20:40:20 INFO common.c: Flash written and verified! jolly good!

Otherwise a locked target errors look like this:

(..)
2021-01-28T20:34:11 INFO flash_loader.c: Successfully loaded flash loader in sram
2021-01-28T20:34:14 ERROR flash_loader.c: flash loader run error
2021-01-28T20:34:14 ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1
stlink_fwrite_flash() == -1

Hope this helps folks! ;)