[Bug] keyboard stops responding after power cycles and found where goes wrong
#9,962 opened on Aug 7, 2020
Description
I was playing with the STM32F401CCU6, which is the blackpill development board. I found that the keyboard stops responding if I use that keyboard to wake the host computer. After adding some LEDs event for debugging, I found which code section the QMK firmware sticks and make a dump hotfix to verify the observation.
Describe the Bug
After putting the host computer into sleep, if I press any key from the keyboard to wake the host up, the keyboard can not send any key event to the host computer.
I can observe the QMK firmware is running the loop in the tmk_core/protocol/chibios/main.c to wait for the USB driver to leave the USB_SUSPENDED. However, even the host computer is up, the USB driver state is still USB_SUSPENDED, which causes the keyboard sticks in this loop forever and thus not sending any new key event. I make a dumb hotfix by stoping the USB driver, then re-start the USB driver, and the USB driver becomes USB_ACTIVE again, and the keyboard is back to work.
System Information
- Keyboard:
- Revision (if applicable): Phoenix (I will create a PR for this keyboard as it is still under development, but should be done in this week)
- Operating system: macOS 10.15
- AVR GCC version: 9.2.0
- ARM GCC version: 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599] (GNU Tools for Arm Embedded Processors 9-2019-q4-major)
- QMK Firmware version: 0.9.49
- Any keyboard related software installed?
- AutoHotKey
- Karabiner
- Other:
Additional Context
The diff of my dumb hotfix:
diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c
index 7d32c16ed..bdac09223 100644
--- a/tmk_core/protocol/chibios/main.c
+++ b/tmk_core/protocol/chibios/main.c
@@ -229,6 +229,7 @@ int main(void) {
/* Remote wakeup */
if (suspend_wakeup_condition()) {
usbWakeupHost(&USB_DRIVER);
+ restart(&USB_DRIVER);
}
}
/* Woken up */
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index 65bd291be..d27db391a 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -559,6 +559,14 @@ void init_usb_driver(USBDriver *usbp) {
chVTObjectInit(&keyboard_idle_timer);
}
+void restart(USBDriver *usbp) {
+ usbStop(usbp);
+ usbDisconnectBus(usbp);
+ wait_ms(1500);
+ usbStart(usbp, &usbcfg);
+ usbConnectBus(usbp);
+}
+
/* ---------------------------------------------------------
* Keyboard functions
* ---------------------------------------------------------
diff --git a/tmk_core/protocol/chibios/usb_main.h b/tmk_core/protocol/chibios/usb_main.h
index 94baf9b35..6083fa2bd 100644
--- a/tmk_core/protocol/chibios/usb_main.h
+++ b/tmk_core/protocol/chibios/usb_main.h
@@ -34,6 +34,7 @@
/* Initialize the USB driver and bus */
void init_usb_driver(USBDriver *usbp);
+void restart(USBDriver *usbp);
/* ---------------
* Keyboard header