First steps of LibSWD and OpenOCD

The LibSWD and OpenOCD has just made its first steps into flash memory access and writing program code to the ARM Cortex-M3 based Stm32Primer2 device using cheap and generic FT2232H‘s based JTAG/SWD KT-LINK interface :-) The current connection speed is around 10sec/1kB but still I have some ideas on how to improve it, even with the USB bottleneck. The LibSWD is platform independent, so it can drive any other type of hardware (RLink, GPIO based, Parallel Port, etc), also it can be uploaded into dedicated hardware dongle if necessary :-) Feedback and testing are welcome :-)

You can get the code from remote GIT repository at The project implementation details and history is at

%telnet localhost 4444
 Connected to localhost.
 Escape character is '^]'.
 Open On-Chip Debugger
 > halt
 target was in unknown state when halt was requested
 > flash probe 0
 device id = 0x10016414
 flash size = 512kbytes
 device id = 0x10016414
 flash size = 512kbytes
 flash 'stm32x' found at 0x08000000
 > stm32x mass_erase 0
 stm32x mass erase complete
 > flash write_image toggle.hex
 wrote 1936 bytes from file toggle.hex in 18.636387s (0.101 KiB/s)



Hi Tomek,

I would like to try your swd/openocd work, but I have a slightly different ft2232 based jtag debugger than your KT-LINK: I have the jtagkey. I guess I would have to write a jtagkey_init_swd routine similar to your ktlink_init_swd routing, but I’m struggling with the meaning of all the values that are assigned in this routine such as low_output, low_direction, high_output and high_direction. Could you explain to me what the are so that I can change them appropriately for my debugger?



Tomek Cedro

Hello Armin :-) Please ask this question on OpenOCD project [1] developers mailing list [2] – patches for LibSWD+OpenOCD has just been sent to the main project source code repository [3], so this is perfect moment for asking questions, testing and adding new features :-)
Best regards :-)