Author Topic: USB interface from scratch -- what should I watch out for?  (Read 5252 times)

0 Members and 2 Guests are viewing this topic.

Offline ebastlerTopic starter

  • Super Contributor
  • ***
  • Posts: 7156
  • Country: de
USB interface from scratch -- what should I watch out for?
« on: July 09, 2017, 03:50:11 pm »
So I built this replica of the LGP-30, a rather old (1956) computer. Hardware-wise, the replica is essentially an I/O shield for a cheap Spartan-6 FPGA board, the Numato Mimas. The FPGA implements the complete logic equations of the LGP-30's bit-serial CPU (which conveniently had been published in the service manual and in a scientific paper by the original designer).

My current implementation provides an RS-232 port to connect an ASCII terminal, which replaces the pre-ASCII "Flexowriter" teletype machine that came with the LGP-30. Typically, this port will end up being connected to a PC-based terminal program, via USB and an FTDI or equivalent chip. So it would be convenient to also offer a direct USB connection on my I/O board -- to lose the FTDI adapter, and also supply power via just a single cable.

I would like to drive the USB port directly from the FPGA, without any additional interface chip. (That's because (a) I'm cheap, (b) I want to avoid exotic chips, and avoid SMD components, and (c) I like a challenge. ;)) I have located open-source VHDL implementations for USB serial data transmission and for a USB 1.1 PHY layer, so this seems feasible.

My question refers to the electrical side of the USB interface, since I have never built one from scratch so far:
  • What protection seems absolutely necessary, both on the +5V and the data lines, to limit the chance of damaging the PC or the FPGA by mishaps?
  • Any recommendations for avoiding the worst EMI problems, while keeping things simple?
  • Any important layout considerations? This will run at USB 1.1 speeds only, so hopefully does not pose major challenges on this front?
Please keep in mind that this is not meant to be a commercial product. But I would like to make the plans available to other hobbyists, and hence make the design robust enough to avoid headaches for others building it (and for myself, supporting it...). To make the design easy to replicate, I woud like to avoid "special" parts if possible.

Thanks for any advice you may have!
Jürgen
« Last Edit: April 22, 2019, 07:29:33 pm by ebastler »
 

Elf

  • Guest
Re: USB interface from scratch -- what should I watch out for?
« Reply #1 on: July 09, 2017, 04:15:55 pm »
  • What protection seems absolutely necessary, both on the +5V and the data lines, to limit the chance of damaging the PC or the FPGA by mishaps?
  • Any recommendations for avoiding the worst EMI problems, while keeping things simple?
I have been incorporating USB interfaces into some things lately. These may count as special parts, but I now use these as standard for USB:

For host/OTG interfaces I will have power go through a TI TPS2041B current limited switch instead of the Polyzen.

  • Any important layout considerations? This will run at USB 1.1 speeds only, so hopefully does not pose major challenges on this front?
USB is supposed to be run on a 90 ohm differential pair. For USB 1.1 if you keep the connector close to the chip and keep the lines balanced (with appropriate series resistors for D+/D-), then it isn't going to be too critical that it is exactly 90 ohm.
« Last Edit: July 09, 2017, 04:17:34 pm by Elf »
 
The following users thanked this post: ebastler

Offline Leo Bodnar

  • Frequent Contributor
  • **
  • Posts: 814
  • Country: gb
Re: USB interface from scratch -- what should I watch out for?
« Reply #2 on: July 09, 2017, 04:51:02 pm »
  • Any recommendations for avoiding the worst EMI problems, while keeping things simple?
  • Any important layout considerations? This will run at USB 1.1 speeds only, so hopefully does not pose major challenges on this front?

Are you going for LS or FS - they are both 1.1?  They have slightly different requirements for capacitive load, edge rate and maximum cables length.

LS is really easy, for non-commercial project you don't really have to worry about anything.  Folks are still using AVRs to bit-bang almost fully compliant chapter 9 devices using no more than a pull-up resistor (because you said you are cheap...)
 
The following users thanked this post: ebastler

Offline ebastlerTopic starter

  • Super Contributor
  • ***
  • Posts: 7156
  • Country: de
Re: USB interface from scratch -- what should I watch out for?
« Reply #3 on: July 09, 2017, 05:35:20 pm »
  • Any recommendations for avoiding the worst EMI problems, while keeping things simple?
Are you going for LS or FS - they are both 1.1? 
LS is really easy, for non-commercial project you don't really have to worry about anything. 

Good point, thank you. To be honest, I had not even remembered that low-speed mode existed. It should certainy be fast enough though; all I want to transfer is 19.2 kBaud serial data.

I will look into the "poor man's" AVR implementation to get a data point at the other end of the spectrum vs. Elf's professional recommendations.  Guess I'm aiming for a halfway solution...  ;)

Edit: Quote formatting fixed; not sure what happened there...
Also noted Leo's further comment below -- thanks!
« Last Edit: July 09, 2017, 08:48:29 pm by ebastler »
 

Offline Leo Bodnar

  • Frequent Contributor
  • **
  • Posts: 814
  • Country: gb
Re: USB interface from scratch -- what should I watch out for?
« Reply #4 on: July 09, 2017, 07:02:27 pm »
Good point, thank you. To be honest, I had not even remembered that low-speed mode existed. It should certainy be fast enough though; all I want to transfer is 19.2 kBaud serial data.

Sorry I just gave you a bad idea :)  LS USB does not support bulk transfers and as a consequence - CDC class.
Your only choice is FS and up.
Leo

Online BradC

  • Super Contributor
  • ***
  • Posts: 2110
  • Country: au
Re: USB interface from scratch -- what should I watch out for?
« Reply #5 on: July 10, 2017, 02:34:37 am »
Sorry I just gave you a bad idea :)  LS USB does not support bulk transfers and as a consequence - CDC class.
Your only choice is FS and up.
Leo

While technically true, BULK over low speed works on both Windows and OSX. It works on Linux if you patch out the check in the USB driver that prevents it from working. It *is* a hack though.
 
The following users thanked this post: ebastler

Offline Leo Bodnar

  • Frequent Contributor
  • **
  • Posts: 814
  • Country: gb
Re: USB interface from scratch -- what should I watch out for?
« Reply #6 on: July 10, 2017, 07:50:15 am »
While technically true, BULK over low speed works on both Windows and OSX. It works on Linux if you patch out the check in the USB driver that prevents it from working. It *is* a hack though.
Sure, it is a hack and only works because driver writers do not expect device to do that and don't have exhaustive checks for everything that specification forbids.  USB spec guarantees that [certified] USB device won't use bulk in LS so why check?  You can also use 1024 byte long interrupt packets in HID devices on early versions of Windows and abuse the stack in a lot of other ways. Long HID packets loophole got fixed in Vista and there were a few commercial devices that stopped working.

Jürgen's design criteria is to not have a device that needs a lot of support.
 
The following users thanked this post: ebastler

Offline ebastlerTopic starter

  • Super Contributor
  • ***
  • Posts: 7156
  • Country: de
Re: USB interface from scratch -- what should I watch out for?
« Reply #7 on: July 10, 2017, 10:09:23 am »
Thanks, Brad and Leo! I appreciate the further insight on USB Low Speed mode, its limitations and possible hacks.

I tend to go with Leo's advice and opt for a solution that works out-of-the-box on the major operating systems. Full Speed does not seem too intimidating from the electrical perspective -- and should still be accessible for my 100 MHz scope, to get an idea of signal quality and slopes. I think I will give that a try.

Now on to convincing the family that my retro-computing gear has to accompany us on this year's summer vacation...  ;)
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9940
  • Country: us
Re: USB interface from scratch -- what should I watch out for?
« Reply #8 on: July 11, 2017, 04:31:38 pm »
Opencores has something that is intended to work with the Microblaze core but it may be useful for background:
https://opencores.org/project,opb_usblite
 

Offline ebastlerTopic starter

  • Super Contributor
  • ***
  • Posts: 7156
  • Country: de
Re: USB interface from scratch -- what should I watch out for?
« Reply #9 on: July 11, 2017, 08:02:39 pm »
Opencores has something that is intended to work with the Microblaze core but it may be useful for background:
https://opencores.org/project,opb_usblite

Thanks rstofer, I had not spotted that one.
They also have a USB core and physical layer by Rudolf Usselmann which seem to be very mature and hopefully stable, but don't come with much documentation. (Rudolf's business model is to provide free cores, and paid consulting where needed.) The additional background from the Microblaze core might come in handy!

https://opencores.org/project,usb_phy
https://opencores.org/project,usb1_funct
 

Offline ebastlerTopic starter

  • Super Contributor
  • ***
  • Posts: 7156
  • Country: de
Re: USB interface from scratch -- what should I watch out for?
« Reply #10 on: August 12, 2017, 04:37:47 pm »
I have been incorporating USB interfaces into some things lately. These may count as special parts, but I now use these as standard for USB:

Coming back to this side project of mine. In the meantime I have successfully cobbled together the USB stack for a full-speed CDC device in the FPGA, thanks to available open-source components, and have integrated it into my retro-computer simulation. For protecting the physical interface, I have decided to go with elf's recommendation and use the dual TVS for the data lines and the Polyzen to protect from Vbus mishaps.

As I don't have a Polyzen device in hand yet, I was wondering about the footprint and how it can be soldered. The Polyzens are meant for reflow soldering, but my PCB needs to be suitable for hand-soldering too (for myself and potentially other builders).

Can the -LS version of the Polyzen be hand-soldered if I make the pads a bit larger? It seems like the device itsef has solder pads on the bottom only, not at the sides, and that the specified PCB layout has pads only below the device?

Thanks for any hints you might have!
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9940
  • Country: us
Re: USB interface from scratch -- what should I watch out for?
« Reply #11 on: August 12, 2017, 10:56:17 pm »
I would just make the pads a little wider so that there is a bit of pad beyond the edge of the device.

I might use solder paste on the pads, place the part and then hit the exposed pad with a soldering iron.

Or, I might just put those 3 parts on the board with solder paste and reflow them.

Or, I might just cover the pads with flux paste and place a drop of solder on the iron.  Holding the tip against the exposed pad should do the trick.  Kind of like drag soldering.

All in, a non-event.

BTW, it looks like the chip pin rises up the side of the package like many other packages.  This makes it particularly easy to solder.
 

Offline ebastlerTopic starter

  • Super Contributor
  • ***
  • Posts: 7156
  • Country: de
Re: USB interface from scratch -- what should I watch out for?
« Reply #12 on: August 13, 2017, 03:45:44 am »
Thanks, rstofer -- yes, I was thinking along those same lines. Probably all of these soldering methods will work if the PCB pads are wide enough to feed some heat in. What made me a bit nervous was that, from the photographs I looked at, it does not seem like the Polyzen -LS device has regular pins. Its bottom layer looks more like a mini-PCB with pads on the bottom only?

Anyway, I have already edited that standard footprint to make the pads a bit wider. Will send the PCB off for manufacturing, order parts in parallel, and figure out how to best solder them once I have everything in hand.
 

Offline Leo Bodnar

  • Frequent Contributor
  • **
  • Posts: 814
  • Country: gb
Re: USB interface from scratch -- what should I watch out for?
« Reply #13 on: August 13, 2017, 08:52:03 am »
I am very curious why you are going through all the trouble with using Polyzens?  Unlike the TVS you can't leave it out - it needs at least a short to make the board work.

What Vbus mishaps are you trying to protect against?  According to USB spec protection against Vbus shorts (about 1A in actual designs) to GND is the job of the upstream device and it has been followed by the manufacturers pretty well.  Every PC that does not have port protection has already burnt out. 

I have never seen a host with Vbus exceeding the USB spec continuously.  And proper USB TVS clamps already have transient protection for Vbus - like TPD2E001.

Cheers
Leo

Offline ebastlerTopic starter

  • Super Contributor
  • ***
  • Posts: 7156
  • Country: de
Re: USB interface from scratch -- what should I watch out for?
« Reply #14 on: August 13, 2017, 09:01:49 am »
I am very curious why you are going through all the trouble with using Polyzens?  Unlike the TVS you can't leave it out - it needs at least a short to make the board work.

Valid question! If this were a pure USB port, I would probably be less concerned about the Vbus quality. But my little retro-computer also has a conventional RS-232 port, for those who want to use it with a vintage terminal rather than a PC and terminal program. In that case, the USB connector can be used as just a power jack, and power supplies with wrong polarity or voltage seem somewhat more likely to show up. Hence the Polyzen.

I did provide for a jumper in parallel with the the Polyzen in the PCB layout, so it is optional.  ;)
 

Offline Leo Bodnar

  • Frequent Contributor
  • **
  • Posts: 814
  • Country: gb
Re: USB interface from scratch -- what should I watch out for?
« Reply #15 on: August 13, 2017, 09:27:11 am »
the USB connector can be used as just a power jack, and power supplies with wrong polarity or voltage seem somewhat more likely to show up. Hence the Polyzen.
OK, I see. It's a good answer!
Leo
 
The following users thanked this post: ebastler


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf