hackpascal / ufprog

Universal Flash Programmer
69 stars 20 forks source link

希望可以支持 CH347F #6

Closed 0wQ closed 8 months ago

0wQ commented 8 months ago

作者您好,我制作了一个 CH347F 的编程器,但是无法识别使用,测试官方 DEMO 板也是一样的问题。 手上没有 CH347T,但是使用 CH341 识别是正常的,不知是否操作不正确。 测试沁恒官方的 CH347Demo.exe 是可以正常使用的,如果不支持请问是否可以适配一下?

PS C:\Data\ufprog-win64-mingw-msvcrt-2023-09-18> .\ufsnorprog.exe dev=ch341 uid
Universal flash programmer for SPI-NOR 1.0 [Portable]
Author: Weijie Gao <hackpascal@gmail.com>

Loaded controller plugin WCH CH341 (DLL)
CH341-DLL: Opened device 0
Opened interface device 'ch341' using driver 'ch341-dll'

Manufacturer:       Winbond
Part:               W25Q64FV
Capacity:           8MB

Unique ID: d1640850a72d1636
PS C:\Data\ufprog-win64-mingw-msvcrt-2023-09-18> .\ufsnorprog.exe dev=ch347 uid
Universal flash programmer for SPI-NOR 1.0 [Portable]
Author: Weijie Gao <hackpascal@gmail.com>

Loaded controller plugin WCH CH347 (DLL)
[ERROR] CH347-DLL: Device 0 is not in SPI mode
[WARN] CH347-DLL: No device specified by match#0 could be opened
[ERROR] Failed to open interface device using 'C:\Data\ufprog-win64-mingw-msvcrt-2023-09-18\device\ch347.json'
[ERROR] No interface device named 'ch347' could be opened
Failed to open device 'ch347'
PS C:\Data\ufprog-win64-mingw-msvcrt-2023-09-18> .\ufsnorprog.exe dev=ch347-libusb uid
Universal flash programmer for SPI-NOR 1.0 [Portable]
Author: Weijie Gao <hackpascal@gmail.com>

Loaded controller plugin WCH CH347 (libusb)
[ERROR] Failed to open interface device using 'C:\Data\ufprog-win64-mingw-msvcrt-2023-09-18\device\ch347-libusb.json'
[ERROR] No interface device named 'ch347-libusb' could be opened
Failed to open device 'ch347-libusb'
PS C:\Data\ufprog-win64-mingw-msvcrt-2023-09-18> .\ufsnorprog.exe dev=ch347-hid uid
Universal flash programmer for SPI-NOR 1.0 [Portable]
Author: Weijie Gao <hackpascal@gmail.com>

Loaded controller plugin WCH CH347 (HID)
[ERROR] CH347-HID: Unable to enumerate HID devices: No HID devices with requested VID/PID found in the system.
[ERROR] Failed to open interface device using 'C:\Data\ufprog-win64-mingw-msvcrt-2023-09-18\device\ch347-hid.json'
[ERROR] No interface device named 'ch347-hid' could be opened
Failed to open device 'ch347-hid'
hackpascal commented 8 months ago

ch347和ch347-libusb使用的驱动程序是不一样的 ch347使用WCH的原厂驱动,通过ch347dll.dll/ch347dlla64.dll进行通信 ch347-libusb使用libusb(winusb)驱动,通过libusb.dll进行通信 只有ch347-hid是免驱的,可以直接使用

但是注意,板子的工作模式必须要设置正确: ch347和ch347-libusb要求ch347处于工作模式1,usb pid必须是55db ch347-hid要求ch347处于工作模式2,usb pid必须是55dc 你有没有检查过这个地方?

此外你说

测试沁恒官方的 CH347Demo.exe 是可以正常使用的

那说明你使用的是WCH的原厂驱动。但是根据你贴出的信息

[ERROR] CH347-DLL: Device 0 is not in SPI mode

ufprog确实通过原厂驱动dll检测到了你的板子,但是板子没有处在工作模式1

因此我也就不清楚为何CH347Demo.exe 可以正常使用

0wQ commented 8 months ago

非常感谢您的回复,抱歉回复比较晚。

我对相关开发不太了解,fork后尝试修改适配了一下,简单测试了一下 dev=ch347 应该没问题,如果有需要我可以提一个PR。

可能还需要进一步适配,如果有需要可以送您一个我开源的编程器 https://oshwhub.com/azunya/ch347f

修改后测试截图

问题 1 回复:

> 但是注意,板子的工作模式必须要设置正确: > ch347和ch347-libusb要求ch347处于工作模式1,usb pid必须是55db > ch347-hid要求ch347处于工作模式2,usb pid必须是55dc > 你有没有检查过这个地方? 在 [CH347DS1.PDF](https://www.wch.cn/downloads/CH347DS1_PDF.html) 中,CH347F 的 pid 是 55de ![image](https://github.com/hackpascal/ufprog/assets/20741439/027ac9c2-0590-4487-b3c9-201abed8a38a) `CH347Demo.exe` 截图: ![image](https://github.com/hackpascal/ufprog/assets/20741439/f0af1b83-55a0-4571-be7f-1b5718368023)

问题 2 回复:

> 此外你说 > > 测试沁恒官方的 CH347Demo.exe 是可以正常使用的 > > 那说明你使用的是WCH的原厂驱动。但是根据你贴出的信息 > > [ERROR] CH347-DLL: Device 0 is not in SPI mode > > ufprog确实通过原厂驱动dll检测到了你的板子,但是板子没有处在工作模式1 在项目代码中可以看到是此处在报错,我猜测可能是 CH347F 芯片功能接口号为 `#define CH347_FUNC_JTAG_IIC_SPI 3 //CH347F` 的原因 https://github.com/hackpascal/ufprog/blob/a6f41a049512467de9c589a6f9e6c3d27a4b3e8f/controller/wch/ch347-dll.c#L73-L80 https://github.com/hackpascal/ufprog/blob/a6f41a049512467de9c589a6f9e6c3d27a4b3e8f/controller/wch/ch34x-dll.h#L23-L26 在 [CH347应用开发手册.pdf](https://www.wch.cn/downloads/CH347EVT_ZIP.html) 中: ![image](https://github.com/hackpascal/ufprog/assets/20741439/a103d1bc-d2c3-48d9-b379-de092f412fd4) 以及 ChipMode 我看到 CH347F 也是不同的 https://github.com/hackpascal/ufprog/blob/a6f41a049512467de9c589a6f9e6c3d27a4b3e8f/controller/wch/ch347-dll.c#L23-L28 ![image](https://github.com/hackpascal/ufprog/assets/20741439/938698fe-20aa-4641-9a93-d33ad094616d)
hackpascal commented 8 months ago

好吧。看来我手里面的资料不包含ch347f的部分 🤣 感谢你指出这部分的问题。我会按我自己的方式来修改ch347f的匹配代码。

可能还需要进一步适配,如果有需要可以送您一个我开源的编程器 https://oshwhub.com/azunya/ch347f

这当然是极好的 😆 毕竟我确实需要验证

0wQ commented 8 months ago

好吧。看来我手里面的资料不包含ch347f的部分 🤣 感谢你指出这部分的问题。我会按我自己的方式来修改ch347f的匹配代码。

可能还需要进一步适配,如果有需要可以送您一个我开源的编程器 https://oshwhub.com/azunya/ch347f

这当然是极好的 😆 毕竟我确实需要验证

给您 gmail 邮箱发送邮件了

hackpascal commented 8 months ago

已添加支持:https://github.com/hackpascal/ufprog/commit/85f6440c1d1b7ee48c0729e4a70e41babf3944d7