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

Add commands for controling IAP mode #84

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

21km43
Copy link
Contributor

@21km43 21km43 commented Jan 17, 2025

I read this issue and implemented commands which controls IAP mode.

Commands:
  iap          Enter or quit IAP mode

Example:

> wlink iap
[WARN] This is an experimental feature, better use the WCH-LinkUtility!
Please choose one mode to switch, either --enter or --quit

> wlink iap --enter
<WCH-Link#0 libusb device> Bus 001 Device 031 ID 1a86:8010(USB-FS 12 Mbps) (RV mode)
[WARN] This is an experimental feature, better use the WCH-LinkUtility!
[INFO] Enter IAP mode

> wlink iap --quit
<WCH-Link#0 libusb device> Bus 001 Device 026 ID 4348:55e0(USB-FS 12 Mbps) (IAP mode)
[WARN] This is an experimental feature, better use the WCH-LinkUtility!
[INFO] Quit IAP mode

> wlink mode-switch --dap
<WCH-Link#0 libusb device> Bus 001 Device 033 ID 1a86:8010(USB-FS 12 Mbps) (RV mode)
[WARN] This is an experimental feature, better use the WCH-LinkUtility!
[INFO] Connected to WCH-Link v2.14(v34) (WCH-LinkE-CH32V305)
[INFO] Switch mode for WCH-LinkRV

> wlink iap --enter
<WCH-Link#0 libusb device> Bus 001 Device 028 ID 1a86:8012(USB-FS 12 Mbps) (DAP mode)
[WARN] This is an experimental feature, better use the WCH-LinkUtility!
[INFO] Enter IAP mode

> wlink iap --quit
<WCH-Link#0 libusb device> Bus 001 Device 026 ID 4348:55e0(USB-FS 12 Mbps) (IAP mode)
09:12:44 [WARN] This is an experimental feature, better use the WCH-LinkUtility!
09:12:44 [INFO] Quit IAP mode

@21km43
Copy link
Contributor Author

21km43 commented Jan 18, 2025

In my environment, Zadig is needed when quit IAP mode. (windows-x86 exe)

@21km43 21km43 marked this pull request as draft January 19, 2025 08:30
@21km43
Copy link
Contributor Author

21km43 commented Jan 19, 2025

In my environment, Zadig is needed when quit IAP mode. (windows-x86 exe)

Supported controling IAP mode without Zadig (x86 only)

 CH375_DRIVER = Some(
     Library::new("WCHLinkDLL.dll")
         .map_err(|_| Error::Custom("WCHLinkDLL.dll not found".to_string()))?,
 );
-let lib = CH375_DRIVER.as_ref().unwrap();
+let mut lib = CH375_DRIVER.as_ref().unwrap();
 
+ // For IAP mode, load CH375DLL.dll if USB ID is zero
+ let get_usb_id: Symbol<unsafe extern "stdcall" fn(u32) -> u32> =
+     { lib.get(b"CH375GetUsbID").unwrap() };
+ if get_usb_id(0) == 0x0000_0000 {
+     CH375_DRIVER = Some(
+         Library::new("CH375DLL.dll")
+             .map_err(|_| Error::Custom("CH375DLL.dll not found".to_string()))?,
+     );
+    lib = CH375_DRIVER.as_ref().unwrap();
+}

@21km43 21km43 marked this pull request as ready for review January 19, 2025 09:15
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

Successfully merging this pull request may close these issues.

1 participant