mattdibi / redox-keyboard

Ergonomic split mechanical keyboard
MIT License
1.79k stars 167 forks source link

Bootloader/reset mode not accessible anymore #115

Closed bilange closed 3 years ago

bilange commented 3 years ago

I am now apparently unable to boot into bootloader/reset mode. After an unsuccessful flash (more on this later), pressing the reset button on the PCB will make Windows say it's an unrecognized device. The keyboard will switch immediatly (without waiting ~10s in bootloader mode) into normal mode.

However on Linux (Fedora) I noticed that the device will outright disappear from the lsusb device listing, and stay absent, once I press reset. A power cycle is needed to return to normal mode.

Normal mode:

❯ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 04ca:2006 Lite-On Technology Corp. Broadcom BCM43142A0 Bluetooth Device
Bus 001 Device 002: ID 04f2:b483 Chicony Electronics Co., Ltd USB2.0 VGA UVC WebCam
Bus 001 Device 009: ID feed:0000 Falbatech The Redox Keyboard
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Once I pressed reset (either physically or via QMK RESET):

❯ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 04ca:2006 Lite-On Technology Corp. Broadcom BCM43142A0 Bluetooth Device
Bus 001 Device 002: ID 04f2:b483 Chicony Electronics Co., Ltd USB2.0 VGA UVC WebCam
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Unsuccessful flash (root cause)

The situation avove may be my own fault, as this happened right after a flash that apparently stopped mid flashing, and for both sides individually, at 88% for many minutes. Ctrl-C didnt abort, I had to physically unplug the keyboard to halt the procedure (I DO know about not doing it in normal circumstances, but as it appeared obvious flashing was somehow halted mid procedure, what else could I do?).

Console output (from Windows QMK MSYS):

[bilange@warbird qmk_firmware]$ avrdude -p atmega32u4 -P COM3 -c avr109 -U flash:w:stable\ -\ backup_flash.hex

Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
    Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
    Device code: 0x44

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude.exe: Device signature = 0x1e9587 (probably m32u4)
avrdude.exe: NOTE: "flash" memory has been specified, an erase cycle will be performed
             To disable this feature, specify the -D option.
avrdude.exe: erasing chip
avrdude.exe: reading input file "stable - backup_flash.hex"
avrdude.exe: input file stable - backup_flash.hex auto detected as Intel Hex
avrdude.exe: writing flash (32730 bytes):

Writing | #####                                              | 10% 0.28s
(...)
(skipping many lines)
(...)
Writing | ############################################       | 88% 2.45s
(stuck indefinitely there)

While flashing seems to work at first sight (the "stable - backup_flash.hex" file was succesfully applied as my keyboard seems to act as per this file*), it has the side effect of having somehow wiped (partially??) bootloader.

So, is there a way to get out of this situation? Mind you, I CAN use the keyboard, only NOT flash it anymore- so i'm basically stuck with whatever is on my keyboards memory right now.

Thanks!

mattdibi commented 3 years ago

Hi,

I'm sorry but I can't help you here. I would redirect you over the QMK github repo for this kind of issues.

Cheers, Matt

bilange commented 3 years ago

Hi Matt,

It definitely looks like I need to reflash my bootloader according to other people having the same issue with other keyboards. I'm in the process of acquiring the proper wiring tools and an additional Pro Micro and will definitely try to flash it back.

I understand this is somewhat unrelated for your Github project, but for the sake of your issues section completeness (for future redox readers that could stumble on the same issue), I will report back when my wiring+Pro Micro order is shipped, if you don't mind.

Sources (partial):

Thanks!

(Sidenote: I hope submitting my comment won't reopen automatically this issue.)

bilange commented 2 years ago

Guide - for the non-hardware inclined

I have been able to get myself out of this issue by the following method. Warning: long text!

As I said above, it really looks like I messed up by writing a .hex file that I got FROM the keyboard by reading it. I was under the impression that avrdude was behaving similarly to using Acronis TrueImage/Clonezilla or NANDroid backups where a whole partition image can be backupped on file and then restored. But TLDR: don't read FROM a Pro Micro and use that file to write back onto the device! This breaks things (that I don't know about)!

To get yourself out of this issue, you need to flash the bootloader, which apparently got wiped and/or corrupted. However this requires the bootloader present to flash things on your Pro Micros on the Redoxes. This chicken-and-egg situation requires you to have a third Pro Micro (by third, I am also counting those inside the Redox in both sides) to use as a programmer (a device responsible of reprogramming another device). This procedure is heavily based on https://beta.docs.qmk.fm/using-qmk/guides/keyboard-building/isp_flashing_guide, with comments specific to the Redox keyboard and with additional missing tidbits, aimed for hardware newbies like me.

Warnings:

Requirements

Hardware

I am Canadian, so Amazon links will be from Amazon Canada (sorry!)

Software

Procedure

Preparing the ISP Programmer

To be extra clear, here we're preparing another Pro Micro to serve as a programmer to fix our corrupted Pro Micros "on board" inside the Redox keyboard.

While it looks like the QMK documentation says to use this image for a Pro Micro based programmer, it doesn't say how to flash the image and skips to wiring.

To flash the ISP image on your spare Pro Micro, you need to press Reset on the Pro Micro (see below), then immediately flash the Pro Micro using one of these methods below. You have ~8 seconds to initiate the flashing procedure, just like when you press Reset (either by the switch on the back or by QMK's RESET command) on the Redox keyboard to flash a new keyboard firmware.

On the command line

Launch this command immediately after pressing reset on the Pro Micro:

avrdude.exe -p atmega32u4 -c avr109 -U flash:w:"path\to\pro_micro_ISP_B6_10.hex":i -P COM6

The parameter -P COM6 varies - it's a value you need to figure out by yourself as the COM number varies every time the device is plugged in. This is part of the reason why it is recommended to use QMK Toolbox, because once Windows detects the device, Toolbox displays the COM port in its console (and you don't need to deal with this value if flashing with the Toolbox GUI)

In QMK Toolbox (prefered)

Just open the hex file in Toolbox, select the right chipset (atmega32u4 for Pro Micros), press reset on the board and hit the Flash button. (OR, you could check Auto-Flash and it will auto-apply once the Pro Micro is seen by your PC as being booted from the bootloader.

Pressing reset

"Pressing Reset" here means shorting the GND pin (any GND will do) and RST pin together. This is easier said than done when the Pro Micro is not soldered or connected, and that's why I soldered the ISP board first onto the breadboard pins that came with it. Then you only need to use a male to male Dupont cable to short GND, which you soldered, to the RST pin directly on the Pro Micro board.

Soldering the ISP Programmer

As far as I know, only those pins are absolutely nessessary to solder to use the 3rd Pro Micro as the ISP programmer: 10, 14, 15, 16, GND, VCC. This means you dont need to solder the rest of the pins if you only ever want to use the third Pro Micro as an ISP Programmer (phew!). Soldering all pins may come useful later if you want to reuse this device in the future, and will make the connection to the breadbord pins more solid anyway.

By using a breadboard to sit your programmer in, you can use Dupont wires to send the signal onto the Redox's Pro Micros. You will probably need Dupont male to female wires, if you're using the clamps I linked above.

wiring

Connecting the programmer onto Redox Pro Micros

This is by far the trickiest part to do if you want to keep the Pro Micros inside the keyboard in place and soldered. Those IC Clamps previously mentioned has alot of torque when gripping to a soldered pin, and will most probably just pop up because of the shape of the solder on the pin, which is basically a rounded or triangle shape pointing upwards. I assume clamps will only work in these circumstances:

solder closeup (this is ugly, but this will do. be careful NOT to add too many, so the back cover can still close the keyboard)

hook (The hook will retract as it is probably spring-loaded or something. You need to push the rod up so the hook opens up.)

According to the guide on QMK, we're wiring almost identically both sides:

ISP Pro Micro Pin Redox Pro Micro Pin
GND GND
10 RST
VCC VCC
15 15
14 14
16 16

Note: Be careful, the Pro Micros changes orientation between both sides! (see images from this GH repository)

My MacGyver solution was two fold: add a drop of solder over the pin to make an odd shape more prone to hold the clamp in place (as mentioned above), and tape the clamp wire in place afterwards, so the clamp has less incentive to move at all. You're basically walking on eggs there: be extra careful not to touch the wire once a clamp is in place (seriously, Good Luck!!) but the whole circuit temporarily holds to make the flash.

macgyver (I adhere by the saying "If this is stupid but it works..." )

In my case, I needed an extra pair of hands: one to make the initial connection with the clamps (on my clamps, you needed to push into the rod to make the actual clamp pop out, requiring both hands), then somebody else to place the tape to secure the clamp rod while connected to the pin.

Once all 6 connections has been made, I suggest you pull out the multimeter / continuity tester to see if all 6 connections, from both ends (from the ISP Pro Micro to the Redox Pro Micro), is working.

Just to be clear, you need to plug your USB cable from the PC onto the ISP Pro Micro (not on the Redox). Power will be provided on the Redox Pro Micros via the VCC pin you wired.

Flashing the actual keyboards

According to the guide, the Caterina / Pro Micro Bootloader 5v is the one I used for the Redox. This is actually verifiable as the rules.mk file shows that as well (BOOTLOADER = caterina). However Flashing by using the :production target doesn't seem to work on Caterina. Manually combining the bootloader and a regular keyboard firmware works as indicated in Production Techniques.

Once you have either your combined (bootloader+firmware) or bootloader only file, you can flash the redox Pro Micros it via this command*:

avrdude -c avrisp -P COM7 -p atmega32u4 -U flash:w:combined.hex:i

Where:

*: I havent tried to flash via QMK Toolbox, flashing via an ISP requires to change the programmer used, and havent seen the option visible in the GUI. I'm sure avrdudess has something for that, but I haven't tried.

Important: When you'll back with a working bootloader, do **NOT** try use this combined image (bootloader + firmware) when trying to flash your Redox regularly. If you flash this file directly onto the Redox Pro Micros, avrdude will fail while flashing, and corrupt your bootloader (again! :( ).

Flashing should take roughly the same time as a regular firmware flash (~10 seconds??), with the same kind of progress bar you were used to when flashing regularly from avrdude.

While everything is still rigged up for flashing though the ISP, test your setup by doing these steps:

You can now repeat the procedure on the second half of the keyboard:

I hope this guide will help somebody in the future. If it actually did, let me know by reacting to this message. Sorry about the lentgh of this reply.

mattdibi commented 2 years ago

Thank you for the detailed post!