Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!

MicroPython Plans a New Feature for the Raspberry Pi RP2040: Runtime-Defined USB Device Support

Breaking change, likely landing in v1.23, will mean existing USB Device projects may need to be reworked.

Gareth Halfacree
9 months agoHW101 / Python on Hardware

MicroPython is set to get official support for turning a Raspberry Pi Pico or other RP2040-based gadget into a USB Device — thanks to a new feature expected to land in the v1.23 release, in a breaking change that will likely require existing USB projects to be reworked.

"USBDevice provides a low-level Python API [Application Programming Interface] for implementing USB device functions using Python code," the MicroPython documentation explains of the upcoming support. "This low-level API assumes familiarity with the USB standard. It’s not recommended to use this API directly, instead install the high-level usbd module from micropython-lib. This functionality is very new and the high-level usbd module is not yet merged into micropython-lib."

The Raspberry Pi RP2040 microcontroller, as found at the heart of the Raspberry Pi Pico development board and its radio-equipped Pico W sibling, has long supported acting as a USB Device — but that functionality has never been readily accessible to MicroPython users. The new USB driver functionality changes that, making it possible to turn the Raspberry Pi Pico or any other RP2040 board into a custom USB device defined at runtime.

The new feature does, however, mean a change in compatibility: a comment on the Raspberry Pi forum highlighting the new feature warns that "it unsurprisingly broke my customized build and was more faff than I expected to get that working again. I am not convinced they have implemented dynamic USB in the most appropriate way," forum user "hippy" adds. "It seems to require tearing down descriptors and re-enumeration and I suspect that will play havoc with Windows."

Developer Stewart Russell, meanwhile, has posted instructions on experimenting with the new feature ahead of its official release to Mastodon — though suggests its official release could be as little as one week away, in the MicroPython v1.23 release.

Documentation is available on the MicroPython site now; the MicroPython team has confirmed that the API will be identical between the RP2040 and Microchip SAMD ports of MicroPython, but will not support any other ports at launch.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles