Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CH343 USB to serial adapter #1640

Merged
merged 2 commits into from
Jan 28, 2024
Merged

Add CH343 USB to serial adapter #1640

merged 2 commits into from
Jan 28, 2024

Conversation

MCUdude
Copy link
Collaborator

@MCUdude MCUdude commented Jan 26, 2024

The CH343 is WCH's latest generation of USB to serial chips and should work with "standard" USB drivers.

Chip details:
#1639 (reply in thread)
https://www.cnx-software.com/2022/04/19/wch-ch343-usb-to-serial-chips-support-1-8v-to-5v-io-voltage-6-mbps-baud-rate-custom-vid-pi
https://www.lcsc.com/search?q=ch343

Can you give this a try @cederom. You need to build with libserialport installed, and test with -P ch343.

@cederom
Copy link
Contributor

cederom commented Jan 26, 2024

Hmm I also have created the configuration in the meantime:

#------------------------------------------------------------
 # ch343
 #------------------------------------------------------------
 # CH343G chip https://www.wch-ic.com/downloads/CH343DS1_PDF.html

serialadapter # ch343
    id                     = "ch343";
    desc                   = "WCH CH343 USB to serial adapter";
    usbvid                 = 0x1a86;
    usbpid                 = 0x55d3;
;

Updated the avrdude.conf in the build directory and it fails to find the programmer. Any hints welcome :-)

% uname -a
FreeBSD XXX 13.2-RELEASE-p8 FreeBSD 13.2-RELEASE-p8 GENERIC amd64

% usbconfig -d 0.7 dump_device_desc
ugen0.7: <vendor 0x1a86 USB Single Serial> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (134mA)

  bLength = 0x0012
  bDescriptorType = 0x0001
  bcdUSB = 0x0110
  bDeviceClass = 0x0002  <Communication device>
  bDeviceSubClass = 0x0000
  bDeviceProtocol = 0x0000
  bMaxPacketSize0 = 0x0008
  idVendor = 0x1a86
  idProduct = 0x55d3
  bcdDevice = 0x0443
  iManufacturer = 0x0000  <no string>
  iProduct = 0x0002  <USB Single Serial>
  iSerialNumber = 0x0003  <5434023603>
  bNumConfigurations = 0x0001

% ./avrdude -c ch343
avrdude error: cannot find programmer id ch343
similar programmer name:
  ch341a = ch341a programmer (AVR must have minimum F_CPU of 6.8 MHz)
use -c? to see all possible programmers

% ./avrdude -c ch343:5434023603
avrdude error: cannot find programmer id ch343:5434023603
use -c? to see all possible programmers

% ./avrdude "-c?"

Valid programmers are:
  2232hio            = 2232hio based on FT2232H with buffer and LEDs
  4232h              = FT4232H based generic programmer
  adafruit_gemma     = Adafruit Trinket Gemma bootloader disguised as USBtiny
  arduino            = Arduino for bootloader using STK500 v1 protocol
  arduino-ft232r     = Arduino: FT232R connected to ISP
  diecimila          = Arduino: FT232R connected to ISP
  arduino_as_isp     = Arduino board as programmer using arduino as ISP firmware
  arduino_gemma      = Arduino Gemma bootloader disguised as USBtiny
  arduinoisp         = Arduino ISP Programmer
  arduinoisporg      = Arduino ISP Programmer
  atmelice           = Atmel-ICE (ARM/AVR) in JTAG mode
  atmelice_jtag      = Atmel-ICE (ARM/AVR) in JTAG mode
  atmelice_dw        = Atmel-ICE (ARM/AVR) in debugWIRE mode
  atmelice_isp       = Atmel-ICE (ARM/AVR) in ISP mode
  atmelice_pdi       = Atmel-ICE (ARM/AVR) in PDI mode
  atmelice_tpi       = Atmel-ICE (ARM/AVR) in TPI mode
  atmelice_updi      = Atmel-ICE (ARM/AVR) in UPDI mode
  avr109             = Atmel for bootloader using AppNote AVR109
  avr910             = Atmel Low Cost Serial Programmer
  avr911             = Atmel for bootloader using AppNote AVR911 AVROSP
  avrftdi            = FT2232H/D based generic programmer
  2232h              = FT2232H/D based generic programmer
  avrisp             = Atmel AVR ISP
  avrisp-u           = Kanda AVRISP-U
  avrispmkII         = Atmel AVR ISP mkII
  avrisp2            = Atmel AVR ISP mkII
  avrispv2           = Atmel AVR ISP v2
  buspirate          = The Bus Pirate
  buspirate_bb       = The Bus Pirate (bitbang interface, supports TPI)
  butterfly          = Atmel for bootloader (Butterfly Development Board)
  butterfly_mk       = Mikrokopter.de Butterfly for bootloader
  mkbutterfly        = Mikrokopter.de Butterfly for bootloader
  bwmega             = BitWizard ftdi_atmega builtin programmer
  c232hm             = C232HM cable from FTDI
  c2n232i            = serial port banging, reset=dtr sck=!rts sdo=!txd sdi=!cts
  ch341a             = ch341a programmer (AVR must have minimum F_CPU of 6.8 MHz)
  dasa               = serial port banging, reset=rts sck=dtr sdo=txd sdi=cts
  dasa3              = serial port banging, reset=!dtr sck=rts sdo=txd sdi=cts
  digilent-hs2       = Digilent JTAG HS2 (MPSSE)
  dragon_dw          = Atmel AVR Dragon in debugWire mode
  dragon_hvsp        = Atmel AVR Dragon in HVSP mode
  dragon_isp         = Atmel AVR Dragon in ISP mode
  dragon_jtag        = Atmel AVR Dragon in JTAG mode
  dragon_pdi         = Atmel AVR Dragon in PDI mode
  dragon_pp          = Atmel AVR Dragon in PP mode
  dryrun             = Emulates programming without a programmer
  ehajo-isp          = AVR ISP programmer from eHaJo.de
  flip1              = FLIP for bootloader using USB DFU protocol version 1 (doc7618)
  flip2              = FLIP for bootloader using USB DFU protocol version 2 (AVR4023)
  flyswatter2        = TinCan Tools Flyswatter 2
  ft2232h            = FT2232H/D based generic programmer
  ft2232h_jtag       = FT2232H based generic JTAG programmer
  ft232h             = FT232H based generic programmer
  ft232h_jtag        = FT232H based generic JTAG programmer
  ft232r             = FT232R based generic programmer
  ft245r             = FT245R based generic programmer
  ft4232h            = FT4232H based generic programmer
  iseavrprog         = AVR ISP programmer from iascaled.com
  jtag1slow          = Atmel JTAG ICE (mkI)
  jtag2dw            = Atmel JTAG ICE mkII in debugWire mode
  jtag2fast          = Atmel JTAG ICE mkII
  jtag2              = Atmel JTAG ICE mkII
  jtag2isp           = Atmel JTAG ICE mkII in ISP mode
  jtag2pdi           = Atmel JTAG ICE mkII in PDI mode
  jtag2slow          = Atmel JTAG ICE mkII
  jtag2updi          = JTAGv2 to UPDI bridge
  jtag3              = Atmel AVR JTAGICE3 in JTAG mode
  jtag3dw            = Atmel AVR JTAGICE3 in debugWIRE mode
  jtag3isp           = Atmel AVR JTAGICE3 in ISP mode
  jtag3pdi           = Atmel AVR JTAGICE3 in PDI mode
  jtag3updi          = Atmel AVR JTAGICE3 in UPDI mode
  jtagkey            = Amontec JTAGKey, JTAGKey-Tiny and JTAGKey2
  jtagmkI            = Atmel JTAG ICE (mkI)
  jtag1              = Atmel JTAG ICE (mkI)
  jtagmkII           = Atmel JTAG ICE mkII
  jtagmkII_avr32     = Atmel JTAG ICE mkII in AVR32 mode
  jtag2avr32         = Atmel JTAG ICE mkII in AVR32 mode
  lm3s811            = Luminary Micro LM3S811 Eval Board (Rev. A)
  mib510             = Crossbow MIB510 programming board
  micronucleus       = Micronucleus for bootloader
  nibobee            = NIBObee
  o-link             = O-Link, OpenJTAG ARM JTAG USB
  openmoko           = Openmoko debug board (v3)
  pavr               = Jason Kyle's pAVR Serial Programmer
  pickit2            = Microchip PICkit 2 programmer in ISP mode
  pickit4            = MPLAB(R) PICkit 4 in JTAG mode
  pickit4_jtag       = MPLAB(R) PICkit 4 in JTAG mode
  pickit4_isp        = MPLAB(R) PICkit 4 in ISP mode
  pickit4_pdi        = MPLAB(R) PICkit 4 in PDI mode
  pickit4_tpi        = MPLAB(R) PICkit 4 in TPI mode
  pickit4_updi       = MPLAB(R) PICkit 4 in UPDI mode
  pkobn_updi         = Curiosity nano (nEDBG) in UPDI mode
  ponyser            = design ponyprog serial, reset=!txd sck=rts sdo=dtr sdi=cts
  powerdebugger      = Atmel PowerDebugger (ARM/AVR) in JTAG mode
  powerdebugger_jtag = Atmel PowerDebugger (ARM/AVR) in JTAG mode
  powerdebugger_dw   = Atmel PowerDebugger (ARM/AVR) in debugWire mode
  powerdebugger_isp  = Atmel PowerDebugger (ARM/AVR) in ISP mode
  powerdebugger_pdi  = Atmel PowerDebugger (ARM/AVR) in PDI mode
  powerdebugger_tpi  = Atmel PowerDebugger (ARM/AVR) in TPI mode
  powerdebugger_updi = Atmel PowerDebugger (ARM/AVR) in UPDI mode
  serialupdi         = SerialUPDI
  siprog             = Lancos SI-Prog (same as ponyser)
  snap               = MPLAB(R) SNAP in JTAG mode
  snap_jtag          = MPLAB(R) SNAP in JTAG mode
  snap_isp           = MPLAB(R) SNAP in ISP mode
  snap_pdi           = MPLAB(R) SNAP in PDI mode
  snap_tpi           = MPLAB(R) SNAP in TPI mode
  snap_updi          = MPLAB(R) SNAP in UPDI mode
  stk500             = Atmel STK500 (probes STK500v2 first then STK500v1)
  stk500hvsp         = Atmel STK500 v2 in high-voltage serial programming mode
  scratchmonkey_hvsp = Atmel STK500 v2 in high-voltage serial programming mode
  stk500pp           = Atmel STK500 v2 in parallel programming mode
  scratchmonkey_pp   = Atmel STK500 v2 in parallel programming mode
  stk500v1           = Atmel STK500 version 1.x firmware
  stk500v2           = Atmel STK500 version 2.x firmware
  scratchmonkey      = Atmel STK500 version 2.x firmware
  stk600             = Atmel STK600
  stk600hvsp         = Atmel STK600 in high-voltage serial programming mode
  stk600pp           = Atmel STK600 in parallel programming mode
  tc2030             = Tag-Connect TC2030
  teensy             = Teensy for bootloader
  tigard             = Tigard interface board
  ttl232r            = FTDI TTL232R-5V with ICSP adapter
  tumpa              = TIAO USB Multi-Protocol Adapter
  tumpa-b            = TIAO USB Multi-Protocol Adapter
  tumpa_jtag         = TIAO USB Multi-Protocol Adapter (JTAG)
  um232h             = UM232H module from FTDI
  uncompatino        = uncompatino with all pairs of pins shorted
  urclock            = Urclock programmer for urboot bootloaders using urprotocol
  usbasp             = USBasp ISP and TPI programmer
  usbasp-clone       = Any usbasp clone with correct VID/PID
  usbtiny            = USBtiny simple USB programmer
  wiring             = Wiring for bootloader using STK500 v2 protocol
  xbee               = XBee for Series 2 Over-The-Air (XBeeBoot) bootloader using STK500 v1 protocol
  xplainedmini       = Atmel AVR XplainedMini in ISP mode
  xplainedmini_isp   = Atmel AVR XplainedMini in ISP mode
  xplainedmini_dw    = Atmel AVR XplainedMini in debugWIRE mode
  xplainedmini_tpi   = Atmel AVR XplainedMini in TPI mode
  xplainedmini_updi  = Atmel AVR XplainedMini in UPDI mode
  xplainedpro        = Atmel AVR XplainedPro in JTAG mode
  xplainedpro_pdi    = Atmel AVR XplainedPro in PDI mode
  xplainedpro_updi   = Atmel AVR XplainedPro in UPDI mode

