-
Notifications
You must be signed in to change notification settings - Fork 105
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
usb_hid behaviour at boot.. #117
Comments
Could you describe the problem in more detail? What errors do you see? Sometimes a delay of a few seconds in your |
Tried adding a delay of 10seconds in code.py, but still same issue. SO, from power up, the boot process seems to run as per normal, just not functioning HID keyboard device. dmesg output from the boot process shows:
Unplugging the device while system operating and plugging back in, the HID keyboard generates errors in dmesg (or it works as normal:
|
Could you post your code.py, or the simplest version that reproduces the problem? Thanks. |
I'm using the code from the project |
Any thoughts on this ? |
Diagnostic testing: |
Seems to make no difference with.out the boot.py and uf2 versions either (been back as far as 6.3.3). Setup is running RetroPie 4.8.4, rpi4 (armv7l) - Raspbian GNU/Linux 10 (buster) - Linux retropie 5.10.103-v7l+ |
@dhalbert @n0rt0nthec4t Same problem here on pico with CP 8.2.3 boot.py: import usb_midi
import usb_cdc
import usb_hid
import storage
usb_cdc.disable() # Disable both serial devices.
usb_midi.disable() # Disable mini
usb_hid.enable((usb_hid.Device.KEYBOARD, )) # Enable just KEYBOARD
storage.disable_usb_drive()
So how to disable storage with usb_hid enabled? |
if you remove the I have a volume control that is built with a Trinket M0, with code similar to the above. I upgraded it to 8.2.3, and it is still working properly. It does not disable anything in HID, and it does not disable MIDI, but it does do this: storage.disable_usb_drive()
usb_cdc.enable(console=False) Host computer is a PC running Ubuntu 22.04. |
@dhalbert No change. No hid device on device manager.
Look's like Host is not a problem here. Any ideas? |
But it works on WinCE if it is connected from boot time. |
makes no difference for me |
I've set up a small test jig that can reproduce the problem. I borrowed a simple keyboard HID emulator from here https://learn.adafruit.com/circuitpython-essentials/circuitpython-hid-keyboard-and-mouse and modified it slightly to work with a Pico W. I put these lines from @dhalbert into
Plugging this into a cold RP 4 fails, but plugging it in when the RP 4 is booted works. I also tried it on a Linux box with similar but oddly intermittent results. Sometimes it worked with the cold Linux box and sometimes it didn't. I also noticed that when it failed, the onboard led blinked two shorts and a long pause repeatedly. I think this means that board has fallen into REPL on an error, I'll hook it up the through picoprobe next to see if that's the case. Something else caught my eye: The linux box fails when power is present on the USB port with the box powered down, but does not fail when it isn't. That's probably due to some janky BIOS code in the Linux box for wake from sleep, but it could be an important clue. |
This is exactly the behaviour I experienced when starting this issue. Lets see where your testing goes |
You all confirmed what we also have. |
Also used now tonny editor instead of bloated Mu-editor. Give it a try. |
Activated UART REPL by adding these lines to #define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO0)
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO1) and then connected the UART through picoprobe. Here's what I get on a cold RP 4:
And here's what I get with a warm RP 4:
|
This is an exception. REPL is usually solid white when entered.
This can be trying to send over USB before it is fully connected. |
If I plug the Pico into a simple power adapter, I get the same OSError as for a cold RP 4. That leads me to think that something in the USB stack doesn't like getting invoked by |
You can use |
During HID initialization, |
The library code like |
On the RP 4 the delay is several seconds (seems like at least 10 without measuring it), while your typical desktop PC the BIOS enumerates PDQ after power on to find HID devices. |
The original delay was done here: #15, clearly not enough now sometimes. |
I'm doing some empirical testing here to find an appropriate delay, then I'll submit a PR. |
Will this be a library PR? We can transfer this issue to the HID library. |
Yes, please transfer to the HID library and I'll pick it up from there. |
It's taking the RP 4 up to 15 seconds to enumerate after POR, so I'm going to retry every second for up to 20 seconds. Having multiple retries 1 second apart avoids the problem of having an unresponsive HID device if enumeration takes just a bit more than 1 second. Updating all HID devices similarly. |
Fix #117: Rework host USB ready timeout
CircuitPython version
Code/REPL
Behavior
...
Description
I have a project using circuitpython to provide a usb HID device (keyboard), however come up with some strange operating behaviour.
When connect a linux host (raspbian rpi4) at boot, the device is detected however doesnt function as a keyboard. Removing the usb connection and replugging back in, the device works as expected.
If I automount the CIRCUITPY disk at boot, then the device will work as expected also.
Is there a way to have this device function as expected without having to mount the usb-storage device?
dmesg output from boot
Additional information
No response
The text was updated successfully, but these errors were encountered: