Difference between revisions of "PineNote Development/UART"

From PINE64
Jump to navigation Jump to search
(→‎Creating a dongle: Added note about 3.3V UART)
(Began documenting process of splicing resistors into wires)
Line 3: Line 3:
This page contains information on creating and using a [https://en.wikipedia.org/wiki/Universal_asynchronous_receiver-transmitter UART] dongle for the [[PineNote]].
This page contains information on creating and using a [https://en.wikipedia.org/wiki/Universal_asynchronous_receiver-transmitter UART] dongle for the [[PineNote]].
The PineNote was shipped with a compatible UART dongle, but replacements are not available to order in case of loss or hardware fault.
The PineNote was shipped with a compatible UART dongle, but replacements are not available to order in case of loss or hardware fault.
Thankfully it is not difficult to make your own from easily-acquired components.
Thankfully it is not difficult to make your own from easily-acquired components and a small bit of soldering.
Fear not if you've never soldered anything before!
This serves as an excellent first soldering project.
Borrow the tools from a friend or a local hackerspace or tool library.


A PineNote UART dongle enables you to:
A PineNote UART dongle enables you to:
Line 30: Line 33:
== Creating a dongle ==
== Creating a dongle ==


A PineNote UART dongle has four components:
A PineNote UART dongle has the following components:
# A USB-C breakout board with a male connector exposing the 24 pins of the PineNote's female USB-C port (located on the bottom of the device)
# A USB-C breakout board with a male connector exposing the 24 pins of the PineNote's USB-C port
# A USB-UART adapter, to plug into a USB port of the computer you'll use to interface with the PineNote
# A USB-UART adapter, to plug into a USB port of the computer you'll use to interface with the PineNote
# [https://en.wikipedia.org/wiki/Jump_wire Jump wires] to connect specific breakout board pins to pins on the USB-UART adapter
# [https://en.wikipedia.org/wiki/Jump_wire Jump wires] to connect specific breakout board pins to pins on the USB-UART adapter
# Electrical tape to wrap connectors and prevent shorts
# Two 1,000 Ohm resistors to splice into the jump wires
# Electrical tape or heat shrink to wrap connectors and prevent shorts


The PineNote's internal UART system is documented in [https://files.pine64.org/doc/PineNote/PineNote_USB-C_Console_UART_breakout_board_schematic_v1.0_20210903.pdf this schematic].
The PineNote's internal UART system is documented in [https://files.pine64.org/doc/PineNote/PineNote_USB-C_Console_UART_breakout_board_schematic_v1.0_20210903.pdf this schematic].
USB-C pins are documented [https://en.wikipedia.org/wiki/USB-C#Specifications on the USB-C Wikipedia page]; of the 24 pins, two are designated for "side band" use.
The purpose of all 24 USB-C pins is documented [https://en.wikipedia.org/wiki/USB-C#Receptacles on the USB-C Wikipedia page].
These pins are labeled SBU1 (A8) and SBU2 (B8).
We are interested in three sets of pins:
In the PineNote UART schematic you can see (on the bottom right diagram) these pins are given the label <code>UART2_TX_SUB1</code> and <code>UART2_RX_SUB2</code> respectively.
# The SBU1 (A8) and SBU2 (B8) side band use pins
The first (TX) is used for transmitting data and the second (RX) is used for receiving data.
# The CC1 (A5) and CC2 (B5) configuration channel pins
These are the pins which must be exposed by the breakout board.
# The GND [https://en.wikipedia.org/wiki/Ground_(electricity) ground return] pins (A1, A12, B1, and B12)
 
In the PineNote UART schematic you can see (on the bottom right diagram labeled <code>USB_TYPEC_Male</code>) the side band pins are given the labels <code>UART2_TX_SUB1</code> for A8 and <code>UART2_RX_SUB2</code> for B8.
The first (TX) is used for transmitting data and the second (RX) is used for receiving data, from the perspective of the PineNote.
Note also the configuration channel pins labeled <code>TYPEC_CC1</code> for A5 and <code>TYPECC_CC2</code> for B5.
These pins are used to signal to the PineNote that a UART dongle is present.
The diagram shows they must be connected to a 3.3V source, mediated by resistors.
 
=== Buying components ===


There are many possible USB-C breakout board designs available for purchase online.
There are many possible USB-C breakout board designs available for purchase online.
Line 47: Line 59:
This design is more versatile in case you want to reuse it in other projects, and also enables you to connect to the PineNote via UART and USB at the same time.
This design is more versatile in case you want to reuse it in other projects, and also enables you to connect to the PineNote via UART and USB at the same time.
An example of this product can be found [https://pmdway.com/products/usb-3-1-type-c-male-to-female-breakout-test-board here], although you are encouraged to shop around for cheaper options.
An example of this product can be found [https://pmdway.com/products/usb-3-1-type-c-male-to-female-breakout-test-board here], although you are encouraged to shop around for cheaper options.
If you're fine with a bit more soldering, there is a very cheap one [https://www.ebay.com/itm/275407037613 here].


Similarly, there are many USB-UART adapter designs available.
Similarly, there are many USB-UART adapter designs available.
Line 52: Line 65:
It is important to get a 3.3V model, or at least a model with the option of 3.3V, as a 5V model might fry the PineNote.
It is important to get a 3.3V model, or at least a model with the option of 3.3V, as a 5V model might fry the PineNote.
[https://pmdway.com/products/usb-to-ttl-serial-cp2104-6-pin-converter-module Here] is one example with jump wires included, although you are again encouraged to shop around for alternatives.
[https://pmdway.com/products/usb-to-ttl-serial-cp2104-6-pin-converter-module Here] is one example with jump wires included, although you are again encouraged to shop around for alternatives.
=== Splicing resistors ===
This is the only difficult part of the whole process.
You will need to splice 1k Ohm resistors into the jump wires you connect to the configuration channel pins.
For this you'll need:
# A soldering iron with solder
# Wire cutters & strippers
# 2 female-ended
TBD
=== Assembly ===


Once you have acquired all necessary components, assemble the UART dongle as follows:
Once you have acquired all necessary components, assemble the UART dongle as follows:
# Connect a jump wire from the GND ([https://en.wikipedia.org/wiki/Ground_(electricity) ground]) pin on the USB-UART adapter to any one of the four GND pins on the USB-C breakout board (A1, A12, B1, or B12)
# Connect a jump wire from the GND pin on the USB-UART adapter to any one of the four GND pins on the USB-C breakout board (A1, A12, B1, or B12)
# Connect a jump wire from the RXD pin on the USB-UART adapter to the <code>UART2_TX_SUB2</code> pin on the USB-C breakout board (SBU1 aka A8)
# Connect a jump wire from the RXD pin on the USB-UART adapter to the <code>UART2_TX_SUB2</code> pin on the USB-C breakout board (SBU1 aka A8)
# Connect a jump wire from the TXD pin on the USB-UART adapter to the <code>UART2_RX_SUB2</code> pin on the USB-C breakout board (SBU2 aka B8)
# Connect a jump wire from the TXD pin on the USB-UART adapter to the <code>UART2_RX_SUB2</code> pin on the USB-C breakout board (SBU2 aka B8)

Revision as of 21:47, 13 October 2023

Basic non-stock PineNote UART dongle

This page contains information on creating and using a UART dongle for the PineNote. The PineNote was shipped with a compatible UART dongle, but replacements are not available to order in case of loss or hardware fault. Thankfully it is not difficult to make your own from easily-acquired components and a small bit of soldering. Fear not if you've never soldered anything before! This serves as an excellent first soldering project. Borrow the tools from a friend or a local hackerspace or tool library.

A PineNote UART dongle enables you to:

  1. Interact with the system boot menu
  2. Read system events in real time as the PineNote is used
  3. Fix the PineNote without opening the case if something goes wrong while flashing it

Since the PineNote is an embedded system, interfacing with it during boot is more complicated than with an ordinary computer. The UART dongle enables you to do this.

The PineNote factory firmware runs UART at a baud rate of 1500000 bps, 8 data bits, 1 stop bit, no parity and no flow control. The process by which the PineNote design was modified to include closed-case UART is documented here.

Stock dongle

The stock UART dongle included with the PineNote was a simple device plugging directly into the PineNote's USB-C port. The dongle exposed a female USB-C port, which the user plugged into to get UART access. This design unfortunately ruled out passthrough USB connections, where the user connects to the PineNote via UART and USB simultaneously. The dongle is not currently available for purchase.

Creating a dongle

A PineNote UART dongle has the following components:

  1. A USB-C breakout board with a male connector exposing the 24 pins of the PineNote's USB-C port
  2. A USB-UART adapter, to plug into a USB port of the computer you'll use to interface with the PineNote
  3. Jump wires to connect specific breakout board pins to pins on the USB-UART adapter
  4. Two 1,000 Ohm resistors to splice into the jump wires
  5. Electrical tape or heat shrink to wrap connectors and prevent shorts

The PineNote's internal UART system is documented in this schematic. The purpose of all 24 USB-C pins is documented on the USB-C Wikipedia page. We are interested in three sets of pins:

  1. The SBU1 (A8) and SBU2 (B8) side band use pins
  2. The CC1 (A5) and CC2 (B5) configuration channel pins
  3. The GND ground return pins (A1, A12, B1, and B12)

In the PineNote UART schematic you can see (on the bottom right diagram labeled USB_TYPEC_Male) the side band pins are given the labels UART2_TX_SUB1 for A8 and UART2_RX_SUB2 for B8. The first (TX) is used for transmitting data and the second (RX) is used for receiving data, from the perspective of the PineNote. Note also the configuration channel pins labeled TYPEC_CC1 for A5 and TYPECC_CC2 for B5. These pins are used to signal to the PineNote that a UART dongle is present. The diagram shows they must be connected to a 3.3V source, mediated by resistors.

Buying components

There are many possible USB-C breakout board designs available for purchase online. One particularly useful design is a "passthrough" or "intercept" style, with both male and female USB-C ports. This design is more versatile in case you want to reuse it in other projects, and also enables you to connect to the PineNote via UART and USB at the same time. An example of this product can be found here, although you are encouraged to shop around for cheaper options. If you're fine with a bit more soldering, there is a very cheap one here.

Similarly, there are many USB-UART adapter designs available. These devices plug into your computer and expose a number of pins themselves, connecting to specific pins on the breakout board with jump wires. It is important to get a 3.3V model, or at least a model with the option of 3.3V, as a 5V model might fry the PineNote. Here is one example with jump wires included, although you are again encouraged to shop around for alternatives.

Splicing resistors

This is the only difficult part of the whole process. You will need to splice 1k Ohm resistors into the jump wires you connect to the configuration channel pins. For this you'll need:

  1. A soldering iron with solder
  2. Wire cutters & strippers
  3. 2 female-ended

TBD

Assembly

Once you have acquired all necessary components, assemble the UART dongle as follows:

  1. Connect a jump wire from the GND pin on the USB-UART adapter to any one of the four GND pins on the USB-C breakout board (A1, A12, B1, or B12)
  2. Connect a jump wire from the RXD pin on the USB-UART adapter to the UART2_TX_SUB2 pin on the USB-C breakout board (SBU1 aka A8)
  3. Connect a jump wire from the TXD pin on the USB-UART adapter to the UART2_RX_SUB2 pin on the USB-C breakout board (SBU2 aka B8)

Note that if you mix up the TX/RX pins, it will still work but the USB-C breakout board will just plug into the PineNote upside down. You can therefore choose which orientation you want by swapping the TX/RX pin connections.

Test that your system works by following the use instructions down below. Be very careful not to touch or short the pins while current is flowing through them - this can damage your device! Once you have confirmed that your UART dongle works, wrap all metal connectors in electrical tape to prevent accidental shorts.

Using UART

First, use your UART dongle to physically connect your PineNote to your computer:

  1. Plug the USB-UART adapter into one of your computer's USB ports
  2. Plug the USB-C breakout board into the USB-C port on the bottom of your PineNote; the orientation matters, so try both and remember which one works

Once the hardware is connected, set up your computer's software as follows:

  1. Install GNU Screen (or some other option, but the instructions below are written for screen)
  2. Identify the USB-UART adapter in your /dev directory by running ls /dev with it plugged in, unplugging it, then again running ls /dev and seeing what changes; it is likely to be called /dev/ttyUSB0
  3. In a terminal window, run screen -L /dev/ttyUSB0 1500000 (you may need to run this as sudo depending on your user's permissions; on most Linux distributions you need to be in the dialout usergroup)

Once the software is set up, power-cycle your PineNote; as the system boots you should see text appearing in your terminal window. You can exit the screen session with ctrl+a k then pressing y to confirm. The screen -L flag outputs a text log of the session to the current working directory, probably called screenlog.0.

Troubleshooting

If you don't see any text in your terminal as the PineNote boots, or the text is garbled, try the following:

  • Ensure your GND, RX and TX jump wires are connected to the correct pins on both the USB-UART adapter and the USB-C breakout board
  • Connect your USB-C breakout board to your PineNote in the opposite orientation
  • Run the screen command as sudo in case your user doesn't have appropriate permissions
  • Ensure you are setting the baud rate in the screen command to 1500000 (1.5 million)

USB passthrough

If your USB-C breakout board has a passthrough/intercept design, you can connect to your PineNote over USB and UART at the same time. This can be useful when you're doing development work on the PineNote boot process so you don't have to continually reconnect cables. You'll need a USB-A to USB-C cable, connecting directly from your computer's USB-A hub to your USB-C breakout board's female USB-C port. It's important to connect directly from USB-A, without any intermediate USB-C components. Note that connecting a live USB cable to your USB-C breakout board in this way dramatically increases the danger of frying your PineNote with a short, so you should only do this if all connectors are safely wrapped in electrical tape.