Sekigon Gonnoc Unlocks a Second USB Port on the Raspberry Pi RP2040, Using PIO State Machines

Designed for projects where a single USB port isn't enough, this PIO implementation works in Host or Device mode as-required.

Gareth Halfacree
2 years ago β€’ HW101

Embedded developer Sekigon Gonnoc has implemented USB Host and Device functionality on the programming input/output (PIO) blocks of the Raspberry Pi RP2040 β€” allowing the microcontroller to run two USB ports, in place of its usual one.

The RP2040 is an undeniably powerful yet low-cost microcontroller, with a few stand-out features including native USB support. If one USB port isn't enough, though, Gonnoc's code adds a second β€” making use of a state machine running on the RP2040's programmable input/output (PIO) blocks.

"I implemented a USB host using the PIO of RP2040 (the microcontroller of the Raspberry Pi Pico)," Gonnoc writes, in translation, of the project in a Twitter post brought to our attention by arturo182. "It can have both Host and Device functions in addition to the original USB function."

Gonnoc wrote the PIO USB implementation as part of a project to create a split keyboard, creating a second USB port for communication between the keyboard's sections β€” a total of three plus a bonus off-the-shelf wireless USB trackball, in the video demonstration β€” while still providing connectivity to the host PC on the original USB port of a Raspberry Pi Pico development board.

The USB implementation takes up three state machines across two of the Raspberry Pi RP2040's PIO blocks, one for USB transmission and two for reception. Additionally, it requires access to two general-purpose input/output (GPIO) pins for the data lines, 15kB of RAM and the same amount of program storage, a 1ms repeating timer for Host use or a PIO interrupt request (IRQ) line for Device mode.

The source code for the project is available on GitHub under the permissive MIT license, though Gonnoc warns that it's a work-in-progress and that the "API may be changed drastically in [the] future."

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