adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.11k stars 1.22k forks source link

adafruit_hid.keyboard doesn't work when using storage.disable_usb_drive() [Windows 7/8.1 problem] #5382

Closed st42 closed 1 year ago

st42 commented 3 years ago

CircuitPython version

Adafruit CircuitPython 7.0.0 on 2021-09-20; Raspberry Pi Pico with rp2040

Code/REPL

#code.py
import usb_hid
from adafruit_hid.keyboard import Keyboard

kbd = Keyboard(usb_hid.devices)

#boot.py
import storage

storage.disable_usb_drive()

Behavior

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "adafruit_hid/keyboard.py", line 65, in __init__
  File "adafruit_hid/keyboard.py", line 113, in release_all
OSError: USB busy

Description

I was trying to get the Pico to only be recognized as a usb keyboard and discovered that adafruit_hid.keyboard doesn't work with storage.disable_usb_drive(). I stripped away all of the unnecessary code in code.py and boot.py to show the error. I was using the Thonny IDE to view the output.

This error only occurs in Windows. It doesn't happen in Raspberry Pi OS.

I was using adafruit_hid.keyboard from adafruit-circuitpython-bundle-7.x-mpy-20210922.zip

Additional information

No response

dhalbert commented 3 years ago

I tried this on a Dell Optiplex 3020 running Windows 10 and could not reproduce the problem. It may be a slow USB startup. What is your host computer and what version of Windows is it running?

Try inserting a time.sleep() of a few seconds at the beginning of code.py, before the Keyboard() instantiation, and see if that makes a difference for you.

st42 commented 3 years ago

My computer is a HP Pavilion p6320y running Windows 7 Home Premium. I tried a 10 second sleep just for good measure but the error still occurs.

dhalbert commented 3 years ago

Do you have a Windows 10 computer to try?

st42 commented 3 years ago

I don't have a Win 10 computer unfortunately

dhalbert commented 3 years ago

Try disabling serial as well. Add these lines to your boot.py:

import usb_cdc

usb_cdc.disable()

Our Windows Drivers installer does not yet support the Pi Pico, and that may have something to do with this.

Also try Uwe Seiber's USB Device Cleanup tool, which may remove some bad state: https://learn.adafruit.com/welcome-to-circuitpython/troubleshooting#device-errors-or-problems-on-windows-3094694-15

dhalbert commented 3 years ago

Did you have any success?

dhalbert commented 3 years ago

I am changing this to Long Term because the problem is Windows 7/8.1 specific. There are restrictions caused by the Windows 7/8.1 drivers about the Interface numbers of the drivers. We also need to update the drivers package to include the Pi Pico. But this is not a problem we can fix in CircuitPython.

When I update the drivers we can try this again.

dhalbert commented 1 year ago

Closing because we have no plans to update the Windows 7/8.1 drivers.