WCH CH343 Linux Driver

repository·main·Indexed 42 days ago

https://github.com/wchsoftgroup/ch343ser_linux

Custom Linux kernel VCP driver for WCH USB-to-UART chips, including the CH343, CH344, and CH91x series. Provides access to device-specific features such as hardware flow control and GPIO functions. Includes the CH34xSerCfg configuration tool for modifying USB parameters like VID, PID, and string descriptors via CONFIG.INI.

Tokens
3.2K
Snippets
6
Records
10
Agent score
54%

What's inside CH343

  1. Overview of CH34xSerCfg configuration software

    main

    The CH34xSerCfg configuration software is a tool used to configure USB parameters for the WCH USB-to-Serial chip series. It allows users to modify the following parameters:

    • Vendor ID (VID)
    • Product ID (PID)
    • Maximum current value
    • Manufacturer information string descriptor
    • Product information string descriptor
  2. Supported chip models for CH34xSerCfg

    main

    The CH34xSerCfg tool supports a wide range of WCH chips for parameter configuration, including:

    • CH34x Series: CH343P, CH342F, CH344Q/L, CH346C, CH347T/F, CH348Q/L
    • CH91xx Series: CH9101U/H/R/Y, CH9102F, CH9103M, CH9104L, CH9105W, CH9111L, CH9114L/W/F
    • Other Models: CH9344Q, CH339W

    Note on CH342F/CH9102F: For these specific models, configuration is only supported if the 4th character from the end of the batch number is a letter, indicating the chip has a built-in EEPROM that supports this functionality.

  3. Supported CH34x/CH91x chips

    main

    The CH343 driver supports a wide range of USB to UART chips, including single, dual, and quad serial port configurations:

    • Single serial port: CH343, CH346, CH347, CH9101, CH9102, CH9111, CH9433
    • Dual serial ports: CH342, CH346, CH347, CH9103
    • Quad serial ports: CH344, CH9104, CH9105, CH9114
  4. Configure CH34x chip parameters via CONFIG.INI

    main

    The CH34xSerCfg tool uses a CONFIG.INI file to modify chip parameters. You only need to include the items you wish to change; other items can be omitted.

    Important Warnings:

    • VID/PID Modification: If you change the VendorID or ProductID, the original VCP driver will no longer work with the chip. The device will then only be recognized by the system's default CDC driver (note: CH340/CH348 series do not support system CDC drivers). To use the VCP driver again, you must recompile the driver with the new IDs.
    • Identification: To distinguish between multiple chips, it is recommended to modify Serial_String, Product_String, or Manufacturer_String instead of VID/PID.
    • Formatting: Do not modify any content or formatting in CONFIG.INI other than the configuration values.
    VendorID=
    ProductID=
    
    Serial_String_Enable=y
    Product_String_Enable=y
    Manufacturer_String_Enable=y
    Serial_String=abcdef
    Product_String=USB_xxx_Serial
    Manufacturer_String=www.wch.cn
    
    MaxPower(mA)=300
    PowerMode=Bus-Powered
    Remote_Wakeup_Enable=no
    
    PIN_USE_EEPROM_Enable=no
    CDC_CTSRTS_FlowControl_Enable=no
    TurnOff_SuspendMode_Enable=no
    
    # CH344/CH348/CH9114
    DTR_MUX_TNOW_SoftSet_Enable=y
    UARTx_TNOW_DTR_SETBITS=00
    
    # CH9101RY
    CH9101RY_MODEM_Enable=y
    CH9101RY_TXS_MUX_DSR_Enable=y
    CH9101RY_RXS_MUX_RI_Enable=y
    CH9101RY_TNOW_MUX_DCD_Enable=y
    CH9101RY_SLEEP_MUX_DTR_Enable=y
    
    # CH346
    CH346_Config_Enable=n
    CH346_Config_Freq=
    CH346_Config_Mode=
    CH346_Config_PLen=
    CH346_Config_M0_IO0=
    CH346_Config_M0_IO1=
    CH346_Config_M1_IO0=
    CH346_Config_M1_IO1=
    CH346_Config_M2_IO0=
    CH346_Config_M2_IO1=
    CH346_Config_M2_IO2=
    CH346_Config_M2_IO3=
  5. Manage the CH343 driver lifecycle

    main

    Use the following commands to unload or remove the driver from your system:

    • Unload dynamically: Use sudo make unload or sudo rmmod ch343.ko.
    • Uninstall permanently: Use sudo make uninstall to remove the driver from the system.
    sudo make unload
    sudo rmmod ch343.ko
    sudo make uninstall
  6. Configure UDEV rules for CH34x devices

    main

    To ensure the CH34x USB-Serial converter uses the correct driver instead of the default CDC-ACM driver, you must install the provided UDEV rules.

    Follow these steps:

    1. Copy the 99-ch34x.rules file to the /etc/udev/rules.d/ directory.
    2. Reload the UDEV rules using udevadm.
    3. Replug the device into the USB port.

    Once configured, the system will no longer use the CDC-ACM device driver for WCH USB-Serial converter devices.

    # 1. Copy the rules file
    sudo cp 99-ch34x.rules /etc/udev/rules.d/
    
    # 2. Reload UDEV rules
    sudo udevadm control -R
    
    # 3. Replug your device
  7. Install the CH343 Linux serial driver

    main

    To use the custom VCP driver for CH343/CH346/CH347/CH9101/CH9102/CH9111/CH9433 and related chips, follow these steps in your terminal:

    1. Navigate to the driver directory.
    2. Compile the driver using make. A successful build produces ch343.ko.
    3. Load the driver dynamically using sudo make load or sudo insmod ch343.ko.
    4. To make the driver work permanently, run sudo make install.

    Important: Before installing this driver, ensure the default Linux cdc-acm driver is not active for your device. You can check for existing ACM devices with ls /dev/ttyACM*. If the cdc-acm driver is loaded, remove it using rmmod cdc-acm before proceeding.

    # Compile the driver
    make
    
    # Load the driver dynamically
    sudo make load
    # OR
    sudo insmod ch343.ko
    
    # Make the driver permanent
    sudo make install
  8. Compile and run the CH34xSerCfg tool

    main

    To use the parameter configuration tool, you must first compile it using the provided library.

    1. Obtain libch34xcfg.so or libch34xcfg.a from the lib folder of the ch343ser_linux repository.
    2. Place the library file in the system standard library path or directly in the param_config directory.
    3. Compile the demo using gcc.

    Command Syntax: ./CH34xSerCfg -d [serial_device_path] -c [config_file_path]

    Interactive Commands:

    • g: Get current configuration
    • s: Set chip configuration from CONFIG.INI
    • d: Write manufacturer default configuration to EEPROM
    • q: Quit
    # Compilation
    gcc ch34x_demo_param_config.c -lch34xcfg -o CH34xSerCfg
    
    # Execution example
    ./CH34xSerCfg -d /dev/ttyCH343USB0 -c CONFIG.INI
  9. Verify USB device connection and driver nodes

    main

    Before using the driver, verify that the USB device is recognized by the system. The USB Vendor ID (VID) for these devices is 1a86.

    Verification Commands:

    • Use lsusb to check if the device is listed.
    • Use dmesg to view kernel logs for connection events.

    Device Nodes: Once the driver is successfully loaded and the device is connected, the following nodes will appear in /dev:

    • Serial ports: /dev/ttyCH343USBx
    • GPIO functions (for supported chips): /dev/ch343_iodevx

    Permissions: By default, operating these devices in /dev requires root permissions. To allow non-root users to access the device, you must create a udev rule file for the device.

  10. Reference: CONFIG.INI configuration keys

    main

    The following keys are available in CONFIG.INI for configuring CH34x series chips. Note that support for specific keys depends on the chip model.

    # General USB Configuration
    VendorID                      # VID (Note: changing this breaks original VCP driver compatibility)
    ProductID                     # PID (Note: changing this breaks original VCP driver compatibility)
    Serial_String_Enable          # y: enable, n: disable
    Product_String_Enable         # y: enable, n: disable
    Manufacturer_String_Enable    # y: enable, n: disable
    Serial_String                 # Length <= 10
    Product_String                # Length <= 18
    Manufacturer_String           # Length <= 18
    MaxPower(mA)                   # e.g., 300
    PowerMode                     # Self-Powered or Bus-Powered
    Remote_Wakeup_Enable          # y: enable, n: disable
    
    # Chip Specific Features
    PIN_USE_EEPROM_Enable         # y: enable, n: disable (Supports CH9102F, CH9101U/H/R/Y)
    CDC_CTSRTS_FlowControl_Enable # y: enable, n: disable (CDC mode hardware flow control)
    TurnOff_SuspendMode_Enable    # y: enable, n: disable (Supports CH348Q/L, CH344Q, CH9114L/W/F, CH9111)
    DTR_MUX_TNOW_SoftSet_Enable   # y: enable, n: disable (Supports CH344, CH348, CH9114)
    UARTx_TNOW_DTR_SETBITS       # bit0~bit7 for UART0~UART7. 1: TNOW, 0: DTR (Requires DTR_MUX_TNOW_SoftSet_Enable=y)
    
    # CH9105 Specific
    CH9105_GPIO_Enable            # y: enable, n: disable
    CH9105_GPIO_Enable_BITS       # 16-bit hex value (e.g., 0xFFFF)
    
    # CH9101RY Specific
    CH9101RY_MODEM_Enable         # y: enable, n: disable
    CH9101RY_TXS_MUX_DSR_Enable  # y: DSR#, n: TXS (default)
    CH9101RY_RXS_MUX_RI_Enable   # y: RI#, n: RXS (default)
    CH9101RY_TNOW_MUX_DCD_Enable # y: DCD#, n: TNOW (default)
    CH9101RY_SLEEP_MUX_DTR_Enable# y: DTR#, n: SLEEP (default)
    
    # CH346 Specific
    CH346_Config_Enable           # y: enable, n: disable
    CH346_Config_Freq             # Decimal frequency value
    CH346_Config_Mode             # 0, 1, or 2
    CH346_Config_PLen             # Packet size (must be multiple of 512, default 512)
    CH346_Config_M0_IO0           # Mode 0 IO0: 0x00:RXD0, 0x01:TX_S, 0x02:ACT, 0x03:GPIO6
    CH346_Config_M0_IO1           # Mode 0 IO1: 0x00:TXD0, 0x01:RX_S, 0x02:SUSP, 0x03:GPIO7
    CH346_Config_M1_IO0          # Mode 1 IO0: 0x00:DCD0, 0x01:TX_S, 0x02:Invalid, 0x03:GPIO4
    CH346_Config_M1_IO1          # Mode 1 IO1: 0x00:DTR0, 0x01:RX_S, 0x02:Invalid, 0x03:GPIO2
    CH346_Config_M2_IO0          # Mode 2 IO0: 0x00:DCD1, 0x01:SUSP, 0x02:Invalid, 0x03:GPIO7
    CH346_Config_M2_IO1          # Mode 2 IO1: 0x00:DCD0, 0x01:TX_S, 0x02:Invalid, 0x03:GPIO4
    CH346_Config_M2_IO2          # Mode 2 IO2: 0x00:DTR0, 0x01:RX_S, 0x02:Invalid, 0x03:GPIO2
    CH346_Config_M2_IO3          # Mode 2 IO3: 0x00:DSR0, 0x01:ACT, 0x02:Invalid, 0x03:GPIO3