TX vs RX naming conventions for USB 3.0 SuperSpeed pairs

Just a draft note for now, as a result of a mistake I made while designing a USB 3.0 board featuring a male USB type-C plug soldered directly to the board I designed!

A classic problem with the TX and RX lines of UARTs & RS-232 systems is that the “TX” and “RX” nomenclature is a little bit open to interpretation — at some point the wire that is labelled “TX” because it was transmitted by one device gets a new name “RX” as we approach the device that is receiving the signal. If we’re lucky, the lines are labelled something more useful like “FromMCUToPC” or whatever.

But how are the TX+/- vs RX+/- pairs in USB 3.x connectors handled? Based on my interpretation of the USB Type-C Spec, the “naming flip” happens within the USB cable. (I haven’t check thoroughly, but it seems to be the same for Type-A and -B connectors and cables too.)

More specifically, a device transmits into the TX+/- pins (A2, A3*) of a type-C receptacle, which connects to identically named pins in the type-C plug on the cable. But within the cable, pins A2 and A3 at one end of the cable are not routed to pins A2 and A3 at the other end of the cable. Instead, pins A2 and A3 (named TX1+ and TX1-) at one end of the cable are wired through to pins B10 and B11 (named RX1+ and RX1-) at the other end of the cable.

This allows designers of USB 3.0 devices to be pretty naïve and ignore the inherent ambiguity of the “TX” and “RX” naming of the pins — it’s always named with respect to the “nearest” device (i.e., the device that isn’t at the other end of the cable.) In other words, always connect “TX” to “TX”.

That is, unless you have a male plug soldered directly to your board! That what I did, naively connecting the TX pins of a male Type-C plug to the TX pins of the device on the board. USB 2.0 was working, but USB 3.0 wasn’t. After a day of debugging, I realized this was the mistake.

It’s normally the responsibility of the cable to “switch” the TX and RX pins at either end of the cable. But more generally, it’s actually the responsibility of the male plug — whether that’s the male plug on a standard cable, or a male plug soldered directly to a circuit board. One way to figure out what to do is to fully map out how the wiring would work if you had a receptacle and a male-to-male cable — and once that is fully figured out, then carefully factor the cable and receptacle away. But if I’ve figured it out correctly, this is the (abridged) pinout you should be using in that scenario (for single-lane, e.g. USB 3.2 Gen 2x1):

  • CC (A5) — 5.1k to GND
  • “TX1+”/”TX1-” (A2, A3) — USB 3.x data entering your PCB — so should be wired to RXp/RXn on your IC. (Positive and negative can be switched if you like).
  • “RX1+”/”RX1-” (B10, B11) — USB 3.x data leaving your PCB — so should be wired to TXp/TXn on your IC. (Positive and negative can be switched if you like).
  • “D+”/”D-” (A6, A7) — USB 2.0 data, bidirectional. Wired to Dp/Dn on your IC. (Positive and negative must not be switched).

(Incidentally, it’s the responsibility of the receptacle to observe what’s going on on the CC1/CC2 pins and use a mux to “unflip” the TX1 vs TX2 lines and RX1 vs RX2 lines accordingly. One of the benefits of designing a device with a captive male cable or a male plug soldered directly to the board is that you get to control the position of the CC lines yourself, so you don’t need the muxes.)

One final trick: if you’re designing a USB hub, just do a sanity check where you see what would happen if you plugged one of your hubs into another of your hubs. If I had checked that, I would have noticed that the TX lines were plugged into the TX lines, and might have realised the conflict!

* Assuming the CC line of the cable is presented to A5.

Share

Programming TrueSTUDIO .hex files over DFU on linux

So you have an Intel HEX (.hex) file from your microcontroller firmware (from Atollic TrueSTUDIO for a STM32 micro, for example), but you need a .dfu file in order to program your microcontroller using dfu-util? And can’t (or don’t want to) use the Windows-only DfuSe software? I hope this guide helps you out!
Read the full post »

Share

Do beeswax candles produce negative ionisation? Nope.

This short note is heavily based on Are Ions Good for You, a beautiful exposition of the actual science of ionisation and pollution of the air.

There are lots of claims around the internet, mostly by beeswax candle makers, that beeswax candles are “natural ionizers”. The theory goes that beeswax candles emit “negative ionisation” which spreads through the room and causes pollutants and allergens to bind together because, apparently, those things are positively charged. No source or explanation is ever provided, and I very much believe that’s because the claim is bogus.
Read the full post »

Share

Using MOSFETs as blocking diodes

Connecting a battery backwards to an electronic circuit can rapidly do a lot of damage — current will flood through (and destroy) many integrated circuits when powered up the wrong way, and electrolytic capacitors have a famous tendency to explode. For this reason, it’s common to use a blocking diode in a circuit to provide reverse polarity protection:

highdiode

If the battery is connected correctly, as shown, current flows through the diode to the circuit, and the circuit operates normally. If the battery is reversed, the battery tries to pull current through the diode the wrong way, and the diode refuses to conduct — protecting the load from damage.

Find out the disadvantages of this circuit, and how to do better…

Share

XKCD’s ‘Click and Drag’ comic in Google Maps form

I just threw together a zoomable view of xkcd’s latest comic using the Google Maps API and US$0.27 of Google App Engine quota: Click and Drag. It helps to find some of the more off-the-beaten-track easter eggs, view it here!

If I get enough (i.e., any) interest, I will clean up the source code and make it available.

Share

Wyprowadzanie magnetyzmu z elektrostatyki i teorii względności

Wyobraź sobie świat, w którym w ogóle nie było magnetyzmu – tylko siły elektrostatyczne. Okazuje się, że dodając do tego świata prawa specjalnej teorii względności Einsteina i patrząc na wpływ, jaki szczególna teoria względności wywiera na ruchome ładunki, pojawiają się prawa magnetyzmu – po prostu łącząc ze sobą elektrostatykę i teorię względności.

Innymi słowy, poruszające się elektrony w cewkach silnika elektrycznego widzą świat z innej ramy odniesienia niż atomy miedzi tworzące uzwojenia silnika – i to właśnie brak równowagi powoduje, że silnik się obraca!

W Internecie jest wiele rzeczy, ale trudno mi to przetworzyć, ponieważ dotyczy ogólnych zależności między polami magnetycznymi i elektrycznymi, a nie konkretnych przykładów. Jestem pewien, że jest to w rzeczywistości bardzo ogólne i przydatne, ale także poza moim bezpośrednim zrozumieniem. Próbowałem więc podejść do problemu na swój własny sposób, stosując specjalną teorię względności i fizykę na poziomie szkoły średniej, i to działa!

Zobacz, jak to wszystko jest połączone…

Share

Deriving magnetism from electrostatics and relativity

Imagine a world where there was no magnetism at all — just electrostatic forces. It turns out that by adding Einstein’s laws of special relativity to that world, and looking at the effects that special relativity has on moving charges, the laws of magnetism appear — just by mashing electrostatics and relativity together.

In other words, the moving electrons in an electric motor’s coils see the world from a different frame of reference to the copper atoms making up the windings of the motor — and this imbalance is what makes the motor turn!

There’s a bunch of stuff around on the internet on this, but I find it hard to process because it deals with general relationships between magnetic and electric fields, not specific examples. I’m sure this is actually very general and useful, but it’s also beyond my immediate understanding as well. So, I tried approach the problem in my own way using just special relativity and high-school level physics, and it works!

See how it’s all connected…

Share

Automatic vs Manual transmission cars

Don’t worry, this post is not advice on how to live your life. Actually, on second thought, it is. Well, no, not really, it’s mostly about cars. And life.

Maybe I should start off with my main point:

Things which are “easy-to-use” often come with hidden drawbacks.

Some examples:

  • Point-and-shoot digital cameras (vs Digital SLR cameras) – Due to their larger sensors, SLR cameras can give much sharper images and more beautiful out-of-focus backgrounds. As well as much better performance in low-light situations, and more versatility with a variety of lenses. However, the compact size and low cost of point-and-shoot cameras make them a perfectly valid choice for casual photographers.
  • Automatics cars (vs manual cars) – Unlike point-and-shoot cameras, there is no valid reason (special circumstances aside) I can think of or find that justifies wanting a car with an automatic transmission – if you’re blessed with two legs.

At this point, I’m going to drop the illusion of making a general argument about “easy things” and just rant about automatic cars instead.

What’s the actual difference between auto and manual?

Find out…

Share

Where’s the North Pole on Google Maps?

I’ve seen several posts on the internet asking about the North Pole on Google Maps: where is it? Why isn’t there any snow there? Where’s Santa’s house?

There’s a couple of reasons why the ice around the North Pole is not shown on Google Maps.

Find out why…

Share

The Galaxy Nexus PenTile display: comparing apples and oranges

There has been a lot of discussion on the ‘net about the infamous PenTile display. Lots of sites are throwing numbers around, comparing the ‘subpixel resolution’ of competing phones such as the Galaxy Nexus and iPhone 4/4S. Some commentary has been insane, comparing apples with oranges and declaring PenTile an abomination regardless of resolution. Others, like this one, are a lot more reasoned, but still seem to ignore the well-proven fact that the eye’s visual acuity depends on the colour in question. Let’s rattle off a couple of undeniably true facts:

  1. Hypothetical 1000ppi RGB and PenTile displays can both look absolutely sharp and perfect.
  2. The acuity of the human eye varies significantly between colours. Acuity is particularly poor with blue light.

Take the following example: these four squares consist of fine lines. From left-to-right, they are: #1: white/black, #2: red/cyan, #3: green/magenta, and #4: blue/yellow.

Stand well back from your monitor, until you can’t tell the lines apart. Now slowly move back in. Notice how the blue/yellow (#4) lines look almost the same as white/black (#1), and red/cyan (#2) look very similar to green/magenta (#3)? Very roughly speaking, this is because our eyes smear out blue light slightly, so we can’t tell the difference between white lines (yellow+blue), or alternating yellow and blue lines. Similarly, the only difference between red/cyan and green/magenta is where the blue lies.

I started this not-terribly-scientific experiment with the “hypothesis” that the eye had a higher acuity to green than red and blue. This is apparently the reason that is used to justify PenTile’s use of twice as many green subpixels as red or blue. However, although my pictures above suggest that green is more visible than blue, my eyes are more-or-less equally acute with respect to red and green light. This is backed up by at least one actual proper study, as well. [Interestingly, the original PenTile technology was RRGGB, which makes much more sense!]

So, we can conclude that the resolution of red subpixels might be the limiting factor for an RGGB “Retina” PenTile display, whereas the resolution of green subpixels might be the limiting factor for an RGB Retina iPhone 4 display. Comparing the two of these numerically is very difficult and highly subjective. The sharpness with which the eye can see these colours is different, and even this difference varies according to the brightness of the image, and the individual. To see numbers calculated with no apparent regard to these factors and presented to five significant figures is just laughable.

The closest you can come to a meaningful comparison is stating what sort of displays would be equivalent if green sub-pixel resolution was all that mattered, and what would be equivalent if red/blue sub-pixel resolution was all that mattered. The linear green sub-pixel resolution is the same for both RGB and PenTile displays, because both feature full green sub-pixels. The linear red/blue sub-pixel resolution of PenTile is compromised by a factor of sqrt(2), because red pixels are diagonally separated. So, here we go:

The effective equivalent RGB resolution of a 1280×720 PenTile display probably lies somewhere between 905×509 (if red/blue is the limiting factor by far) and 1280×720 (if green is limiting factor by far.) That is, somewhere between the-highest-resolution-ever-seen-on-a-smartphone (except the iPhone 4S by a hair) and the-highest-resolution-ever-seen-on-a-smartphone (by a mile, although some [dirty LCD] RGB 720p devices have been launched since.)

And we’ve come all this way without mentioning display size. The bigger the display, the bigger the font can be and the further you can comfortably hold the device from your eyes. A bigger display should therefore mean a lower linear resolution limit before the display be reasonably considered a ‘Retina’ display.

The proof of the pudding is in the eating

My conclusion? It is virtually impossible to pre-judge a display that we haven’t even seen before. I would love to hear subjective comments from people who have seen the device in person; otherwise, I’m not interested.

Continue reading, including simulated images from a 720p PenTile display…

Share