It has been a while since I touched my CH32Vxxx boards. If I want to have a look at them again, I will need an OpenOCD version with support for the WCH-Link and WCH_LinkE.
Looking around online, I found the most recent version is found at https://github.com/cjacker/wch-openocd, currently at commit 2b6802d, which was 2 years ago.
Attempting to build OpenOCD in this state will fail, due to a missing configure file in the jimctlc directory. To solve this, I have replaced its contents with a checkout of their repository at git tag 0.80. Then the build should complete, using the provided instructions and adding CFLAGS like `CFLAGS=-Wno-incompatible-pointer-types` to the configure script.
Like I mentioned previously, it had been years since I have touched my WCH stuff. Back then I did update my WCH-Link(E) to the latest firmware to make them work with the then latest OpenOCD version. However, this firmware appears too old to work with this new OpenOCD version. It prints the firmware version and then exists.
The version of the firmware that was present on both WCH-Link and WCH-LinkE was v2.7(v27).
To update the firmware version, there is a tool called wlink-iap. However, attempting a firmware update with this tool resulted in bricked devices, both for the WCH-Link and WCH-LinkE.
To update the WCH-Link, I opened the device and bridges the pads below the MCU. When powered up the device is in a bootloader mode, and then a tool called ch552tool can be used to write the firmware.
To update the WCH-LinkE, a working WCH-LinkE, needs to be connected to it. SWDIO to SWDIO, SWDCLK to SWCLK, and off course ground. However, both devices must be USB powered. Then using the wlink tool. This tool works fine with the older firmware version. I have tried a WCH-Link with updated firmware, however, the wlink tool freezes little after starting the flashing process.
16:59:28 [INFO] Connected to WCH-Link v2.12(v32) (WCH-Link-CH549)
16:59:28 [INFO] Attached chip: CH32V30X [CH32V305FBP6] (ChipID: 0x30520518)
16:59:28 [INFO] Chip ESIG: FlashSize(128KB) UID(cd-ab-06-e5-48-bc-1b-4d)
16:59:28 [INFO] Flash protected: false
16:59:28 [INFO] Read /home/andre/git/openocd/cjacker//opensource-toolchain-ch32v/firmwares/Firmware_Link/WCH-LinkE-APP-IAP.bin as Binary format
16:59:28 [INFO] Flashing 101872 bytes to 0x08000000
16:59:28 [INFO] Read protected: false
4096/101872
Using the WCH-LinkE with old firmware, the flashing works correctly.
17:02:46 [INFO] Connected to WCH-Link v2.7(v27) (WCH-LinkE-CH32V305)
17:02:47 [INFO] Attached chip: CH32V30X [CH32V305FBP6] (ChipID: 0x30520518)
17:02:47 [INFO] Chip ESIG: FlashSize(128KB) UID(cd-ab-06-e5-48-bc-1b-4d)
17:02:47 [INFO] Flash protected: false
17:02:47 [INFO] Read /home/andre/git/openocd/cjacker//opensource-toolchain-ch32v/firmwares/Firmware_Link/WCH-LinkE-APP-IAP.bin as Binary format
17:02:47 [INFO] Flashing 101872 bytes to 0x08000000
17:02:47 [INFO] Read protected: false
101872/101872
17:02:52 [INFO] Flash done
17:02:53 [INFO] Now reset...
The firmwares we want to flash are found in the opensource-toolchain-ch32v repository. The current versions in there are WCH-Link v2.12(v32) and WCH-LinkE v2.15(v35).
Now these firmwares are updated, OpenOCD correctly connects to the target MCU. This is as far as I will go today. Actually trying if it works as expected will be for another day.