-
-
Notifications
You must be signed in to change notification settings - Fork 39.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Address wake from sleep instability #11450
Conversation
This should also target the chibiOS suspend, too |
I just added some speculative code for chibiOS, but I don't have an ARM-based board on which to test it (yet - bluepill on the way). Help with testing would be appreciated! |
Unfortunately, testing this, this breaks sleep for me, outright. Computer IMMEDIATELY wakes up after trying to put it to sleep. And this is on macOS Catalina. Windows PC works fine. |
Is that on AVR or on ARM? |
AVR. |
Hmm... I am trying to imagine how this code could cause that, since it doesn't send anything to the host that would wake it up unless |
One more question: How soon is "IMMEDIATELY"? Less that a second? Less than 10 seconds? I just did a quick test on the Mac, and didn't see it wake up right away. Also, what method did you use to put the Mac to sleep? |
Oh, boy, this is fun. And I use the sleep option in the apple menu. |
Yeah!
Sigh. Time to buy yet another flavor of MCU so that I can test stuff... :)
That's what I was doing as well. |
Yup, sleeps and wakes just fine without. |
I did some quick testing of this on a split stm32f401, computer suspends and wakes correctly (Windows 10). RGB behavior is a little odd with RGBLIGHT_SLEEP defined but that also seems to true with master branch, I'll do some more testing when I get a chance. |
Can you be specific about exactly what you mean by "a little odd"? I've also seen some oddities, but most are explained by:
|
I'm using the following hardware 2x STM32F401 using split common with no eeprom. The rgblight is enabled using the code below and I do not use any rgblight layers.
Master, PR#11450 and PR#11442 all show the same behaviour with rgblight enabled and rgblight_sleep defined. I thought I noticed different behaviour but it seems I was mistaken. The computer sleeps without issue and wakes via key press fine, also I've had no incidents of self waking. This is what's happening with the rgb lighting but I guess it might be more relevant to the other pull request, I've bracketed anything I did manually.
|
I think it is relevant to this PR - would like to understand it. Seems like rgblight is not being re-enabled on wakeup, which would imply that one of the following two cases is occurring:
Do you have anything in |
I did a little more playing, it doesn't seem like USB_EVENT_WAKEUP ever happens on my stm32 keyboard. I've got a bodge working but it's probably not a real fix. Just to be clear without my bodge suspend is never called on master either. I've logged the behaviour for 2 different split keyboards, one avr (atmega32u4) and the other arm (stm32f401). Below is this PR and my bodge for arm.
Below is master and my bodge for arm.
Repeated calls to suspend are ignored, my crude buffer for logging wasn't big enough on avr so I disabled on both but there's definitely an improvement. |
I just had a look at the bodge, and the funny thing is that it's almost identical to a change that I am planning to add to this PR. I need to do a bit more testing on the bluepill onekey that I just built yesterday, though, to verify that it works consistently. That being said, like you, I cannot believe that |
I think you're getting close to the truth.
void suspend_power_down_kb(void) { void suspend_wakeup_init_kb(void) { |
@XBowsTech which keyboard and mcu is this? Also, do you have |
xbows/nature |
@XBowsTech did either of those help? I'm running with SLEEP_LED_ENABLE = no. |
I've tested it myself. It works. Are you using IS31FL3731? |
Glad to hear that - but I need to get this working without SLEEP_LED_ENABLE; need to get the kb into lowest power state, and can't do that with the breathing on.
No; my boards all use WS2812. But I don't think that's really the issue. This is all about suspend states and host interaction. I think the LEDs are just a symptom... |
I am testing on kbd75 (AVR, atmega32u4), and on a bluepill (STM32F103). at90usb1286 is on it's way here so I can test that. RGB_DISABLE_WHEN_USB_SUSPENDED is not relevant; it only applies to RGB Matrix, and I don't have that installed or enabled on any of these devices. |
You can try it. In fact, LEDs don't light up when the computer is asleep. I'm not sure if this approach will work for WS2812. |
Like I said - that works for RGB Matrix, but NOT for RGB Lighting (underglow). The RGB_DISABLE_WHEN_USB_SUSPENDED macro is defined and used only in the context of quantum/rgb_matrix.c.
Again, we need to come up with a solution that does not require non-hardware hacking folks to physically modify their keyboards. And as I said, all of this mess with the LEDs is just a symptom. The real problem is that the methods that enable and disable them are not being called at the right times, and that's all because the suspend / wake state of the keyboard is incorrect. |
@drashna — I just tried with an at90usb1286 (Teensy++ 2.0) on a Mac with Catalina and I am not seeing the problem that you mention. When I click on Sleep the screen goes dark, and then within 30 to 60 seconds the keyboard is suspended and the LEDs are shut off. I am running with That being said, it is surprising that you are seeing that odd behavior on two different Teensy boards and also on your Planck. I wonder — do you have anything unusual in |
Per this discord discussion the problem that @drashna saw is no longer reproducible, so I am taking this PR out of draft and submitting it for review. Note: Notes that are playing are not stopped on suspend, but that is a known issue, not related to the topic being addressed in this PR. |
88d6f54
to
cf51106
Compare
Thanks! |
You're welcome! |
* resolve race condition between suspend and wake in LUFA * avoid multiple calls to suspend_power_down() / suspend_wakeup_init() * Remove duplicate suspend_power_down_kb() call * pause on wakeup to wait for USB state to settle * need the repeated suspend_power_down() (that's where the sleep is) * more efficient implementation * fine tune the pause after sending wakeup * speculative chibios version of pause-after-wake * make wakeup delay configurable, and adjust value * better location for wakeup delay
* resolve race condition between suspend and wake in LUFA * avoid multiple calls to suspend_power_down() / suspend_wakeup_init() * Remove duplicate suspend_power_down_kb() call * pause on wakeup to wait for USB state to settle * need the repeated suspend_power_down() (that's where the sleep is) * more efficient implementation * fine tune the pause after sending wakeup * speculative chibios version of pause-after-wake * make wakeup delay configurable, and adjust value * better location for wakeup delay
Description
My work-from-home setup is a complicated mess of KVM switches, USB hubs, etc. Sleep / wake works fine when the keyboard is plugged directly into the computer, but through the switches / hubs it becomes unreliable, with the keyboard hanging sometimes on wake, or lighting being wrong after wakeup. Other people have reported similar experiences, especially when using KVM switches or when using pass-through USB on a USB-C or HDMI connected monitor.
Debugging showed that when a key is tapped to wake the board / host, if it goes through the switch, instead of USB device state going smoothly from Suspended to Configured, it goes back and forth a few times before settling on Configured. When that happens, sometimes, the keyboard hangs. Other times the host just doesn't stay awake.
After spending some time looking into this, I've applied a few targeted changes:
suspend_power_down_kb()
(it was called twice for each suspend cycle).At present, the suspend code is called repeatedly in a tight loop during suspend. I've made a change so that it is only called once on the transition to Suspended state.[It turns out that the repeated calls are required, as that is where the low-power sleep cycle is implemented, so this has been restored.]At the moment this is a draft, as I've only been able to test it on a few boards, and only for a few days. Help testing this would be greatly appreciated.
Code has been written for ARM / chibiOS, but is has not been tested at all yet.Note that I am targeting the develop branch, as this seems a bit too deep and critical to go directly to master...
Types of Changes
Checklist