amazing project: USB FS host/device using RP2040  PIO - Page 1
Forum section: electronics / general

author: spostma
author_rank: Regular Contributor
timestamp: May 17, 2022, 07:23:59 pm
content: via the Ultibo forum (which is a great bare metal rPi platform), I stumbled over this link about an amazing projectto implement a full speed USB host and device (simultaneously if you want) on a RP2040 processor:https://ultibo.org/forum/viewtopic.php?p=12872#p12872It links tohttps://github.com/sekigon-gonnoc/Pico-PIO-USBThis project is being merged with the tiny usb project:https://github.com/sekigon-gonnoc/Pico-PIO-USB/pull/22https://github.com/adafruit/Adafruit_TinyUSB_Arduino/issues/169enjoy and spread the word about this top-class hacking project by sekigon-gonnoc, hathach and FahimFBA!It is not fiished, but progresses very quickly...

author: Simon
author_rank: Unknown
timestamp: May 28, 2022, 10:41:53 am
content: why is it haking? it's called programming and bit banging

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 28, 2022, 01:28:01 pm
content: It's impressive, running the USB I/F in software is not easy, you gotta know every detail about USB spec.But yeah nowadays everything is "hacking"

author: Simon
author_rank: Unknown
timestamp: May 28, 2022, 03:24:36 pm
content: well yes, when you choose to bit bang you are taking GPIO pins and controlling them with software that perfectly mimics what a piece of hardware would do. This is why a micro has "peripherals". In computer land it is called "hardware acceleration" in microcontrollers they are simply peripherals. I could bit bang a PWM but yea, it's a pain in the ass so it's nice to have even the simplest of hardware features and saves a lot of software writing and means that your CPU can do other stuff.The cores run at 133 MHz, I guess having 2 you can use one just for USB "emulation".How do you even write code for multiple core microcontrollers?

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 28, 2022, 05:05:25 pm
content: The RP2040 already has a USB OTG controller, so this is really 1/ for getting an additional USB port and 2/ just as an exercise.But the nice thing with this is that it also gives you a starting point for implementing USB FS OTG on other targets. In particular, that would be a nice starting point for implementing this on some FPGA if you already use a soft core. Whatever is done with the PIO would be easily implementable on FPGA, and the software side ported to your soft core.Since it's being included in the TinyUSB project, I would suppose this project is already "mature" enough and reasonably implemented.

author: Simon
author_rank: Unknown
timestamp: May 30, 2022, 06:54:38 pm
content: when i looked it us I did not see mention of it although I was expecting to see one.

author: eugene
author_rank: Frequent Contributor
timestamp: May 31, 2022, 04:11:26 pm
content: At first I wasn't impressed with RPI taking such a creative approach with the RP2040, but it turns out to be a pretty cool chip.In another thread there's a lot of teeth gnashing over FTDI and Prolific USB to UART converter chips. An affordable alternative that doesn't require additional drivers might be attractive to at least a few people. (Understandably, there will always be a need for simple, low pin count, drop in solutions.) And there are RP2040 chips in stock, ready to buy today!

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 31, 2022, 11:24:28 pm
content: Quote from: eugene on May 31, 2022, 04:11:26 pmYes it's impressive they can even make this work.Resource Usage Two PIOOne PIO is for USB transmitter using 22 instruction and one state machineAnother PIO is for USB receiver using 31 instruction and two state machineTwo GPIO for D+/D- (Series 22ohm resistors are better)15KB ROM and RAM(For Host) One 1ms repeating timer(For Device) One PIO IRQ for receiverbut I've not seen benchmarks on the sustained data rates this can actually support ?Keyboard and mice emulation only need low data rates.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: June 01, 2022, 07:56:24 pm
content: Quote from: Simon on May 28, 2022, 03:24:36 pmFreeRTOS is (sometimes?) aware of multiple cores, and you can thus use them mostly transparently. I think it also has the ability to bind certain tasks to a specific core.Bit-banging USB was a real neat feat ... 17 years ago.Back then it was done on a 12MHz 8-bit AVR processor.I think it first started by a russian or bulgarian guy, and later it was a bit more formalized and Obdev released V-USBhttps://obdev.at/products/vusb/index.htmlAnd since that time I've been using it with my USBasp programmers.It "only" does low speed (1.5Mbps) USB but that's still only 8 clock cycles for each bit.But these days, it's mostly "meh, who cares". Apart from this temporary chip shortage there are so many uC's with hardwasre USB on board, that it just seems silly to want to bit bang it.I do think that V-USB can be a great resource for learning to work with USB.Instead of a gazillion pages of documentation of both USB and the peripherals in your uC, you have a quite small and compact library which is mostly written in C, with a bit of asm poured in for the bit banging itself, and they have working examples on their website.I've also once captured a bit of this data with Sigrok / Pulseview and the EUR 10 LA hardware (CY7C68013A based). Pulseview has nice software decoders and you see all kind of interesting stuff. Starting tokens (not differential), keep alive messages, checksums, and a whole lot more, and this all still works quite nicely on such cheap hardware and 1.5Mbps.

author: spostma
author_rank: Regular Contributor
timestamp: June 01, 2022, 08:40:04 pm
content: The beautiful thing is that all low-level bit banging is done in the PIO peripheral,and the shifted (parallel) result values get queued into a hardware FIFO (I assume per 32 bits word).Only one processor of the two gets interrupted every msec, and the CPU load seems to remain low.

author: Simon
author_rank: Unknown
timestamp: June 02, 2022, 08:33:13 am
content: Quote from: eugene on May 31, 2022, 04:11:26 pmIt looks like they have created the in-between a raspberry pi type device and a microcontroller. It's not an operating system oriented CPU but it is not actually a microcontroller as it has no program storage. But, we all love RAM, they have let you spend the money on the ram but leave the program storage up to you so it could be as small or large as you need and while you are at it this also allows to consolidate permanent program storage with non volatile data.