Author Topic: USB OTG between microcontrollers  (Read 19999 times)

0 Members and 4 Guests are viewing this topic.

Offline Esposch T. Tapir

  • Contributor
  • Posts: 36
  • Country: au
Re: USB OTG between microcontrollers
« Reply #25 on: May 12, 2015, 12:08:14 am »
Quote
It is obviously created by programmers not Engineers.

Hahaha, I was thinking the same thing.  Just didn't say anything because I didn't want to slander an entire profession when I haven't worked with any of them in the real world.

LUFA is a good place to start. If you are unlucky you have to write the hardware drivers but that is still much less work than creating your own stack from scratch.

It is worth noting that LUFA is, for the most part, incompatible with ASF.  Not that you need ASF, but it's definitely useful for certain tasks (e.g printf()ing to dot matrix LCDs).
Bachelor of Engineering (ECSE) with Honours.
Every time I write a line of code or build a circuit I am reminded that, in the grand scheme of things, I know bugger all.
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: USB OTG between microcontrollers
« Reply #26 on: May 12, 2015, 12:26:28 am »
Quote
It is obviously created by programmers not Engineers.

Hahaha, I was thinking the same thing.  Just didn't say anything because I didn't want to slander an entire profession when I haven't worked with any of them in the real world.
[/quote]

Some quick research would show that is not the case, blame design by committee if you want to point fingers, just too many cooks :P
 

Offline marcan

  • Regular Contributor
  • *
  • Posts: 80
  • If it ain't broke I'll fix it anyway.
    • My blog
Re: USB OTG between microcontrollers
« Reply #27 on: May 12, 2015, 03:54:48 am »
I've been doing a bit of USB stuff recently, and it is an absolute nightmare.
It is obviously created by programmers not Engineers.
No, USB is one of the best (worst) examples of Design by Committee. A committee of engineers and a committee of programmers can both be equally dangerous. Worst is when you put together a committee of hardware and software engineers/programmers with nobody who actually understands both sides. The impedance mismatch of epic proportions guarantees a steaming pile of crap as the output.

Then again, it could be worse. It could be Bluetooth.

Anyway, as for abusing USB as a lower-level protocol, it's doable, but you can't get away from the basic USB topology where one side is the host and the other is the device. At a bare minimum, you have to configure each side's peripheral for the correct role, hardcode the speed mode to whatever you want, hardcode an address on the device (e.g. 1), set up a pair of IN/OUT endpoint pipes on both ends, and then just have the host side send OUT packets when it wants to, and poll for IN packets periodically. You need to make sure you implement data toggle (subsequent packets should be sent with alternating DATA0/DATA1 PIDs) since that's part of hardware packet retransmission support, if the hardware doesn't do that for you. You can ignore all of the enumeration/configuration/descriptor stuff which is the most painful part of USB.

If you want to have more than a point-to-point link, sorry, you're screwed. You're going to have to implement the enumeration crap to be able to talk to a standard hub chip. You can still get away with hardcoding things instead of parsing descriptors though, but at that point I'd say it's more trouble than it's worth.

If you had bare USB PHYs, and not the built-in peripherals which are smarter, you could abuse it at a lower level even (and e.g. improve throughput) but you still won't really get away from the master/slave requirement; ultimately you'd have to define some kind of bus arbitration protocol (since TX and RX share the same pair in USB) that would end up looking very similar to what normal USB does anyway.

If all you want is the equivalent of full-speed USB (12mbps), just use SPI or whatever. SPI works fine at 32MHz. Same with higher-baudrate RS485. USB is really asking for trouble.

I make it usually in four steps. 1. Download manufacturers' example 2. Copy it into your project 3. Use it as any other serial port 4. download drivers after realizing why it is not working.
Honestly, there's a big difference between your average manufacturer sample code blob for CDC and a nice microcontroller interconnect system with all the features that you mentioned. If you're the kind of person that enjoys using those horrid monsters of sample code as a black box, you're not going to enjoy trying to work out how to do this and make it work properly. Real engineering isn't about copying and pasting sample code, and designing a microcontroller interconnect system around commodity USB peripherals requires real engineering, since you're going outside of established use cases.
 

Online tszabooTopic starter

  • Super Contributor
  • ***
  • Posts: 9917
  • Country: nl
  • Current job: ATEX product design
Re: USB OTG between microcontrollers
« Reply #28 on: May 12, 2015, 07:56:32 am »
Honestly, there's a big difference between your average manufacturer sample code blob for CDC and a nice microcontroller interconnect system with all the features that you mentioned. If you're the kind of person that enjoys using those horrid monsters of sample code as a black box, you're not going to enjoy trying to work out how to do this and make it work properly. Real engineering isn't about copying and pasting sample code, and designing a microcontroller interconnect system around commodity USB peripherals requires real engineering, since you're going outside of established use cases.
Then you must be glad to hear that I'm the guy that designs the circuit boards, not the guy who writes the code. Usually when I have to write code or decide to write code, I use whatever which gets the job done by the fastest possible, so I can go back to do what I actually enjoy. So a blob of code (which I described quite well) is fine as long as it works.
Measure power rails with 2GHz bandwidt: https://eleshop.eu/prp1-power-rail-probe.html
 

Offline marcan

  • Regular Contributor
  • *
  • Posts: 80
  • If it ain't broke I'll fix it anyway.
    • My blog
Re: USB OTG between microcontrollers
« Reply #29 on: May 12, 2015, 09:28:03 am »
Then you must be glad to hear that I'm the guy that designs the circuit boards, not the guy who writes the code. Usually when I have to write code or decide to write code, I use whatever which gets the job done by the fastest possible, so I can go back to do what I actually enjoy. So a blob of code (which I described quite well) is fine as long as it works.
Fair enough, but I'm sure you realize that just as real board design isn't about copying and pasting template layouts from datasheets and app notes, real software/firmware engineering isn't about copying and pasting example code. For one, this is how non-compliant USB devices are made (e.g. example that code "works" but does not follow the standard, and then you get things like bus-powered devices reporting themselves to be self-powered because whoever wrote the firmware didn't know how to configure it properly, or that do not handle a perfectly legitimate request in the standard because, hey, the Windows drivers never use it). It's not really reasonable to expect to correctly design a device if you don't understand or care for an entire half of its development process and just resort to canned examples for it.

Quoting from your original message:
This opens endless possibilities. Basically boards could be chained, or connected together with just a standard USB HUB.
Backplanes could be implemented by using these protocol, where only two pins and standard libraries could take care about the entire communication, hot swapping it, timing it, arbitration and so on.
That kind of system takes as much, if not more, engineering on the firmware side than on the PCB/circuit design side; it's a non-traditional use of the hardware on both fronts and you're not going to get away with just canned examples for either side. USB is a standard geared towards using it with something like a PC as the host, and it's highly unlikely that standard OTG libraries for micros will do everything you want properly.

So if you really want to do this, you're going to have to think hard about what kind of features and constraints you really want, and talk to someone more experienced with the mess that is USB at both the hardware and higher logic layers to figure out if it's feasible. I think we've covered the simple case of peer-to-peer communications between two micros using a minimal protocol over USB hardware, which would definitely require writing some custom software but at least wouldn't be anywhere near as complex as a full USB stack. That doesn't handle hot swapping, hubs, etc, though, and going there is where things get tricky on the firmware side of things.
 

Offline tmbinc

  • Frequent Contributor
  • **
  • Posts: 270
Re: USB OTG between microcontrollers
« Reply #30 on: May 12, 2015, 09:55:47 am »
USB is not great, but it's not as horrible as people make it sound. Yes, it has unfortunate performance characteristics (like USB1.1's "sending a DATA packet over and over just to receive a NAK for it every time"), but once you see the limitations as trade-offs (ahem), it's something workable. Not great. Don't get me wrong. I'd still not use it for chip-to-chip connectivity.

Even enumeration isn't that complicated. Implement GET_DESCRIPTOR (simple, just return a fixed string based on wValue/wIndex), SET_CONFIGURATION (dummy), GET_STATUS (dummy), SET_ADDRESS (just poke your hardware's address register) and be done. It won't be standard compliant, but it gets you enumerated. That's ~50 lines of non-dense code.

And then, yeah, just use bulk transfers.


What makes USB really frustrating, in my mind, are two things: a.) you don't need to understand it in order to use it, and b.) USB is cheap.

For a.), it allows you to go with the black box approach (take vendor code, compile, use, throw it against the wall because it doesn't fully work and hangs every two hours) for quite a long time. You can develop USB devices these days without understanding which USB packets exist. That's different from, say, TCP/IP, where Ethereal is your friend and you get full insight down to ethernet level with a few mouse clicks. Or a serial port, where, to be honest, not many corner cases can happen anyway.

But with USB it's different. You _need_ to understand what's going on on the wire, otherwise the first issue you run into will turn into a heisenbugfestmess. The issue is that it's not easy to get there. usbmon and friends are not telling you what's going on on the wire, but instead what _should_ go on on the wire. I was scared of USB until I bought a (even back then overpriced) LeCroy analyzer from the BenQ germany auction. But it was the first time I could actually make sense out of those dreaded kernel messages a la "Device does not accept address" etc., and get a hint in debugging them other than just cargo-cult programming. USB analyzers thankfully got less expensive.

For b.), the issue is that USB is so mass-market, you can't trust anything anymore. Your hub? marcan will happily tell you horror stories. Cables? Don't get me started. Cheap usb controllers that just don't respond to certain commands, and an equal number of ugly workarounds in the kernel drivers? Check.
 

Offline marcan

  • Regular Contributor
  • *
  • Posts: 80
  • If it ain't broke I'll fix it anyway.
    • My blog
Re: USB OTG between microcontrollers
« Reply #31 on: May 12, 2015, 10:06:56 am »
But with USB it's different. You _need_ to understand what's going on on the wire, otherwise the first issue you run into will turn into a heisenbugfestmess. The issue is that it's not easy to get there. usbmon and friends are not telling you what's going on on the wire, but instead what _should_ go on on the wire. I was scared of USB until I bought a (even back then overpriced) LeCroy analyzer from the BenQ germany auction. But it was the first time I could actually make sense out of those dreaded kernel messages a la "Device does not accept address" etc., and get a hint in debugging them other than just cargo-cult programming. USB analyzers thankfully got less expensive.
You're lucky to have had the cash. I wrote the device stack that my first USB device used in PIC18 assembler and debugged it with 4 LEDs. At more than one point I was latching and outputting packet fields via the LEDs. Getting it to work with Windows (which will unhelpfully tell you nothing about what went wrong when a device fails to enumerate - Linux at least vaguely hints at the source of the issue) was "fun". I certainly couldn't afford an oscilloscope or logic analyzer back then, let alone a USB analyzer.

For b.), the issue is that USB is so mass-market, you can't trust anything anymore. Your hub? marcan will happily tell you horror stories. Cables? Don't get me started. Cheap usb controllers that just don't respond to certain commands, and an equal number of ugly workarounds in the kernel drivers? Check.
I'm just going to say avoid Genesys Logic hub chips like the plague.
« Last Edit: May 12, 2015, 10:09:25 am by marcan »
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: USB OTG between microcontrollers
« Reply #32 on: May 13, 2015, 03:16:32 am »
Maybe wait until USB Type-C is more common?





http://www.cypress.com/Type-C/

http://en.wikipedia.org/wiki/USB#USB_Type-C

Edit: more technical, lengthy and with a monotone voice announcer



and sorry for the Cypress overload, just happened to be watching the cypress channel when I ran into the Type-C connector :)

« Last Edit: May 13, 2015, 03:22:00 am by miguelvp »
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: USB OTG between microcontrollers
« Reply #33 on: May 13, 2015, 06:04:05 pm »
If anyone can figure out to make USB physical interface into a fast low-level data pipe, without all the USB protocol baggage, I think that would be very interesting. Peer-to-peer would be useful, network would be great.

From my understanding of USB, the USB device hardware has special stuff to be a device, and similar for host. At least OTG might be needed to perform necessary host functions.
Bob
"All you said is just a bunch of opinions."
 

Offline Brutte

  • Frequent Contributor
  • **
  • Posts: 614
Re: USB OTG between microcontrollers
« Reply #34 on: May 13, 2015, 06:45:06 pm »
If anyone can figure out to make USB physical interface into a fast low-level data pipe, without all the USB protocol baggage, I think that would be very interesting. Peer-to-peer would be useful, network would be great.
USB device stack is really tiny. IIRC the simplest HID on AVR8 (ATMega16U2) occupies less than 2k of flash.
As most of decent USB uCs are 16k or more, I cannot see why would anyone want to dump USB interoperability for the price of that 1k of flash. Get a bigger tiny.

As for USB OTG, the smallest uC I know of is 64k. How much would you expect to save here?

Now for the throughput, Full-speed USB reaches 1MB/s out of theoretically 12Mbps available (half duplex). Neither here is the place for improvements. Get Hi-Speed instead of reinventing the wheel.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 30417
  • Country: nl
    • NCT Developments
Re: USB OTG between microcontrollers
« Reply #35 on: May 13, 2015, 07:16:03 pm »
Most USB host/OTG microcontrollers also have ethernet. You can cross connect their MACs (without PHYs in between) and you'll have a 100Mbit DMA capable interface in between. A small CPLD could act as a hub between several PHY-less ethernet devices.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online tszabooTopic starter

  • Super Contributor
  • ***
  • Posts: 9917
  • Country: nl
  • Current job: ATEX product design
Re: USB OTG between microcontrollers
« Reply #36 on: May 13, 2015, 09:25:44 pm »
Most USB host/OTG microcontrollers also have ethernet. You can cross connect their MACs (without PHYs in between) and you'll have a 100Mbit DMA capable interface in between. A small CPLD could act as a hub between several PHY-less ethernet devices.
That sounds like science fiction to me. MII or RMII is not a symmetrical interface. What happens with clocks, enables, error signals? Could you give us an example?
Measure power rails with 2GHz bandwidt: https://eleshop.eu/prp1-power-rail-probe.html
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4644
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: USB OTG between microcontrollers
« Reply #37 on: May 13, 2015, 09:57:26 pm »
I stumbled upon USB SSIC in the 3.1 standard, which translates to USB SuperSpeed Inter Inter-Chip.
So your idea is already being considered by the USB people.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 30417
  • Country: nl
    • NCT Developments
Re: USB OTG between microcontrollers
« Reply #38 on: May 13, 2015, 10:27:11 pm »
Most USB host/OTG microcontrollers also have ethernet. You can cross connect their MACs (without PHYs in between) and you'll have a 100Mbit DMA capable interface in between. A small CPLD could act as a hub between several PHY-less ethernet devices.
That sounds like science fiction to me. MII or RMII is not a symmetrical interface. What happens with clocks, enables, error signals? Could you give us an example?
The interface is symetric. The clock comes from the PHY so provide an appropriate clock (IIRC 25 or 50MHz) to both controllers. Connect TX to RX and cross 'receive data valid' with 'transmit enable'. If you add bus buffers you can create a bidirectional bus between multiple devices while using the colission / carrier sense signal + some logic to signal the bus being busy or free. This may be less straightforward due to timing issues but the idea should work.
« Last Edit: May 13, 2015, 10:58:19 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online tszabooTopic starter

  • Super Contributor
  • ***
  • Posts: 9917
  • Country: nl
  • Current job: ATEX product design
Re: USB OTG between microcontrollers
« Reply #39 on: May 14, 2015, 07:41:28 am »
I stumbled upon USB SSIC in the 3.1 standard, which translates to USB SuperSpeed Inter Inter-Chip.
So your idea is already being considered by the USB people.
2.0 had High-Speed Inter-Chip already. It has different physical layer.
http://ww1.microchip.com/downloads/en/AppNotes/00001602A.pdf
I consider it as a failure, never got any wind, like the wireless USB.
Measure power rails with 2GHz bandwidt: https://eleshop.eu/prp1-power-rail-probe.html
 

Offline photon

  • Frequent Contributor
  • **
  • Posts: 260
  • Country: us
Re: USB OTG between microcontrollers
« Reply #40 on: May 14, 2015, 08:33:36 am »
One brilliant move the USB folks made was for the bus to supply power. This one idea alone ensures the survival of USB for at least the next 10 years. This does not help it be a board level bus much less a chip level bus.
 

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 898
  • Country: es
Re: USB OTG between microcontrollers
« Reply #41 on: May 15, 2015, 11:28:00 pm »
USB HSIC is alive! Example: application CPU <-> cellular modem interconnect in every iPhone starting from 4s.
But that's a direction completely opposite to OP's idea: HSIC keeps the same complex protocols while simplifying the PHY to work point to point (no hubs) and just few cm distance.
 

Offline John_ITIC

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: us
  • ITIC Protocol Analyzers
    • International Test Instruments Corporation
Re: USB OTG between microcontrollers
« Reply #42 on: May 16, 2015, 05:16:19 am »
Since I design USB Protocol Analyzers for a living I though I'd chime in my $0.02...

The bottom line is that USB is designed to be completely plug-and-play for the user, no configuration of IRQs and I/O addresses as prior buses like ISA and the like. USB 1.1 was designed to replace the commonly used PC parallel port, keyboard port and mouse port with a single port. All this functionality however means that for the engineer that actually have to implement all this magic, it becomes orders of magnitude more complex. If you need to understand on-the wire protocols then you need a hardware protocol analyzer. USB analyzers used to be thousands of dollars but can now be had for hundreds.

USB is designed to have 90% of the complexity on the host controller side (i.e. PC hardware and device drivers). The host controller schedules all transactions to all discovered devices on the bus (up to 127 devices), handles traffic across hubs, discovers capabilities of unknown devices and much more. Essentially, the host controller handles all bus transactions in hardware and the associated host controller device driver sets up the data transfers as instructed by higher-layer software.

Therefore, if you have two chips known that you need to have communicate then USB is not well suited. Instead choose a simple SERDES protocol or a semi-fast parallel protocol, depending on bandwidth requirements. If using FPGAs, there is cheap of no-cost IP available that can be leveraged.

Finally, USB has nothing to do with Ethernet. A USB 2.0 PHY actually doesn't have separate TX and RX signals but rather a shared set of differential D+ and D- signals that alternate between sending and receiving. USB 3.0 has two sets for dual simplex but still nothing to do with Ethernet. The host controller and device still have very different capabilities in USB 3.0. You can in USB 3.0 hook up two PHYs against each other only if you develop your own MAC layer (in FPGA). Again, this is hugely complex (but interesting...).

/John.

« Last Edit: May 16, 2015, 05:18:49 am by John_ITIC »
Pocket-Sized USB 2.0 LS/FS/HS Protocol Analyzer Model 1480A with OTG decoding.
Pocket-sized PCI Express 1.1 Protocol Analyzer Model 2500A. 2.5 Gbps with x1, x2 and x4 lane widths.
https://www.internationaltestinstruments.com
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 30417
  • Country: nl
    • NCT Developments
Re: USB OTG between microcontrollers
« Reply #43 on: May 16, 2015, 09:33:11 am »
A quick note: ethernet has been mentioned because a MAC (MII / RMII interface) can be used to create a point-to-point or point-to-multipoint on board network without PHYs or a switch very easely.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 12782
  • Country: nz
Re: USB OTG between microcontrollers
« Reply #44 on: May 16, 2015, 10:02:31 am »
An ARM cpu with 32KB in system reprogrammed flash inside every usb cable... What could go wrong??

Damn, my usb cable has a virus
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: USB OTG between microcontrollers
« Reply #45 on: May 16, 2015, 11:42:38 am »
It's funny how the OPs fairly straightforward idea turns into 3 pages of people missing the point and going off on irrelevant tangents. No one really addressed the key question.

Oh well, that's engineers for you :)
Bob
"All you said is just a bunch of opinions."
 

Offline photon

  • Frequent Contributor
  • **
  • Posts: 260
  • Country: us
Re: USB OTG between microcontrollers
« Reply #46 on: May 16, 2015, 06:46:41 pm »
It's funny how the OPs fairly straightforward idea turns into 3 pages of people missing the point and going off on irrelevant tangents. No one really addressed the key question.
The point, being the OPs idea of using USB as a bus between microcontrollers, has been addressed. It's not a good idea.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->