Skip to content
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

Teensy 4.1: implement USB remote wakeup #345

Draft
wants to merge 1 commit into
base: chibios-21.11.x
Choose a base branch
from

Conversation

stapelberg
Copy link
Contributor

This allows waking up a computer from Suspend-to-RAM by pressing a key on the keyboard (with the QMK keyboard firmware, which uses ChibiOS for the Teensy).

related to kinx-project/kint#59

related to qmk/qmk_firmware#16934

stapelberg added a commit to stapelberg/ChibiOS-Contrib that referenced this pull request Oct 29, 2022
Without this change, the Teensy 3.6 (with QMK firmware) can wake a computer from
Suspend-to-RAM, but the keyboard does not actually produce any keypresses until
you un-plug and re-plug it.

A similar change was needed for the Teensy 4.x as well:
ChibiOS#345

related to qmk/qmk_firmware#16934
stapelberg added a commit to stapelberg/ChibiOS-Contrib that referenced this pull request Oct 29, 2022
Without this change, the Teensy 3.6 (with QMK firmware) can wake a computer from
Suspend-to-RAM, but the keyboard does not actually produce any keypresses until
you un-plug and re-plug it.

A similar change was needed for the Teensy 4.x as well:
ChibiOS#345

related to kinx-project/kint#59

related to qmk/qmk_firmware#16934
@stapelberg stapelberg marked this pull request as draft October 30, 2022 08:04
@stapelberg
Copy link
Contributor Author

I converted this PR to a draft for now, because I noticed that on a different PC, with this change, the keyboard seems to not work after suspend/resume (when the resume is not triggered by the keyboard). Will need to investigate.

@stapelberg
Copy link
Contributor Author

I converted this PR to a draft for now, because I noticed that on a different PC, with this change, the keyboard seems to not work after suspend/resume (when the resume is not triggered by the keyboard). Will need to investigate.

Did some initial investigation: the symptom is that when the PC resumes from suspend-to-RAM, it resets all devices connected to my USB hub, and the keyboard does not enumerate any longer.

Unfortunately, as soon as I compile in printf_debug in lib/chibios-contrib/os/hal/ports/MIMXRT1062/MIMXRT1062/printf_debug.[ch], the problem no longer reproduces. I can replace the printf_debug() implementation with a 1ms sleep and the problem still doesn’t show up.

This indicates it’s either a missing delay somewhere, a race condition/timing issue, or adding extra sleeps papers over the issue. In any case — very annoying to figure out :(

I’ll see if I can find some time to set up my NXP devkit to see if anything obvious shows up in a debugger.

@stapelberg
Copy link
Contributor Author

I’ll see if I can find some time to set up my NXP devkit to see if anything obvious shows up in a debugger.

When running it on the NXP devkit, the issue doesn’t reproduce :(

Worse, in my current testing, waking the PC up via USB didn’t work anymore!

I have a https://www.crowdsupply.com/great-scott-gadgets/luna ordered, so when/if it ships I might give this another look, but for now I’ll give up on this. I don’t have the right tools to effectively debug this.

@stapelberg
Copy link
Contributor Author

Actually, one thing came to mind: I think my hack to use DWT->CYCCNT directly instead of hwTick is not quite correct: hwTick is measured in ms, not in cycles. So, probably the USB stack delays are too short, which might explain why the extra delays paper over the issue.

I’ll try to give this a shot over the weekend

This allows waking up a computer from Suspend-to-RAM by pressing a key on the
keyboard (with the QMK keyboard firmware, which uses ChibiOS for the Teensy).
@stapelberg
Copy link
Contributor Author

So, probably the USB stack delays are too short, which might explain why the extra delays paper over the issue.

I have updated the code to convert milliseconds to cycles to fix the delay timing, but unfortunately the “hanging USB enumeration” symptom still happens :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant