There is an UART on the Nexus 4!

I recently started hacking on bringing Mer and possibly Nemo to the Nexus 4 (aka Mako).
I chose the Nexus 4 as these devices are traditionally very open, as you can see in case of the Nexus 4 e.g. by the availability of Ubuntu Touch images. I didn’t expect however for it to be that hackable as I was about to find out on Saturday.

I had just completed packaging the Mako kernel on Mer OBS in my home project and the package is now available (it however doesn’t boot properly yet). So the memories from me hacking on the Archos 5 IT with the openAOS project came back and I thought, wouldn’t it be nice to have an UART available for debugging…

A few queries to the Internet search engine of my least distrust later I had a first lead in the form of an XDA post. This however didn’t help me much yet, which logic levels? which pins? really the headphone socket? I quickly checked and didn’t notice anything coming out of the port when piping out /dev/urandom to /dev/ttyHSL0.

Then I was lucky and found a more detailed description on another page (sadly the link got lost) and based on that drew a circuit schematic:

UART switch circuit

UART switch circuit to enable UART on 3.5mm headphone jack.

The circuit is basically a simple comparator with a reference Voltage of 2.8V. If the input voltage on the other pin exceeds this, then it switches its output to VCC (logic 1/true). This apparently triggers a switch that turns off audio and puts a UART on R/RX, L/TX. As I later found out by trying it out, the polarity is actually so, that you need to apply -2.9V.(seems I was wrong?)

Here’s my test setup. I borrowed a scope and bench power supply to do this properly.

test setup audio

Test setup for measuring audio output

I had VLC running with a file of a 1kHz sine wave.

oscilloscope audio

oscilloscope showing a sine on both left and right channel

This is actually interesting. It looks suspiciously as if one of the channels is quite noisy? Anyone who can comment on this?

I then proceeded to attach the bench power supply to the MIC and GND pins. (Set at 2.9V and lowest possible current limit of about 10mA). Note that it’s connected so, that GND→+ and MIC→-, so -2,9V.

test setup UART

test setup for measuring UART output

I then opened a terminal and ran this to get a continuous output:

cat /dev/zero >/dev/ttyHSL0
oscilloscope UART

oscilloscope showing UART output

So, there you go, a nice and clean output. The RX port seems to suffer a bit from crosstalk though… (but note the different V/div settings! for both channels!)


The oscilloscope used for this.

Here you can see, that the signal is about 3V peak/peak, so I’d guess 3.3V reference should work for the serial converter. 1.8V might work too though.

I’d recommend to use a resistor in line with the 2.9V to further protect the circuit. (wasn’t shown in the pictures).

Sadly I then connected some cables wrongly during my further experiments and it seems like I have now fried the switch. Audio out works fine, I just can’t seem to be able to enable the UART anymore. I’m a sad panda, but at least now others can benefit from this.

Update: I received some additional information. Seems it should be +3V on the MIC in after all. And this seems to also apply to other models. Anyone want to try on e.g. some of the other Nexus devices? If someone wants to build a cable, here are some examples: 3.5mm 4pin and 3.3V USB to Serial cable based on a  FTDI chip

6 thoughts on “There is an UART on the Nexus 4!

    1. Thomas B. Rücker Post author

      Sure, that would work.
      I’d recommend to use a voltage divider to drop the 3.3V to something like 2.9V though for the enable pin.

      1. YL

        Thanks a lot.. I already read it somewhere , this also works. so, what’s the difference between pl2303hx and ft232rl? Are they just a FTDI model number? And, is it any USB-to-serial (TTL) converter should work with this project? But, just make to drop that 3.3V to something like 2.9V.. I am pretty new to this kinda of stuff… Thanks a lot!!

        1. Thomas B. Rücker Post author

          There is no difference between using a FTDI or PL2303 chip-set in this case.
          Just make sure, that the reference voltage for the RX/TX lines is either 1.8V or 3.3V (ideally it would be 3V).
          The mic line needs that fixed voltage of around 2.9-3V.