Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Upgrade WCH-Link firmware #42

Open
andelf opened this issue Nov 23, 2023 · 10 comments
Open

Feature Request: Upgrade WCH-Link firmware #42

andelf opened this issue Nov 23, 2023 · 10 comments

Comments

@andelf
Copy link
Contributor

andelf commented Nov 23, 2023

esp. for macOS users.

@sass20
Copy link

sass20 commented Feb 18, 2024

hi
Can you add show virsion of firmware in wchlink?

@andelf
Copy link
Contributor Author

andelf commented Feb 19, 2024

It's already displayed in basic logging:

16:26:11 [INFO] Connected to WCH-Link v2.11(v31) (WCH-LinkE-CH32V305)

v31 is used by official tools.
v2.11 is the original version. => 0x020a

@sass20
Copy link

sass20 commented Feb 19, 2024

I connect wch-linkE only, wutout targer cpu and run wlink.exe -v

wlink.exe -v
19:51:13 [INFO] Found WCH-LinkRV, Bus 001 Device 005: ID 1a86:8010
No command given, use --help for help.
hint: use wlink status to get started.

if I run command wlink.exe status
it is have this output
wlink.exe status
Error: USB error: Entity not found

Caused by:
Entity not found
What is options need place for show [INFO] Connected to

i start wlink.exe on WIN10 OS
thank you

@andelf
Copy link
Contributor Author

andelf commented Feb 20, 2024

A new "list" subcommand is added recently.

@orangecms
Copy link

orangecms commented Nov 3, 2024

I have the first WCH-Link, the one based on CH549.
I want to flash a CH32V003, which is currently not supported.

So I tried upgrading the WCH-Link firmware, using the file WCH-LinkUtility/Firmware_Link/FIRMWARE_CH549.bin from the WCH Link Utility zip file with the J1 switch and wchisp. Now it is no longer showing up on USB. There are also the following files:

FIRMWARE_CH32V203.bin  FIRMWARE_CH549.bin      WCH-DAPLink_APP_IAP.bin   WCH-LinkE-APP-IAP.bin
FIRMWARE_CH32V208.bin  FIRMWARE_DAP_CH549.bin  WCH-Link_APP_IAP_ARM.bin  WCH-LinkW-APP-IAP.bin
FIRMWARE_CH32V305.bin  firmware_version.txt    WCH-Link_APP_IAP_RV.bin   wchlink.wcfg

Do you have any idea? Would I need to flash one of those *_APP_* files to another location?

EDIT: I flashed the WCH-Link_APP_IAP_RV.bin and now the programmer shows up as 1a86:8010 QinHeng Electronics WCH-Link again. 😌

@cjacker
Copy link

cjacker commented Nov 29, 2024

[Info] temp firmware-upgrade solution without windows.

Please refer to https://github.com/cjacker/opensource-toolchain-ch32v?tab=readme-ov-file#how-to-update-firmware-of-wch-linke

for wch-link(ch549)

1, Enter ISP mode by short DP pin(P5.1) and 3v3 VCC pin when power up.
2. use ch552tool to erase and program the firmware:

ch55xtool -e -c
ch55xtool -f WCH-Link_APP_IAP_RV.bin

for wch-linke(ch32v305fbp6)

1, prepare another WCH-LinkE and wire up the target WCH-LinkE as:

 +------------+            +-----------+
 |            |----3v3-----|           |
 |            |            |           |
 |            |----gnd-----|           |
 |            |            |  target   |
 | WCH-LinkE  |----dio-----| WCH-LinkE |
 |            |            |  to be    |
 |            |----clk-----|  update   |
 |            |            |           |
 |            |----nrst----|           |
 +------------+            +-----------+

2, hold IAP button of "target WCH-LinkE" down and plug WCH-LinkE to PC USB port. When power up, the "target WCH-LinkE" will enter IAP mode. Acctually below steps is not IAP update, but entering IAP mode will release the occupied DIO/CLK pins, otherwise the target WCH-LinkE can not be probed and programmed.

Official WCH-LinkE has a plastic case, you can not press the IAP button unless break the case, you can use wlink-iap to toggle IAP mode of the target WCH-LinkE as:

Plug the "target WCH-LinkE" to PC USB port first, And run wlink-iap -i.
After the "target WCH-LinkE" was switched to IAP mode, unplug the target WCH-LinkE and plug WCH-LinkE to PC USB port, this time you don't have to hold the IAP button down of target WCH-LinkE.

3, update firmware:

wlink erase --method pin-rst --speed low --chip CH32V30X
wlink flash WCH-LinkE-APP-IAP.bin

@cjacker
Copy link

cjacker commented Nov 29, 2024

Info: the process that WCH-LinkUtility update firmwares online

After analysing McuCompilerDLL.dll:

  1. OpenDevice: libusb_open/configuration/claim_interface. WCH-LinkUtility(windows) use ch375 functions.
  2. read adapter type / version.
  3. find corresponding chiptype of adatper type and firmware and compare the version with 'wchlink.wcfg'. the firmware for WCH-LinkE is: FIRMWARE_CH32V305.bin
  4. If outdated, setIAPmode.
    • malloc a buffer and load corresponding firmware to the buffer.
    • setIAPmode by write "0x01010f81" len 4 and no read, since the "1a86:8010" disappear after setIAPmode.
  5. usleep(3500*1000) , then OpenDevice "4348:55e0", configuration and claim interface 0.
  6. write "0x00000281" len 4 to endp 2.
  7. read len 2 from endp 2, 0x00 0x00 as expected.
  8. start program the firmware using IAP method.
  9. first loop, allocate a small_buffer with size 64, memset to 0, memcpy 60 from firmware buffer to small_buffer+4, small_buffer[0] = 0*2+0x80, small_buffer[1] = 0x3C(60, data length), small_buffer[2]=offset, small_buffer[3]=offset>>8; write to endp 2 and read len 2, 0x0000 expected.
  10. second loop, as same as firstloop except small_buffer[0] =1*2+0x80.
  11. After firmware written, write 0x00000283 to quit IAP mode?

@cjacker
Copy link

cjacker commented Nov 29, 2024

Done.

wlink-iap: A tool to upgrade / downgrade WCH-LinkE firmware online using IAP method.

Test with:

  • wch-link
  • wch-linke r0 1v2 and r0 1v3.
  • various thirdparty link/linke.

please refer to: https://github.com/cjacker/wlink-iap

Hope wlink can implement this feature soon and deprecate my project.

@andelf
Copy link
Contributor Author

andelf commented Nov 30, 2024

@cjacker Thanks. That's helpful. Now I can rewrite the c code into Rust to impl this. 😆

@cjacker
Copy link

cjacker commented Dec 2, 2024

@cjacker Thanks. That's helpful. Now I can rewrite the c code into Rust to impl this. 😆

Please consider to add two options to involk enter iap mode and quit iap mode standalone . It seems still useful under some special situations:

1, To erase the whole data flash or/and reprogram the whole firmware with another wch-linke, it requires to enter IAP mode first by a physical button or by “ 0x01010f81” cmd. For official wchlinke, it has a case and not convenient to hold the IAP button down when power up. Some thirdparty device such as YD-Link even have no buttons on board.

2, User may accidently enter iap mode when using thirdparty wchlink since they all have no case, maybe user just want to switch rv/dap mode but hold the wrong button, I made such mistake before. And it has no chance to leave IAP mode anymore even with wch linkutility except reprogramming the firmware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants