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

"Invalid payload length" on WCH-Link CH549 at ProbeInfo response payload #68

Open
rowanclarke opened this issue Aug 13, 2024 · 7 comments

Comments

@rowanclarke
Copy link

Running wlink -vv regs gives the following output:

13:15:09 [TRACE] (1) wlink::usb_device::libusb: [src/usb_device.rs:118] Device: Bus 002 Device 003: ID 1a86:8010
13:15:09 [DEBUG] (1) wlink::usb_device::libusb: Serial number: "0001A0000001"
13:15:09 [TRACE] (1) wlink::probe: [src/probe.rs:196] send command: GetProbeInfo
13:15:09 [TRACE] (1) wlink::probe: [src/probe.rs:177] send 810d01 01
13:15:09 [TRACE] (1) wlink::probe: [src/probe.rs:187] recv 820d02 0201
Error: Invalid payload length

The error arises from the ProbeInfo response here, where there must be at least three bytes in the payload but my payload only contains two bytes [2, 1]. It then seems as though only the first two bytes are being used.

What should the payload of three bytes look like if only the first two are going to being used?

Thanks,
Rowan

@fanoush
Copy link

fanoush commented Sep 29, 2024

Almost the same here

$ ./wlink -vv status
15:24:37 [TRACE] (1) wlink::usb_device::libusb: [src/usb_device.rs:118] Device: Bus 007 Device 031: ID 1a86:8010
15:24:37 [DEBUG] (1) wlink::usb_device::libusb: Serial number: "0001A0000001"
15:24:37 [TRACE] (1) wlink::probe: [src/probe.rs:196] send command: GetProbeInfo
15:24:37 [TRACE] (1) wlink::probe: [src/probe.rs:177] send 810d01 01
15:24:37 [TRACE] (1) wlink::probe: [src/probe.rs:187] recv 820d02 0203
Error: Invalid payload length

this is wch link with older combined firmware where you can still switch between ARM CMSIS-DAP and RISCV mode by grounding TX pin when plugging device in.

When updating to newer RISCV only firmware it works fine

$ ./wlink -vv status
15:31:09 [TRACE] (1) wlink::usb_device::libusb: [src/usb_device.rs:118] Device: Bus 007 Device 033: ID 1a86:8010
15:31:09 [DEBUG] (1) wlink::usb_device::libusb: Serial number: "434AC30F0659"
15:31:09 [TRACE] (1) wlink::probe: [src/probe.rs:196] send command: GetProbeInfo
15:31:09 [TRACE] (1) wlink::probe: [src/probe.rs:177] send 810d01 01
15:31:09 [TRACE] (1) wlink::probe: [src/probe.rs:187] recv 820d04 020c0100
15:31:09 [INFO] Connected to WCH-Link v2.12(v32) (WCH-Link-CH549)
15:31:09 [TRACE] (1) wlink::probe: [src/probe.rs:196] send command: SetSpeed { riscvchip: 1, speed: High }
15:31:09 [TRACE] (1) wlink::probe: [src/probe.rs:177] send 810c02 0101
15:31:09 [TRACE] (1) wlink::probe: [src/probe.rs:187] recv 820c01 01
15:31:09 [TRACE] (1) wlink::probe: [src/probe.rs:196] send command: AttachChip
15:31:09 [TRACE] (1) wlink::probe: [src/probe.rs:177] send 810d01 02
15:31:09 [TRACE] (1) wlink::probe: [src/probe.rs:187] recv 815501 01
15:31:09 [DEBUG] (1) wlink::operations: retrying...
...

the 0203 response is probably firmware version 2.03, newer one is 2.12 and the response is 4 bytes instead of 2

@fourMew
Copy link

fourMew commented Sep 30, 2024

I encountered this same error using a CH549 based WCH-Link. Flashing a new firmware using the official WCH-LinkUtility and then switching to WinUSB drivers fixed it for me.

@fanoush
Copy link

fanoush commented Sep 30, 2024

but anyway, the line

if bytes.len() < 3 {

should probably have < 2 not < 3 so it is worth fixing if older firmware would otherwise work. As mentioned older firmware has both ARM and RISCV versions combined, so if one uses devices with both cpu families and it otherwise works, one may prefer to keep the older version.

EDIT: Here is build with this change https://github.com/fanoush/wlink/actions/runs/11108154349 with downloadable artifacts, did not try with the device yet.

@fanoush
Copy link

fanoush commented Sep 30, 2024

I have tried it and detection now works but it does not detect attached CH32V305 device

$ ./wlink status
16:09:18 [INFO] Connected to WCH-Link v2.3(v23) (WCH-Link-CH549)
Error: Probe is not attached to an MCU, or debug is not enabled. (hint: use wchisp to enable debug)

When testing another CH549 based wch-link with updated firmware it finds it

$ ./wlink status
16:16:40 [INFO] Connected to WCH-Link v2.12(v32) (WCH-Link-CH549)
16:16:40 [INFO] Attached chip: CH32V30X [CH32V305FBP6] (ChipID: 0x30520528)
16:16:40 [INFO] Chip ESIG: FlashSize(128KB) UID(...........)
16:16:40 [INFO] Flash protected: false
16:16:40 [INFO] RISC-V ISA(misa): Some("RV32ACFIMUX")
16:16:40 [INFO] RISC-V arch(marchid): Some("WCH-V4A")
....

so unfortunately this is not the only change needed. I don't have WCH RISCV devices older than 305/307 so can't test if older chips would work with older firmware.

@ITstreet1
Copy link

I encountered this same error using a CH549 based WCH-Link. Flashing a new firmware using the official WCH-LinkUtility and then switching to WinUSB drivers fixed it for me.

Where did you find the firmware for this one? I need it, too.

@fanoush
Copy link

fanoush commented Dec 18, 2024

it is part of the wch-link utility zip from https://www.wch.cn/downloads/wch-linkutility_zip.html I think it is the WCH-Link_APP_IAP_RV.bin inside Firmware_Link folder if you want to flash risc-v chips and the WCH-Link_APP_IAP_ARM.bin if you want CMSIS-DAP functionality

@ITstreet1
Copy link

it is part of the wch-link utility zip from https://www.wch.cn/downloads/wch-linkutility_zip.html I think it is the WCH-Link_APP_IAP_RV.bin inside Firmware_Link folder if you want to flash risc-v chips and the WCH-Link_APP_IAP_ARM.bin if you want CMSIS-DAP functionality

Mate, thanks in a million!
I have this firmware from a year ago and didn't know what I have, LOL. This solved everything.

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

No branches or pull requests

4 participants