Update: After removing the build, adding the definition to the src and rebuilding result is the same :-)

@MCUdude
Copy link
Collaborator Author

MCUdude commented Jan 26, 2024

@cederom Sorry, It's a bit too early for me. What I meant was -P, so -P ch343 instead of the serial port name/path

@cederom
Copy link
Contributor

cederom commented Jan 26, 2024

@cederom Sorry, It's a bit too early for me. What I meant was -P, so -P ch343 instead of the serial port name/path

No worries @MCUdude its 8AM and you probably did not sleep yet or are already running since 4AM just like me :-) :-)

% ./avrdude -P ch343
avrdude error: no programmer has been specified on the command line or in the
        config file(s); specify one using the -c option and try again

It seems CD340 and CH343 are serial adapters only not programmers. I have ordered CH341 board it will arrive next friday so I will be able to test. Can I test anything more at this point? :-)

ps/2: Please add datasheet reference to the configuration too (see my example above) :-)

@MCUdude
Copy link
Collaborator Author

MCUdude commented Jan 26, 2024

No worries @MCUdude its 8AM and you probably did not sleep yet or are already running since 4AM just like me :-) :-)

My 4-year-old daughter woke me up at 06:00, which is way earlier than what I'm used to. And Norway is also so dark in the winter, so that contributes as well!

Can you try avrdude -c urclock -P ?

This should list all available serial ports without starting a programming session

@cederom
Copy link
Contributor

cederom commented Jan 26, 2024

% ./avrdude -c urclock "-P ?"
avrdude OS error: cannot open port  ?: No such file or directory
avrdude error: unable to open port  ? for programmer urclock
Possible candidate serial ports are:
  -P /dev/cuau0
  -P /dev/cuaU0 or -P ch343
Note that above ports might not be connected to a target board or an AVR programmer.
Also note there may be other direct serial ports not listed above.

avrdude done.  Thank you.


% ./avrdude -c urclock -P /dev/cuaU0
avrdude warning: attempt 1 of 10: not in sync
avrdude warning: attempt 2 of 10: not in sync
avrdude warning: attempt 3 of 10: not in sync
avrdude warning: attempt 4 of 10: not in sync
avrdude warning: attempt 5 of 10: not in sync
avrdude warning: attempt 6 of 10: not in sync
avrdude warning: attempt 7 of 10: not in sync
avrdude warning: attempt 8 of 10: not in sync
avrdude warning: attempt 9 of 10: not in sync
avrdude warning: attempt 10 of 10: not in sync
avrdude warning: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude error: unable to open port /dev/cuaU0 for programmer urclock
Possible candidate serial ports are:
  -P /dev/cuau0
  -P /dev/cuaU0 or -P ch343
Note that above ports might not be connected to a target board or an AVR programmer.
Also note there may be other direct serial ports not listed above.

avrdude done.  Thank you.


% ./avrdude -c urclock -P ch343
avrdude warning: attempt 1 of 10: not in sync
avrdude warning: attempt 2 of 10: not in sync
avrdude warning: attempt 3 of 10: not in sync
avrdude warning: attempt 4 of 10: not in sync
avrdude warning: attempt 5 of 10: not in sync
avrdude warning: attempt 6 of 10: not in sync
avrdude warning: attempt 7 of 10: not in sync
avrdude warning: attempt 8 of 10: not in sync
avrdude warning: attempt 9 of 10: not in sync
avrdude warning: attempt 10 of 10: not in sync
avrdude warning: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude error: unable to open port /dev/cuaU0 for programmer urclock
Possible candidate serial ports are:
  -P /dev/cuau0
  -P /dev/cuaU0 or -P ch343
Note that above ports might not be connected to a target board or an AVR programmer.
Also note there may be other direct serial ports not listed above.

avrdude done.  Thank you.

Btw I have found AtTiny104-Xplained-Nano is it supported already? :-)

@MCUdude
Copy link
Collaborator Author

MCUdude commented Jan 26, 2024

% ./avrdude -c urclock "-P ?"
avrdude OS error: cannot open port  ?: No such file or directory
avrdude error: unable to open port  ? for programmer urclock
Possible candidate serial ports are:
  -P /dev/cuau0
  -P /dev/cuaU0 or -P ch343
Note that above ports might not be connected to a target board or an AVR programmer.
Also note there may be other direct serial ports not listed above.

avrdude done.  Thank you.

Excellent! This means that Avrdude/libserialport can detect the CH343 VID/PID and correctly identify it. Thank you!

Btw I have found AtTiny104-Xplained-Nano is it supported already? :-)

Correct! Use avrdude -cxplainedmini_tpi -pattiny104

@cederom
Copy link
Contributor

cederom commented Jan 26, 2024

I need to refresh my AVR setup :D I also found BusPirate and I have FT2232H (ktlink) that seems supported.. just how to connect them to AVR?

@mcuee mcuee added the enhancement New feature or request label Jan 26, 2024
@cederom
Copy link
Contributor

cederom commented Jan 26, 2024

% avrdude -cxplainedmini_tpi -pattiny104
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e900b (probably t104)

avrdude done.  Thank you.

% avrdude -cxplainedmini_tpi -pattiny104 -P ch343
avrdude error: JTAGICE3/EDBG port names must start with usb
avrdude error: unable to open programmer xplainedmini_tpi on port ch343

avrdude done.  Thank you.

@MCUdude
Copy link
Collaborator Author

MCUdude commented Jan 26, 2024

I need to refresh my AVR setup :D I also found BusPirate and I have FT2232H (ktlink) that seems supported.. just how to connect them to AVR?

Yes, Avrdude has gotten a ton of new features lately, including a bund of new and exciting hardware.

I have an FT2232 board that can be used as a JTAG programmer, and it's fairly easy to get working:

#------------------------------------------------------------
# ft2232h_jtag
#------------------------------------------------------------

# Here a FTDI ft2232h chip is used for JTAG programming.

programmer # ft2232h_jtag
    id                     = "ft2232h_jtag";
    desc                   = "FT2232H based generic JTAG programmer";
    type                   = "avrftdi_jtag";
    prog_modes             = PM_JTAG;
    connection_type        = usb;
    usbvid                 = 0x0403;
    usbpid                 = 0x6010;
    usbdev                 = "A";
# JTAG-signals - lower ADBUS-Nibble (default)
    tck                    = 0; # AD0 (TCK)
    tdi                    = 1; # AD1 (TDI)
    tdo                    = 2; # AD2 (TDO)
    tms                    = 3; # AD3 (TMS)
;
% avrdude -cxplainedmini_tpi -pattiny104
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e900b (probably t104)

avrdude done.  Thank you.

% avrdude -cxplainedmini_tpi -pattiny104 -P ch343
avrdude error: JTAGICE3/EDBG port names must start with usb
avrdude error: unable to open programmer xplainedmini_tpi on port ch343

avrdude done.  Thank you.

This is to be expected. The xplainedmini_tpi is a USB device, so the only port that will work is -P usb

@stefanrueger
Copy link
Collaborator

Thanks! Cool new addition

ps/2: Please add datasheet reference to the configuration too (see my example above) :-)

Agreed!

# CH343G chip https://www.wch-ic.com/downloads/CH343DS1_PDF.html

@mcuee
Copy link
Collaborator

mcuee commented Jan 28, 2024

This PR should be good to be merged.

@stefanrueger stefanrueger merged commit d0e444c into avrdudes:main Jan 28, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants