You are not logged in.

#1 2023-05-09 13:37:29

poiasd
Member
Registered: 2023-05-09
Posts: 5

Cannot detect microcontroller - CH34X driver (6.3.1)

Hi all, I am trying to program an ESP32 , but Arch does not seem to detect it at all. I am on Kernel 6.3.1, but this is my FIRST time trying it, so I can't say it is definitely the new kernel's fault.

I tried to manually build and install the kernel module as outlined here: https://github.com/juliagoda/CH341SER/# … arch-linux , including adding my user to the `uucp` and `lock` groups, then restarting.

I manually loaded the kernel module using `modprobe ch34x` , and still doesn't seem like anything is happening.

$ sudo dmesg | grep ch34x
[   60.592626] usbcore: registered new interface driver ch34x
[   60.592638] usbserial: USB Serial support registered for ch34x

$ sudo dmesg | grep tty
[    0.003333] printk: console [tty0] enabled
[    5.322053] serial8250: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[   19.005956] systemd[1]: Created slice Slice /system/getty.

Running `udevadm monitor` and then plugging in the ESP32:

$ sudo udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

[... nothing]

It seems to be loaded though:

$ lsmod | grep ch34x
ch34x                  36864  0

any pointers on what to try next? It works on windows so I know its not the ESP32 itself at fault.

Offline

#2 2023-05-13 21:43:12

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 369

Re: Cannot detect microcontroller - CH34X driver (6.3.1)

poiasd wrote:

Hi all, I am trying to program an ESP32 , but Arch does not seem to detect it at all.

Are you trying to use CH341 as USB-to-serial adapter? Serial driver is in mainline kernel. Arch supports it out of box, you don't need third-party driver.
Did you set jumper to "UART" position?
Does lsusb detect adapter?

Last edited by dimich (2023-05-13 21:45:45)

Offline

#3 2023-05-14 02:47:37

Fijxu
Member
Registered: 2021-08-11
Posts: 46

Re: Cannot detect microcontroller - CH34X driver (6.3.1)

The CH341 as far as i know is in the Linux kernel, it can read NAND Flash memories (In my case, to dump the BIOS) using Flashrom and use the UART interface (Switching the jumper from 1-2 to 2-3). I own a CH341B btw (Different from the CH341A)

I don't know anything about the CH34X, it should be the same i guess.

https://elixir.bootlin.com/linux/latest … al/ch341.c

Offline

#4 2023-05-14 07:57:36

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 369

Re: Cannot detect microcontroller - CH34X driver (6.3.1)

Fijxu wrote:

The CH341 as far as i know is in the Linux kernel, it can read NAND Flash memories (In my case, to dump the BIOS) using Flashrom and use the UART interface (Switching the jumper from 1-2 to 2-3).

Depending on jumper setting CH341A appears as two different devices. When it is set to "UART":

$ lsusb | grep CH341
Bus 001 Device 005: ID 1a86:5523 QinHeng Electronics CH341 in serial mode, usb to serial port converter

Note PID 0x5523. In this mode the device is handled by in-tree kernel driver ch341. It should appear as /dev/ttyUSB* as usual USB-to-serial adapter.

When it is set to "I2C/SPI":

$  lsusb | grep CH341
Bus 001 Device 006: ID 1a86:5512 QinHeng Electronics CH341 in EPP/MEM/I2C mode, EPP/I2C adapter

Note PID 0x5512. Mainline kernel has no driver for this mode. Tools like ch341prog or ch341eeprom access device with libusb and don't require kernel driver.
You need third party drivers only if you want to use it as linux SPI or I2C device (e.g. /dev/spi* or /dev/i2c-*).

Fijxu wrote:

I own a CH341B btw (Different from the CH341A)

I never owned CH341B, so not sure. According to this page the difference is requirement for external crystal oscillator: CH341B can work with internal clock.

Please provide output of

$ lsusb

when the device is plugged in.

And how is it related to ESP32? Is CH341 chip installed on your ESP32 board? Or do you want to connect ESP32's UART to PC with external adapter?

Offline

#5 2023-05-26 18:58:18

willard
Member
Registered: 2023-05-26
Posts: 3

Re: Cannot detect microcontroller - CH34X driver (6.3.1)

I have recently started having trouble with my ESP32 WROOM dev boards that have the same chip. According to dmesg, they'll enumerate, then disconnect, over and over, once every couple of seconds.

[ 1410.955162] usb 1-1: new full-speed USB device number 51 using xhci_hcd
[ 1411.096390] usb 1-1: New USB device found, idVendor=1a86, idProduct=7523, bcdDevice=81.34
[ 1411.096406] usb 1-1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 1411.096413] usb 1-1: Product: USB Serial
[ 1411.098595] ch341 1-1:1.0: ch341-uart converter detected
[ 1411.099013] usb 1-1: ch341-uart converter now attached to ttyUSB0
[ 1413.873188] usb 1-1: USB disconnect, device number 51
[ 1413.873547] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[ 1413.873600] ch341 1-1:1.0: device disconnected
[ 1416.115042] usb 1-1: new full-speed USB device number 52 using xhci_hcd
[ 1416.256960] usb 1-1: New USB device found, idVendor=1a86, idProduct=7523, bcdDevice=81.34
[ 1416.256977] usb 1-1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 1416.256984] usb 1-1: Product: USB Serial
[ 1416.258915] ch341 1-1:1.0: ch341-uart converter detected
[ 1416.259358] usb 1-1: ch341-uart converter now attached to ttyUSB0
[ 1418.872877] usb 1-1: USB disconnect, device number 52
[ 1418.873379] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[ 1418.873456] ch341 1-1:1.0: device disconnected
[ 1421.115062] usb 1-1: new full-speed USB device number 53 using xhci_hcd
[ 1421.256954] usb 1-1: New USB device found, idVendor=1a86, idProduct=7523, bcdDevice=81.34
[ 1421.256971] usb 1-1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 1421.256978] usb 1-1: Product: USB Serial
[ 1421.258871] ch341 1-1:1.0: ch341-uart converter detected
[ 1421.259338] usb 1-1: ch341-uart converter now attached to ttyUSB0
[ 1424.208709] usb 1-1: USB disconnect, device number 53
[ 1424.209198] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[ 1424.209273] ch341 1-1:1.0: device disconnected
[ 1426.451795] usb 1-1: new full-speed USB device number 54 using xhci_hcd
[ 1426.593375] usb 1-1: New USB device found, idVendor=1a86, idProduct=7523, bcdDevice=81.34
[ 1426.593391] usb 1-1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 1426.593398] usb 1-1: Product: USB Serial
[ 1426.601998] ch341 1-1:1.0: ch341-uart converter detected
[ 1426.602615] usb 1-1: ch341-uart converter now attached to ttyUSB0
[ 1429.208996] usb 1-1: USB disconnect, device number 54
[ 1429.209534] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[ 1429.209603] ch341 1-1:1.0: device disconnected

This isn't happening on my Fedora 38 laptop, which is running a slightly older kernel (6.2.15). I've got 6.3.3-arch1-1 on my Arch laptop, and unlike a lot of other folks online, I don't, nor have ever, had brltty or any components therein installed.

