ESP8266 and PL2303HX-gpio adventures.

As you might have seen, I’ve made a few projects with PL2303HX, namely that little nifty esp8266 developer board. I plan to dive in esp8266 firmware development soon and my goal will be a nifty mysql client, so that I can run mysql queries via UART! The only bad thing (apart from eeprom never working, and occasional freezes that I’ve later fixed with a 10uF SMD capacitor) – I had to press the buttons to reset the ESP8266 module to bootloader mode. So I’ve made a ‘dark green evil sister’ twin of that red board with a little bit updated schematics:

  • GP0 and GP1 lines are now rigged to reset and bootloader buttons respectively, resistors protect those against logic level conflict.
  • I’ve ditched EEPROM. It doesn’t work anyway. Screw that!
  • Proper decoupling – no more freezes!
  • SMD LEDs on GP0 and GP1.
  • Nice dark greenish design and clear urethane coating FTW!

IMG_2486

IMG_2489

I did’t use RTS/DTR pins for that. Mostly because guys haven’t yet decided how to rig them in esptool and I wanted to make use of PL2303HXA GPIOs anyways for some other projects. They’re often quite handy. However, there’s no driver for those in linux. A few patches are in the upstream, but none have been merged so far. So I’ve settled for a userspace solution with libusb. Luckily for us, sending a few control transfers to PL2303 doesn’t screw up the kernel driver. You can grab the result of my work at github.

The resulting tool is really simple to embed in any of you scripts and is less than 500 lines of C code with little to no dependencies.

1 ✗ necromant @ sylwer ~/Dev/software/pl2303ctl $ pl2303gpio --help
PL2303HXA userspace GPIO control tool
(c) Andrew 'Necromant' Andrianov 2014, License: GPLv3
Usage: pl2303gpio [action1] [action2] ...
Options are: 
         -g/--gpio  n  - select GPIO, n=0, 1
         -i/--in       - configure GPIO as input
         -o/--out v    - configure GPIO as output with value v
         -r/--read v   - Read current GPIO value

Examples: 
        pl2303gpio --gpio=1 --out 1
        pl2303gpio --gpio=0 --out 0 --gpio=1 --in

For a quick hardware summary – turned out PL2303HX was more treacherous one may think at first. Here’s a quick summary of PL2303HXA pitfalls I came across and that wasted a good deal of my time:

  • Internal lowdropout regulator output should be decoupled with no less than 10uF. Otherwise – device freezes randomly. Even if you to not use this 3.3 volts source for anything – it is used internally by the chip and needs decoupling.
  • Despite the PL2303HXA datasheet stands that it will work at 1.8V – it will not. I was making a serial dongle for my odroid-x2 that uses 1.8v signalling and I cursed every single bit of that PL2303HXA. The TX will work, RX will not. Datasheet lies!
  • External EEPROM config never worked with at24c64. Period. They don’t even tell us the i2c slave address. Not a big loss anyway – newer revisions have OTP ROM.

12 thoughts on “ESP8266 and PL2303HX-gpio adventures.

    1. Hi, Juergen.
      I’ve seen your work. You basically use DTR and RTS pins, while I use GP0 and GP1 for that on pl2303 and an external tool. The buttons are there for times when you have to reboot to windoze and use stock software for debugging purposes.

    1. No problem. DTR and RTS are more clean and portable way of resetting things indeed, but they might be messy since minicom and other terminals tend to toggle these on open and close of the port, and they have no Z state. GP0/GP1 keep their setting until reconfigured/replugged and no app touches them. You can use CBUS on FTDI for that.

      Btw, in your schematic I suggest putting at least 470 Ohm resistors on DTR/DSR. In case of logic conflict you’ll have 15mA flowing, that’s not great for ft232. I’d settle on something no more than 1-2mA in case of a logic conflict.

  1. There is also a kernel patch for PL2303HXA/D GPIOs support in sysfs:

    http://www.zoobab.com/pl2303hxd-gpio

    There is an undocumented mode on the PL2303 where you could use RI, DCD, DSR and CTS as GPIO pins:

    https://play.google.com/store/apps/details?id=tw.com.prolific.pl2303hxdgpio
    https://lh4.ggpht.com/kM6hPQ1n1YEdJGQ2do74JsgWcIuhLruYmYIBSD7kTjnK27NsgMYYHFFhGQrGHPJSYPY=h900-rw

    I still have to find the time to reverse engineer the android app, but if you have more time…

  2. If the RI, DCD, DSR and CTS could be used as GPIOs, that would be great if you could expose those pins as well on your connector.

    I am still hunting for a decent PL2303 breakout board.

    1. You can just make your own with press’n’peel. Schematics are really simple. Just don’t forget to decouple VDD_3v3 with 10uF, or shit will happen.
      Those you see above are purely homebrew modules (they’re not from factory, took ~40 minutes to make each one). I doubt I will be making any further revisions of them since they work.

      And for other pins – I guess firing up usbmon module on an android tablet would give you all the things you need. If they haven’t published the sources.

  3. Necromant,
    great work!

    I am having consistency issues programming the ESP8266, are you sharing your schematics?
    i’d love to home-brew a board like that.

    Thanks

  4. Ive tried for years to get my esp8266 1’s working what a pain in the butt. I tried several times for hours at a time until I had to admit they must be broken or I simply did not have the aptitude to complete the task. I hope they were broken. Either way Im sad because I never could do it….

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.