pok3r-custom / pok3rtool

Command line tool and library for keyboards using qmk-pok3r
BSD 3-Clause "New" or "Revised" License
41 stars 7 forks source link

Add Holtek ISP USB Protocol Support (using libusb) #15

Closed hansemro closed 1 year ago

hansemro commented 1 year ago

See #12.

Working commands (with -t isp):

Non-working commands:

Depends on #14 to support cross-platform control transfers. However, this does have a major Windows regression that prevents keyboard usage pair from being read via control transfer while it is using the native hid driver. Temporarily switching to WinUSB driver can resolve these issues, but this step can be annoying considering most of the supported HID-IAP protocols don't use control transfers.

lunohod-1 commented 1 year ago

It worked like a charm on my pok3r. I had to connect SEL1 to VCC and SEL2 to GND to get ISP working: image PXL_20221225_190610512

hansemro commented 1 year ago

@lunohod-1 Do you mind sharing any issues or hurdles you have experienced? I've realized that the documentation is a bit poor and could be improved. Also, which OS did you test with?

lunohod-1 commented 1 year ago

@hansemro I struggled a bit with compiling pok3rtool and qmk_pok3r on my ubuntu/debian systems. What was not really clear to me is that SEL1 and SEL2 are aready connected to BOOT0/BOOT1 pins. I read "short BOOT to ground" and tried to solder the wire directly to the chip and connect it to GND, but that did not work. Then I discovered that I can use SEL1/SEL2 and found how to wire them to get into bootloader mode. After that it was straight forward flashing pok3r firmware_builtin.bin and then qmk.

hansemro commented 1 year ago

@lunohod-1 I see.

I struggled a bit with compiling pok3rtool and qmk_pok3r on my ubuntu/debian systems

I assume this has to do with SIGSTKSZ in libchaos? I did create a PR to fix this: https://github.com/ChaoticEnigma/libchaos/pull/5

I read "short BOOT to ground" and tried to solder the wire directly to the chip and connect it to GND, but that did not work. Then I discovered that I can use SEL1/SEL2 and found how to wire them to get into bootloader mode.

According to POK3R Notes wiki page (https://github.com/pok3r-custom/pok3r_re_firmware/wiki/POK3R-Notes), the boot pins are (weakly) tied high (as is on several keyboards), so shorting just BOOT1/SEL2 to ground should have done the job. Anyhow, this was not referenced well and should be noted.

(I wrote BOOT(1) due to observations above and because HT32F523x2 only have 1 BOOT pin which is not numbered.)

lunohod-1 commented 1 year ago

@hansemro yes, that one and the udev library is not discovered by cmake.

IIRC, just shorting SEL2 to ground did not work for me. I've got another pok3r to flash and I'll check again later.

For the qmk_pok3r build I just took a ubuntu:16.04 docker image.

BTW, I saw your pull-request to qmk, does the recent qmk version work fine on your keyboard?

hansemro commented 1 year ago

@lunohod-1

udev library is not discovered by cmake.

Not sure what you mean. I am aware that udev is not explicitly required to build pok3rtool but is required to make the USB devices accessible by the tool. Did you want the rule file to be installed to /usr/lib/udev/rules.d/ with cmake or something?

BTW, I saw your pull-request to qmk, does the recent qmk version work fine on your keyboard?

Latest qmk works fine on my cooler master keyboards although an additional patch is needed for stable SPI flash support (https://github.com/hansemro/ChibiOS-Contrib/commit/149fd60d274409eeea813a4ecc3759d7e478c875).

Are you interested in getting mainline qmk on pok3r?

lunohod-1 commented 1 year ago

@hansemro [ 97%] Linking CXX executable pok3rtool /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/libusb-1.0.a(linux_udev.o): in functionudev_hotplug_event': (.text+0x2c): undefined reference to udev_device_get_action' /usr/bin/ld: (.text+0x5c): undefined reference toudev_device_get_devnode' /usr/bin/ld: (.text+0x6c): undefined reference to udev_device_get_sysname' /usr/bin/ld: (.text+0xa2): undefined reference toudev_device_unref' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/libusb-1.0.a(linux_udev.o): in function linux_udev_event_thread_main': (.text+0x2ab): undefined reference toudev_monitor_receive_device' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/libusb-1.0.a(linux_udev.o): in function linux_udev_start_event_monitor': (.text+0x370): undefined reference toudev_new' /usr/bin/ld: (.text+0x38f): undefined reference to udev_monitor_new_from_netlink' /usr/bin/ld: (.text+0x3b5): undefined reference toudev_monitor_filter_add_match_subsystem_devtype' /usr/bin/ld: (.text+0x3c9): undefined reference to udev_monitor_enable_receiving' /usr/bin/ld: (.text+0x3dd): undefined reference toudev_monitor_get_fd' /usr/bin/ld: (.text+0x500): undefined reference to udev_monitor_unref' /usr/bin/ld: (.text+0x521): undefined reference toudev_unref' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/libusb-1.0.a(linux_udev.o): in function linux_udev_stop_event_monitor': (.text+0x675): undefined reference toudev_monitor_unref' /usr/bin/ld: (.text+0x696): undefined reference to udev_unref' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/libusb-1.0.a(linux_udev.o): in functionlinux_udev_scan_devices': (.text+0x762): undefined reference to udev_enumerate_new' /usr/bin/ld: (.text+0x784): undefined reference toudev_enumerate_add_match_subsystem' /usr/bin/ld: (.text+0x79a): undefined reference to udev_enumerate_add_match_property' /usr/bin/ld: (.text+0x7a2): undefined reference toudev_enumerate_scan_devices' /usr/bin/ld: (.text+0x7aa): undefined reference to udev_enumerate_get_list_entry' /usr/bin/ld: (.text+0x7c4): undefined reference toudev_list_entry_get_name' /usr/bin/ld: (.text+0x7dd): undefined reference to udev_device_new_from_syspath' /usr/bin/ld: (.text+0x7e8): undefined reference toudev_device_get_devnode' /usr/bin/ld: (.text+0x7f8): undefined reference to udev_device_get_sysname' /usr/bin/ld: (.text+0x841): undefined reference toudev_device_unref' /usr/bin/ld: (.text+0x849): undefined reference to udev_list_entry_get_next' /usr/bin/ld: (.text+0x85f): undefined reference toudev_enumerate_unref' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/libusb-1.0.a(linux_udev.o): in function linux_udev_hotplug_poll': (.text+0x908): undefined reference toudev_monitor_receive_device' collect2: error: ld returned 1 exit status make[2]: [CMakeFiles/pok3rtool.dir/build.make:121: pok3rtool] Error 1 make[1]: [CMakeFiles/Makefile2:231: CMakeFiles/pok3rtool.dir/all] Error 2 make: *** [Makefile:136: all] Error 2 ` I just manually added -ludev and it worked.

Yes, I'd like to get mainline qmk working on my pok3r keyboards. There are some usb related changes in the tmk_core directory in this fork and I don't know if they are still needed.

hansemro commented 1 year ago

@lunohod-1 -ludev flag should be added now.

You don't need to modify tmk_core for the hardware bringup. If you have time and want to upstream the changes, I'd recommend starting over from develop qmk branch while using qmk_pok3r as a reference.

hansemro commented 1 year ago

Dropped in favor of version 2 PR: #16.