From a9710700cb5eb5749b78be90ef542818e8bb51e0 Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Tue, 6 Jun 2023 22:35:10 +0300 Subject: [PATCH 01/10] util: add sn32 dfu udev rules --- util/udev/50-qmk.rules | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/udev/50-qmk.rules b/util/udev/50-qmk.rules index 1cc19b41428c..cc7bb7544398 100644 --- a/util/udev/50-qmk.rules +++ b/util/udev/50-qmk.rules @@ -84,3 +84,8 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="28e9", ATTRS{idProduct}=="0189", TAG+="uacc # WB32 DFU SUBSYSTEMS=="usb", ATTRS{idVendor}=="342d", ATTRS{idProduct}=="dfa0", TAG+="uaccess" + +# SN32 DFU +SUBSYSTEMS=="usb", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="7010", TAG+="uaccess" +SUBSYSTEMS=="usb", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="7040", TAG+="uaccess" +SUBSYSTEMS=="usb", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="7900", TAG+="uaccess" From bd35c7db805b645f70776709dd3f1269667c3962 Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Tue, 6 Jun 2023 23:00:03 +0300 Subject: [PATCH 02/10] add sn32-dfu to flash utils --- lib/python/qmk/constants.py | 5 +++++ lib/python/qmk/flashers.py | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/python/qmk/constants.py b/lib/python/qmk/constants.py index 8a13029a8a8f..6a6e4221a333 100644 --- a/lib/python/qmk/constants.py +++ b/lib/python/qmk/constants.py @@ -109,6 +109,11 @@ 'hid-bootloader': { ("03eb", "2067"), # QMK HID ("16c0", "0478") # PJRC halfkay + }, + 'sn32-dfu': { + ("0c45", "7010"), # SN32F260 + ("0c45", "7040"), # SN32F240B + ("0c45", "7900") # SN32F240 } } diff --git a/lib/python/qmk/flashers.py b/lib/python/qmk/flashers.py index f83665d9accf..d30c4c388517 100644 --- a/lib/python/qmk/flashers.py +++ b/lib/python/qmk/flashers.py @@ -96,7 +96,7 @@ def _find_bootloader(): details = 'halfkay' else: details = 'qmk-hid' - elif bl == 'stm32-dfu' or bl == 'apm32-dfu' or bl == 'gd32v-dfu' or bl == 'kiibohd': + elif bl == 'stm32-dfu' or bl == 'apm32-dfu' or bl == 'gd32v-dfu' or bl == 'kiibohd' or bl == 'sn32-dfu': details = (vid, pid) else: details = None @@ -196,6 +196,14 @@ def _flash_uf2(file): cli.run(['util/uf2conv.py', '--deploy', file], capture_output=False) +def _flash_sonixflasher(details, file): + # SN32F260 + if details[0] == '0c45' and details[1] == '7010': + cli.run(['sonixflasher', '--vidpid', f'{details[0]}:{details[1]}', '--offset', '0x200', '--file', file], capture_output=False) + else: + cli.run(['sonixflasher', '--vidpid', f'{details[0]}:{details[1]}', '--file', file], capture_output=False) + + def flasher(mcu, file): bl, details = _find_bootloader() # Add a small sleep to avoid race conditions @@ -222,6 +230,8 @@ def flasher(mcu, file): _flash_mdloader(file) elif bl == '_uf2_compatible_': _flash_uf2(file) + elif bl == 'sn32-dfu': + _flash_sonixflasher(details, file) else: return (True, "Known bootloader found but flashing not currently supported!") From 19a070af9d420154b7bdb4c28d3692713443c529 Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Tue, 6 Jun 2023 23:15:15 +0300 Subject: [PATCH 03/10] util: add sonixflasher on qmk install --- util/install/linux_shared.sh | 12 ++++++++++++ util/qmk_install.sh | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/util/install/linux_shared.sh b/util/install/linux_shared.sh index e060f425f579..50fd3fe84cf1 100755 --- a/util/install/linux_shared.sh +++ b/util/install/linux_shared.sh @@ -11,3 +11,15 @@ _qmk_install_bootloadhid() { popd > /dev/null fi } + +# No distros package sonixflasher yet +_qmk_install_sonixflasher() { + if ! command -v sonixflasher > /dev/null; then + wget https://github.com/SonixQMK/SonixFlasherC/archive/refs/tags/1.1.0.tar.gz -O - | tar -xz -C /tmp + pushd /tmp/SonixFlasherC-1.1.0/ > /dev/null + if make; then + sudo cp sonixflasher /usr/local/bin + fi + popd > /dev/null + fi +} \ No newline at end of file diff --git a/util/qmk_install.sh b/util/qmk_install.sh index 3f49bd255a7e..510724964a95 100755 --- a/util/qmk_install.sh +++ b/util/qmk_install.sh @@ -73,3 +73,7 @@ _qmk_install if type _qmk_install_bootloadhid &>/dev/null; then _qmk_install_bootloadhid fi + +if type _qmk_install_sonixflasher &>/dev/null; then + _qmk_install_sonixflasher +fi From bb62c4ec6eca269ba279025073dbdc66acc61196 Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Wed, 7 Jun 2023 00:46:32 +0300 Subject: [PATCH 04/10] qmk doctor: arm-none-eabi-gcc version check --- lib/python/qmk/cli/doctor/check.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/python/qmk/cli/doctor/check.py b/lib/python/qmk/cli/doctor/check.py index cd69cdd11c8d..fe67a67387a5 100644 --- a/lib/python/qmk/cli/doctor/check.py +++ b/lib/python/qmk/cli/doctor/check.py @@ -44,7 +44,13 @@ def _check_arm_gcc_version(): version_number = ESSENTIAL_BINARIES['arm-none-eabi-gcc']['output'].strip() cli.log.info('Found arm-none-eabi-gcc version %s', version_number) - return CheckStatus.OK # Right now all known arm versions are ok + parsed_version = _parse_gcc_version(version_number) + if parsed_version['minor'] < 3: + if parsed_version['major'] <= 10: + cli.log.warning('{fg_yellow}We do not recommend arm-none-eabi-gcc older than 10.3.x. Upgrading to 10.3.x or higher is recommended.') + return CheckStatus.WARNING + + return CheckStatus.OK # arm versions less than 10.3.x cause issues on sn32 def _check_avr_gcc_version(): From be00e0ecc523573a8fb33106cc7447ce752e01fd Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Tue, 13 Jun 2023 12:14:43 +0300 Subject: [PATCH 05/10] sn32: add to flashing docs --- docs/flashing.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/docs/flashing.md b/docs/flashing.md index 443fa3123e1b..05ffae1517fe 100644 --- a/docs/flashing.md +++ b/docs/flashing.md @@ -442,3 +442,44 @@ CLI Flashing sequence: 4. Wait for the keyboard to become available 1: This works only if QMK was compiled with `RP2040_BOOTLOADER_DOUBLE_TAP_RESET` defined. + +## SN32 DFU + +All SN32 MCUs, except for 2601 come preloaded with a factory bootloader that cannot be modified nor deleted. + +To ensure compatibility with the SN32-DFU bootloader, make sure this block is present in your `rules.mk` : + +```make +# Bootloader selection +BOOTLOADER = sn32-dfu +``` + +Compatible flashers: + +* [SonixFlasher](https://github.com/SonixQMK/sonix-flasher/releases) (recommended GUI) +* [SonixFlasherC](https://github.com/SonixQMK/SonixFlasherC/releases) (recommended command line) + ``` + sonixflasher --vidpid 0c45:7040 -f + ``` +1: 260 series of chips have part of the SN32-DFU bootloader in userspace and therefore must be guarded to avoid bricking. Install the [sonix-bootloader](https://github.com/SonixQMK/sonix-keyboard-bootloader) before flashing the firmware +``` +sonixflasher --vidpid 0c45:7010 -f + +``` +as a one-shot operation, then flash the firmware with an offset `0x200` +``` +sonixflasher --vidpid 0c45:7010 -o 0x200 -f + +``` + +If using `$ qmk flash` to flash a firmware, the offset is automatically applied if needed. + +Flashing sequence: + +1. Enter the bootloader using any of the following methods: + * Tap the `QK_BOOT` keycode + * If a reset circuit is present, tap the `RESET` button on the PCB; some boards may also have a toggle switch that must be flipped + * Otherwise, you need to bridge `BOOT` to GND (via `BOOT` button or jumper), short `RESET` to GND (via `RESET` button, jumper or by unplugging and replugging USB), and then let go of the `BOOT` bridge +2. Wait for the OS to detect the device +3. Flash a .bin file +4. Reset the device into application mode (may be done automatically) From 99c254438d70e9553cd1c5203ca9c7055297eb3f Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Thu, 15 Jun 2023 11:16:57 +0300 Subject: [PATCH 06/10] add sn32 to driver installation docs --- docs/driver_installation_zadig.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/driver_installation_zadig.md b/docs/driver_installation_zadig.md index 3b2c0b74dc41..4ad71ea2d0d9 100644 --- a/docs/driver_installation_zadig.md +++ b/docs/driver_installation_zadig.md @@ -2,7 +2,7 @@ QMK presents itself to the host as a regular HID keyboard device, and as such requires no special drivers. However, in order to flash your keyboard on Windows, the bootloader device that appears when you reset the board often *does*. -There are two notable exceptions: the Caterina bootloader, usually seen on Pro Micros, and the HalfKay bootloader shipped with PJRC Teensys, appear as a serial port and a generic HID device respectively, and so do not require a driver. +There are three notable exceptions: the Caterina bootloader, usually seen on Pro Micros, the HalfKay bootloader shipped with PJRC Teensys, and the SN32 DFU bootloader shipped with Sonix SN32F2xx, appear as a serial port and a generic HID device respectively, and so do not require a driver. We recommend the use of the [Zadig](https://zadig.akeo.ie/) utility. If you have set up the development environment with MSYS2, the `qmk_install.sh` script will have already installed the drivers for you. @@ -96,4 +96,7 @@ The device name here is the name that appears in Zadig, and may not be what the |`gd32v-dfu` |GD32V BOOTLOADER |`28E9:0189` |WinUSB | |`kiibohd` |Kiibohd DFU Bootloader |`1C11:B007` |WinUSB | |`stm32duino` |Maple 003 |`1EAF:0003` |WinUSB | +|`sn32-dfu` |*none* |`0c45:7010` |HidUsb | +|`sn32-dfu` |*none* |`0c45:7040` |HidUsb | +|`sn32-dfu` |*none* |`0c45:7900` |HidUsb | |`qmk-hid` |(keyboard name) Bootloader |`03EB:2067` |HidUsb | From 18d4c1fa57c9531d7ec3d0a3674d9f6f7bc7f37d Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Thu, 15 Jun 2023 11:21:00 +0300 Subject: [PATCH 07/10] sn32: flashing: document qmk toolbox support --- docs/flashing.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/flashing.md b/docs/flashing.md index 05ffae1517fe..f0714da3fcba 100644 --- a/docs/flashing.md +++ b/docs/flashing.md @@ -456,7 +456,8 @@ BOOTLOADER = sn32-dfu Compatible flashers: -* [SonixFlasher](https://github.com/SonixQMK/sonix-flasher/releases) (recommended GUI) +* [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI) +* [Sonix-Flasher](https://github.com/SonixQMK/sonix-flasher/releases) (advanced GUI with MCU specific functionalities) * [SonixFlasherC](https://github.com/SonixQMK/SonixFlasherC/releases) (recommended command line) ``` sonixflasher --vidpid 0c45:7040 -f From bfc5bd1e643a5b8c53b16383ef7cf9c8d34a88f4 Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Mon, 19 Jun 2023 12:48:22 +0300 Subject: [PATCH 08/10] docs: sn32: add jumploader flag when flashing bootloader --- docs/flashing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/flashing.md b/docs/flashing.md index f0714da3fcba..4fc88d31137c 100644 --- a/docs/flashing.md +++ b/docs/flashing.md @@ -464,7 +464,7 @@ Compatible flashers: ``` 1: 260 series of chips have part of the SN32-DFU bootloader in userspace and therefore must be guarded to avoid bricking. Install the [sonix-bootloader](https://github.com/SonixQMK/sonix-keyboard-bootloader) before flashing the firmware ``` -sonixflasher --vidpid 0c45:7010 -f +sonixflasher --vidpid 0c45:7010 --jumploader -f ``` as a one-shot operation, then flash the firmware with an offset `0x200` From 84391666f6ecffec9d565f407a7272918fa92ada Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Mon, 19 Jun 2023 23:39:54 +0300 Subject: [PATCH 09/10] MSYS2 install: add sonixflasher for sn32 targets --- util/install/msys2.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/install/msys2.sh b/util/install/msys2.sh index fa422023ab60..d5aa2559474a 100755 --- a/util/install/msys2.sh +++ b/util/install/msys2.sh @@ -12,7 +12,8 @@ _qmk_install() { base-devel: toolchain:x clang:x python-qmk:x hidapi:x \ avr-binutils:x avr-gcc:x avr-libc:x \ arm-none-eabi-binutils:x arm-none-eabi-gcc:x arm-none-eabi-newlib:x \ - avrdude:x bootloadhid:x dfu-programmer:x dfu-util:x hid-bootloader-cli:x mdloader:x teensy-loader-cli:x wb32-dfu-updater:x + avrdude:x bootloadhid:x dfu-programmer:x dfu-util:x hid-bootloader-cli:x mdloader:x \ + teensy-loader-cli:x wb32-dfu-updater:x sonixflasher:x _qmk_install_drivers } From d36f1aa4d50cd6ae5342a16d727420c91fd4476b Mon Sep 17 00:00:00 2001 From: dexter93 Date: Tue, 20 Jun 2023 00:18:55 +0300 Subject: [PATCH 10/10] qmk doctor: fix the arm-none-eabi-gcc version check Co-authored-by: Sergey Vlasov --- lib/python/qmk/cli/doctor/check.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/python/qmk/cli/doctor/check.py b/lib/python/qmk/cli/doctor/check.py index fe67a67387a5..4bd590b99e75 100644 --- a/lib/python/qmk/cli/doctor/check.py +++ b/lib/python/qmk/cli/doctor/check.py @@ -45,10 +45,9 @@ def _check_arm_gcc_version(): cli.log.info('Found arm-none-eabi-gcc version %s', version_number) parsed_version = _parse_gcc_version(version_number) - if parsed_version['minor'] < 3: - if parsed_version['major'] <= 10: - cli.log.warning('{fg_yellow}We do not recommend arm-none-eabi-gcc older than 10.3.x. Upgrading to 10.3.x or higher is recommended.') - return CheckStatus.WARNING + if (parsed_version['major'], parsed_version['minor']) < (10, 3): + cli.log.warning('{fg_yellow}We do not recommend arm-none-eabi-gcc older than 10.3.x. Upgrading to 10.3.x or higher is recommended.') + return CheckStatus.WARNING return CheckStatus.OK # arm versions less than 10.3.x cause issues on sn32