Skip to content

Instantly share code, notes, and snippets.

@tommie
Last active December 6, 2023 06:08
Show Gist options
  • Save tommie/89011c5ac06553d5cdb8 to your computer and use it in GitHub Desktop.
Save tommie/89011c5ac06553d5cdb8 to your computer and use it in GitHub Desktop.
PL2303 USB Protocol

A description of the PL2303HX USB protocol.

Control Transfers

Read Register

Read a device register value.

  • bmRequestType: IN, VENDOR, DEVICE
  • bRequest: 1
  • wValue: 80h | registerNumber
  • wLength: 1

Write Register

Write a device register value.

  • bmRequestType: OUT, VENDOR, DEVICE
  • bRequest: 1
  • wValue: registerNumber
  • wIndex: registerValue

Registers

Register 0 (Command/Flow Control)

Sets flow control mode.

  • 00h OFF
  • 01h RFRCTS
  • 08h DTRDSR
  • 31h Unknown
  • 41h RTSCTS
  • C0h XONXOFF

Register 1 (Status/GPIO 0)

Gets/sets GPIO.

  • 08h Unknown
  • 10h GP0 enable
  • 20h GP1 enable
  • 40h GP0 value
  • 80h GP1 value

Register 2

Unknown. Initialized to 44h.

Register 3 (Extended register data)

Read/write while register 4 has an interesting address.

Register 4 (Extended register address)

Set to address to read/write extended registers.

Register 6 (GPIO Enable 2)

Enables/disables GPIO. May not be readable.

  • 03h GP4/RI
  • 0Ch GP5/DCD
  • 30h GP6/DSR
  • C0h GP7/CTS

Register 7 (GPIO Value 2)

Gets/sets GPIO values.

  • 01h GP4/RI
  • 02h GP5/DCD
  • 04h GP6/DSR
  • 08h GP7/CTS

Register 12 (GPIO Enable 1)

Enables/disables GPIO.

  • 03h GP2
  • 0Ch GP3

Register 13 (GPIO Value 1)

Gets/sets GPIO values.

  • 01h GP2
  • 02h GP3

Extended registers 0:1

Device type. The value 123:6 is special.

Extended registers 250:251

Device type. The values 1:3 and 1:4 are special.

Initialization

chipType = 0

if vendor:product != 067B:2303:
  chipType = 4
  writeRegister(0x00, 0x01)
  writeRegister(0x01, 0x00)
  writeRegister(0x02, 0x44)
  for reg in range(0x00, 0x03):
    readRegister(reg)
else:
  readRegister(0x04)
  writeRegister(0x04, 0x00)
  readRegister(0x04)
  v1 = readRegister(0x03)
  readRegister(0x04)
  writeRegister(0x04, 0x01)
  readRegister(0x04)
  v2 = readRegister(0x03)

  if v1:v2 != 123:6:
    writeRegister(0x00, 0x01)
    writeRegister(0x01, 0x00)
    writeRegister(0x02, 0x44)
    for reg in range(0x00, 0x03):
      readRegister(reg)

  if bcdDevice >> 8 == 4:
    chipType = 4

  saved = readRegister(0x01)
  writeRegister(0x01, 0xFF)

  if readRegister(0x01) & 0x0F == 0x0F:
    chipType = 4
    readRegister(0x04)
    writeRegister(0x04, 0xFA)
    readRegister(0x04)
    v1 = readRegister(0x03)
    readRegister(0x04)
    writeRegister(0x04, 0xFB)
    readRegister(0x04)
    v1 = readRegister(0x03)
    if v1:v2 == 1:4 or v1:v2 == 1:3:
      chipType = 2
  else:
    chipType = 2

  writeRegister(0x01, saved)

  if v1:v2 == 123:6:
    if readRegister(0x01) & 0x08 == 0x08:
      writeRegister(0x00, 0x31)
      writeRegister(0x01, 0x08)

if chipType == 4:
  for reg in range(0x00, 0x03):
    readRegister(reg)

  cdcSetLineCoding(...)
  setFlowControl(...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment