USB device smartpin example
__deets__
Posts: 203
in Propeller 2
In my current application I need to transfer data to a Rapberry PI with speeds of ~2MBit. I’ve used SPI for this in the past with a P1, but that’s much more cabling and rather cumbersome. And now that I’m on a P2, I could let USB deal with this. Alas, I haven’t found an example. I’ve read some posts here and there is even mentioning configuration management (which would open up exciting future options with class compliant devices), and the smart pin support document. But nothing was really painting the picture well enough for me.
Does such thing exist? And out of curiosity - how high can we go?
Comments
Garry is your man. He's the only one to even attempt it, afaik: https://forums.parallax.com/discussion/170149/p2-hosted-usb-keyboard-mouse/p1
For outputting as a master, a streamer could push quadSPI very high. 50 MByte/s is quite doable, even 100 MByte/s if DDR.
As a slave, not so much. There is no hardware clock in, you'd be bit-bashing it. And that's true for reading data back as a master too. You have to guess the clock timing, a magic number, and use that for triggering the streamer burst.
I've done a dualSPI for reading a flash chip with two smartpins. There you do have a clock input in hardware, albeit still emulated by the smartpin.
So if I’m not mistaken that is USB host code, no? I’d be interested in being a USB device. As the OI can only play host.
I have the core to spare for a SPI bit banging if I have to. The 2MBit are not relay critical, I’ve done even more than that on a P1. I thing 3 or so. More than enough to transfer the data I need.
From what I've seen, USB code for P2 does USB Host for USB-Keyboard and USB-mouse handling, as that's the more compelling use case.
USB device P2 code is still coming, but there you can also use any of the common USB-UART bridge devices.
The FTDI parts uses on Parallax products are good for 3MBd, and the UB3 on P2D2 can go higher.
In bursts, that can manage 6M.8.n.2 or 8M.8.n.2, with a 1536 byte buffer.
Peter tests that using Linux, so I presume it can also work on Pi as Host ?
I’ve had so far not much luck within USB serial beyond 400KBit. Admittedly the cheaper CP2303 or whaddayacallem on ESP32s. But the using FTDI is an option, got them here.
Can you elaborate what you mean by UB3? Is that just the FTDI chip on my eval board?
Ages ago, I had SPI working with Raspi Zero. The bus speed was set to 5 MHz.
https://forums.parallax.com/discussion/170834/raspberry-pi-zero-as-gpu-over-spi
But, I just looked at the Prop side code and it would take some work to bring it up to current due to all the compiler changes...
I’m not worried about SPI. I’ve got a P1 PASM variant that’s fast enough. Without moving to smart Pins it will be easy enough to port (I think). At least I’m not worried.
Serial as well as USB are mostly more convenient form a wiring and host side programming perspective.
I have 1.92 Mbps serial (UART) running between RPi Zero and P2.
To have things faster, i2s can be used which I hadn't tried yet for a P2 communication, but I tried it up to 5 MBps between 2 RPis connected via standard "breadboard type" (but female at both ends to fit RPi GPIO) 10 cm/4 inch length cables. As I have a ready made i2s code for a baremetal (Ultibo) RPi I only have to learn how to implement this on a P2.
The newer CP2102N can manage 3-4MBd
The UB3 is the EFM8UB3 Flash MCU on the P2D2 board, that has USB-Bridge code, plus other wdog and monitoring features builtin. Parallax use FTDI parts on their boards.
If you need even faster serial, the FT232H / FT2232H parts can manage 12MBd, but they are a but larger physically, and more $, and there is no P2 board yet with those included
Ah, P2D2 is another board. That makes total sense then. I think I have a few FTDI adapters, gotta check them out how fast they would go.
I’m still hoping for a USB primer at some point given that there is even a eval breakout board.
The ftdi chip on the eval board works up to 3 MBaud
With a PC anyway...
The prop2's USB documentation is a small section with that smartpin mode in the hardware manual. It would be fair to say one must already know the workings of USB when reading it. That counts me out.
You don't need any FTDI chip to connect P2 to RPi via UART: 3 wires are enough.