Adafruit Doubles the Raspberry Pi RP2040's USB Ports — to Quickly Flash a Second RP2040
Designed to replace the hard-to-find Teensy 3.6 in flashing and testing rigs, Adafruit's new "Brains Board" uses a TinyUSB doubling tweak.
Developer Ha Thach has given Adafruit a holiday gift: the ability to use a Raspberry Pi RP2040 microcontroller to program another RP2040 microcontroller by providing a "Dual Role" simulated USB port.
"We crank out a lot of RP2040 microcontroller boards," explains Adafruit's Phillip Torrone, "and so we have to be able to program them very fast and very reliably. Historically we used a Teensy 3.6 to run our programmer+tester 'brains' — in particular we liked that it had USB Host support and a microSD Card slot so we could store the target UF2 [firmware] and then burn it over the MSD interface."
All was well, until the component shortages began to bite — and the Teensy 3.6 became harder and harder to find. "We ran out a few months ago," Torrone explains. "Yet, we cannot let that stand in the way of us making new hardware! Thanks to [Ha] Thach’s hard work, we have added USB Host bitbang support to TinyUSB so that the RP2040 can pretend to have a second USB port and it works very well!"
The modification to TinyUSB, a cross-platform embedded stack designed to provide USB Host and/or Device support, means that the RP2040 microcontroller can provide two USB ports — the physical port and a second "fake" port. This "fake" port is used to program the target device over USB Mass Storage — completing the process in just two to three seconds.
To go with the new TinyUSB capability, Adafruit has designed a "Brains Board" based around the Raspberry Pi Pico that entirely replaces the old Teensy 3.6 variant — and has confirmed that it will also be switching its hardware testing boards to use the Raspberry Pi Pico as well.
The "Dual Role" source code is now available on the Adafruit TinyUSB GitHub repository, under the permissive MIT license.