The only workaround that has worked for me thus far (and only once or twice, at that) was this: (https://www.reddit.com/r/esp32/comments … ing_linux/)

UnexpectedMaker sez: Any time if you get an ESP32-S2 or S3 into a boot loop situation, and you can't flash it, you can always put it into download mode (Hold BOOT, Press and release RESET, Release BOOT) - And that will put it into a mode that will force the CDC serial port to kick in, so you can re-flash it or erase the current flash.

Offline

#6 2023-05-26 19:42:56

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 369

Re: Cannot detect microcontroller - CH34X driver (6.3.1)

willard wrote:

According to dmesg, they'll enumerate, then disconnect, over and over, once every couple of seconds.

Looks like board-specific hardware or firmware issue. Maybe some quirks with modem control lines. Isn't one of them used for board reset or mode selection? Do you have schematics for your board?

Also check USB autosuspend and try to disable it if enabled.

Last edited by dimich (2023-05-26 19:43:23)

Offline

#7 2023-05-30 15:06:21

willard
Member
Registered: 2023-05-26
Posts: 3

Re: Cannot detect microcontroller - CH34X driver (6.3.1)

dimich wrote:

Looks like board-specific hardware or firmware issue. Maybe some quirks with modem control lines. Isn't one of them used for board reset or mode selection? Do you have schematics for your board?

I do not have schematics, but I do have the Amazon link to my exact board: (https://www.amazon.com/dp/B0B18MCYFH?ps … ct_details)

There's a chip labeled "CH340C" on the board that I assume is the serial to usb converter.

dimich wrote:

Also check USB autosuspend and try to disable it if enabled.

Good idea, but unfortunately, it didn't seem to work. I checked lsusb to get the vendor and product ID, then added this blacklist rule:

[/etc/udev/rules.d]
$ cat 50-usb_power_save.rules
# blacklist for usb autosuspend
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1a86", ATTR{idProduct}=="7523", GOTO="power_usb_rules_end"

ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto"
LABEL="power_usb_rules_end"

Alas, I'm still getting the same symptoms. Maybe this udev rule is bad?

One weird thing that I noticed (dunno if this means anything) was that the device seemed to insist on being usb1/1-1. I poked around a little in powertop, to no avail. I do see the `autosuspend` option for the USB 1-1 pop up occasionally.

Last edited by willard (2023-05-30 15:17:11)

Offline

#8 2023-05-30 16:51:17

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 369

Re: Cannot detect microcontroller - CH34X driver (6.3.1)

willard wrote:

There's a chip labeled "CH340C" on the board that I assume is the serial to usb converter.

Yes, CH340 is serial to usb converter and it is handled by in-kernel ch341 driver, the same as for CH341 in UART mode.

willard wrote:

Alas, I'm still getting the same symptoms. Maybe this udev rule is bad?

Your rule enables autosuspend for all USB devices except 1a86:7523.
To keep particular device always on this rule should work:

ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1a86", ATTR{idProduct}=="7523", ATTR{power/control}="on"

But i'm not sure the issue is caused by autosuspend.

willard wrote:

I do not have schematics, but I do have the Amazon link to my exact board: (https://www.amazon.com/dp/B0B18MCYFH?ps … ct_details)

It uses DTR/RTS pair for reset and boot control (https://electronics.stackexchange.com/q … rd-dtr-rts).
Usually port opening causes device to reboot (as on most of Arduinos) but here looks like port initialization also does. Maybe you have some software running which automatically open serial port when device attached? Maybe some other udev rule which run such software, e.g. for /dev/ttyUSB*?

Offline

#9 2023-07-01 07:01:22

poiasd
Member
Registered: 2023-05-09
Posts: 5

Re: Cannot detect microcontroller - CH34X driver (6.3.1)

Sorry for disapperaing on you guys.

I just tried it today and it worked. I didn't change anything since last time, so I am guessing maybe something in the kernel? Hard to say for sure. I am currently on 6.3.9

udevadm monitor when I insert it:

$ udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[9298.965995] add      /devices/pci0000:00/0000:00:14.0/usb1/1-2 (usb)
KERNEL[9298.971683] add      /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0 (usb)
KERNEL[9298.971998] add      /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.1 (usb)
KERNEL[9298.972054] bind     /devices/pci0000:00/0000:00:14.0/usb1/1-2 (usb)
UDEV  [9298.974130] add      /devices/pci0000:00/0000:00:14.0/usb1/1-2 (usb)
UDEV  [9298.977548] add      /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.1 (usb)
KERNEL[9298.983098] bind     /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.1 (usb)
KERNEL[9298.983195] add      /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/tty/ttyACM0 (tty)
KERNEL[9298.983249] bind     /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0 (usb)
KERNEL[9298.983285] add      /bus/usb/drivers/cdc_acm (drivers)
KERNEL[9298.983303] add      /module/cdc_acm (module)
UDEV  [9298.983367] add      /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0 (usb)
UDEV  [9298.984030] add      /bus/usb/drivers/cdc_acm (drivers)
UDEV  [9298.985214] bind     /devices/pci0000:00/0000:00:14.0/usb1/1-2 (usb)
UDEV  [9298.985276] add      /module/cdc_acm (module)
UDEV  [9298.986909] bind     /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.1 (usb)
UDEV  [9298.988081] add      /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/tty/ttyACM0 (tty)
UDEV  [9298.989794] bind     /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0 (usb)

Offline

Board footer

Powered by FluxBB