Author Topic: amazing project: USB FS host/device using RP2040 PIO  (Read 4301 times)

0 Members and 1 Guest are viewing this topic.

Offline spostmaTopic starter

  • Regular Contributor
  • *
  • Posts: 123
  • Country: nl
amazing project: USB FS host/device using RP2040 PIO
« on: May 17, 2022, 07:23:59 pm »
via the Ultibo forum (which is a great bare metal rPi platform), I stumbled over this link about an amazing project
to implement a full speed USB host and device (simultaneously if you want) on a RP2040 processor:
https://ultibo.org/forum/viewtopic.php?p=12872#p12872

It links to
https://github.com/sekigon-gonnoc/Pico-PIO-USB

This project is being merged with the tiny usb project:
https://github.com/sekigon-gonnoc/Pico-PIO-USB/pull/22
https://github.com/adafruit/Adafruit_TinyUSB_Arduino/issues/169

enjoy and spread the word about this top-class hacking project by sekigon-gonnoc, hathach and FahimFBA!
It is not fiished, but progresses very quickly...
« Last Edit: May 17, 2022, 07:27:08 pm by spostma »
 
The following users thanked this post: hans, thm_w, edavid, gamalot

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17936
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: amazing project: USB FS host/device using RP2040 PIO
« Reply #1 on: May 28, 2022, 10:41:53 am »
why is it haking? it's called programming and bit banging
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6159
  • Country: es
Re: amazing project: USB FS host/device using RP2040 PIO
« Reply #2 on: May 28, 2022, 01:28:01 pm »
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"  :D
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17936
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: amazing project: USB FS host/device using RP2040 PIO
« Reply #3 on: May 28, 2022, 03:24:36 pm »
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?
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15093
  • Country: fr
Re: amazing project: USB FS host/device using RP2040 PIO
« Reply #4 on: May 28, 2022, 05:05:25 pm »
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.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17936
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: amazing project: USB FS host/device using RP2040 PIO
« Reply #5 on: May 30, 2022, 06:54:38 pm »
when i looked it us I did not see mention of it although I was expecting to see one.
 

Offline eugene

  • Frequent Contributor
  • **
  • Posts: 496
  • Country: us
Re: amazing project: USB FS host/device using RP2040 PIO
« Reply #6 on: May 31, 2022, 04:11:26 pm »
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!
90% of quoted statistics are fictional
 

Online PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 1745
  • Country: au
Re: amazing project: USB FS host/device using RP2040 PIO
« Reply #7 on: May 31, 2022, 11:24:28 pm »
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!


Yes it's impressive they can even make this work.

Resource Usage Two PIO
  • One PIO is for USB transmitter using 22 instruction and one state machine
    Another PIO is for USB receiver using 31 instruction and two state machine
    Two 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 receiver


but I've not seen benchmarks on the sustained data rates this can actually support ?
Keyboard and mice emulation only need low data rates.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3692
  • Country: nl
Re: amazing project: USB FS host/device using RP2040 PIO
« Reply #8 on: June 01, 2022, 07:56:24 pm »
How do you even write code for multiple core microcontrollers?

FreeRTOS 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-USB
https://obdev.at/products/vusb/index.html

And 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.


 

Offline spostmaTopic starter

  • Regular Contributor
  • *
  • Posts: 123
  • Country: nl
Re: amazing project: USB FS host/device using RP2040 PIO
« Reply #9 on: June 01, 2022, 08:40:04 pm »

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.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17936
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: amazing project: USB FS host/device using RP2040 PIO
« Reply #10 on: June 02, 2022, 08:33:13 am »
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!

It 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf