gschorcht / spi-ch341-usb Goto Github PK
View Code? Open in Web Editor NEWLinux kernel driver for CH341A USB to SPI and GPIO adapters
Linux kernel driver for CH341A USB to SPI and GPIO adapters
I'm having an issue where the SPI communication times out after 32 bytes.. Documentation for this boards is obviously slim.. any idea why that might be or is it a bug?
I tried to compile and insert in Mageia Linux 5.15.23-desktop-1.mga8 and an old computer with Debian Linux too. The Debian could compile and start /dev/spidev0.0-2 auto, but Mageia doesn't creates spidev devices.
`make
Error! Unknown action specified: spi-ch341-usb
make -C /lib/modules/5.15.23-desktop-1.mga8/build M=/root/gschorcht/spi-ch341-usb-master modules
make[1]: Entering directory '/usr/src/kernel-5.15.23-desktop-1.mga8'
Error! Unknown action specified: spi-ch341-usb
CC [M] /root/gschorcht/spi-ch341-usb-master/spi-ch341-usb.o
Error! Unknown action specified: spi-ch341-usb
MODPOST /root/gschorcht/spi-ch341-usb-master/Module.symvers
CC [M] /root/gschorcht/spi-ch341-usb-master/spi-ch341-usb.mod.o
LD [M] /root/gschorcht/spi-ch341-usb-master/spi-ch341-usb.ko
make[1]: Leaving directory '/usr/src/kernel-5.15.23-desktop-1.mga8'
`
after loading spi-ch341-usb.ko new spi devices appears in /sys/class/spi_master/spi0 but no /dev/spidev.
`journalctl -ae
kernel: usbcore: registered new interface driver spi-ch341-usb
kernel: usb 1-9: new full-speed USB device number 6 using xhci_hcd
kernel: usb 1-9: New USB device found, idVendor=1a86, idProduct=5512, bcdDevic>
kernel: usb 1-9: New USB device strings: Mfr=0, Product=0, SerialNumber=0
kernel: spi-ch341-usb 1-9:1.0: ch341_cfg_probe: output cs0 SPI slave with cs=0
kernel: spi-ch341-usb 1-9:1.0: ch341_cfg_probe: output cs1 SPI slave with cs=1
kernel: spi-ch341-usb 1-9:1.0: ch341_cfg_probe: output cs2 SPI slave with cs=2
kernel: spi-ch341-usb 1-9:1.0: ch341_cfg_probe: input gpio4 gpio=0 irq=0 (hwi>
kernel: spi-ch341-usb 1-9:1.0: ch341_cfg_probe: input gpio5 gpio=1 irq=1
kernel: spi-ch341-usb 1-9:1.0: ch341_spi_probe: SPI master connected to SPI bu>
kernel: spi-ch341-usb 1-9:1.0: ch341_spi_probe: SPI device /dev/spidev0.0 crea>
kernel: spi-ch341-usb 1-9:1.0: ch341_spi_probe: SPI device /dev/spidev0.1 crea>
kernel: spi-ch341-usb 1-9:1.0: ch341_spi_probe: SPI device /dev/spidev0.2 crea>
kernel: spi-ch341-usb 1-9:1.0: ch341_usb_probe: connected`
On the newer kernels ( 5.3.7 at least ) the compilation fails with
spi-ch341-usb/spi-ch341-usb.c:623:45: error: implicit declaration of function ‘SPI_BIT_MASK’; did you mean ‘SPI_BPW_MASK’? [-Werror=implicit-function-declaration]
I am trying to use the CH341 USB to serial/UART/I2C/SPI adapter in I2C mode. The adapter has a jumper that allows switching between serial mode and I2C/SPI mode. The kernel module module installs without any errors.
When the jumper is set to serial mode, the device is recognized and listed as follows:
Bus 001 Device 014: ID 1a86:5523 QinHeng Electronics CH341 in serial mode, usb to serial port converter
When the jumper is set to I2C mode, the device is recognized and listed as follows:
Bus 001 Device 015: ID 1a86:5512 QinHeng Electronics CH341 in EPP/MEM/I2C mode, EPP/I2C adapter
However, the dmesg
output shows the same information in both cases:
[ 2392.780884] usb 1-2: USB disconnect, device number 13
[ 2392.781072] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[ 2392.781090] ch341 1-2:1.0: device disconnected
[ 2395.056594] usb 1-2: new full-speed USB device number 14 using xhci_hcd
[ 2395.209096] usb 1-2: New USB device found, idVendor=1a86, idProduct=5523, bcdDevice= 3.04
[ 2395.209098] usb 1-2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 2395.210086] ch341 1-2:1.0: ch341-uart converter detected
[ 2395.210449] usb 1-2: ch341-uart converter now attached to ttyUSB0
Has anybody had this issue?
I'm on Ubuntu 20.04 LTS by the way :)
I found out that plugging more than one ch341 at a time makes the driver very unhappy. The dmesg
log complains about creating a duplicate gpio4
file, which to me indicates this driver was not written to support multiple ch341-based devices at once.
However I do not need the GPIO functionality, I just need multiple SPI interfaces (not multiple slaves sharing a bus, I mean multiple buses using multiple physical ch341-based adapters), and that seems to probe fine before crashing and burning when it tries to probe for GPIO later on.
I'm no kernel hacker, but my understanding here is all I need to do is get rid/comment out the GPIO functionality and I would have a working driver that can handle however many devices I can plug in. Am I correct in that assumption ? I'm willing to give it a shot in a PR, but I would certainly appreciate some guidance on how to get that working. Would commenting out the calls to ch341_gpio_probe
/ch341_gpio_remove
do it ?
dmesg log:
[ 390.504201] spi_ch341_usb: loading out-of-tree module taints kernel.
[ 390.505692] spi-ch341-usb 1-1.5.2:1.0: ch341_cfg_probe: output cs0 SPI slave with cs=0
[ 390.505705] spi-ch341-usb 1-1.5.2:1.0: ch341_cfg_probe: output cs1 SPI slave with cs=1
[ 390.505715] spi-ch341-usb 1-1.5.2:1.0: ch341_cfg_probe: output cs2 SPI slave with cs=2
[ 390.505726] spi-ch341-usb 1-1.5.2:1.0: ch341_cfg_probe: input gpio4 gpio=0 irq=0 (hwirq)
[ 390.505738] spi-ch341-usb 1-1.5.2:1.0: ch341_cfg_probe: input gpio5 gpio=1 irq=1
[ 390.505753] spi-ch341-usb 1-1.5.2:1.0: ch341_spi_probe: SPI master connected to SPI bus 0
[ 390.508672] spi-ch341-usb 1-1.5.2:1.0: ch341_spi_probe: SPI device /dev/spidev0.0 created
[ 390.509075] spi-ch341-usb 1-1.5.2:1.0: ch341_spi_probe: SPI device /dev/spidev0.1 created
[ 390.509398] spi-ch341-usb 1-1.5.2:1.0: ch341_spi_probe: SPI device /dev/spidev0.2 created
[ 390.510421] spi-ch341-usb 1-1.5.2:1.0: ch341_usb_probe: connected
[ 390.510590] usbcore: registered new interface driver spi-ch341-usb
[ 395.512838] Voltage normalised (0x00000000)
[ 409.442825] usb 1-1.5.3: new full-speed USB device number 8 using dwc_otg
[ 409.574854] usb 1-1.5.3: New USB device found, idVendor=1a86, idProduct=5512, bcdDevice= 3.04
[ 409.574868] usb 1-1.5.3: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 409.576333] spi-ch341-usb 1-1.5.3:1.0: ch341_cfg_probe: output cs0 SPI slave with cs=0
[ 409.576347] spi-ch341-usb 1-1.5.3:1.0: ch341_cfg_probe: output cs1 SPI slave with cs=1
[ 409.576357] spi-ch341-usb 1-1.5.3:1.0: ch341_cfg_probe: output cs2 SPI slave with cs=2
[ 409.576369] spi-ch341-usb 1-1.5.3:1.0: ch341_cfg_probe: input gpio4 gpio=0 irq=0 (hwirq)
[ 409.576380] spi-ch341-usb 1-1.5.3:1.0: ch341_cfg_probe: input gpio5 gpio=1 irq=1
[ 409.576404] spi-ch341-usb 1-1.5.3:1.0: ch341_spi_probe: SPI master connected to SPI bus 1
[ 409.577385] spi-ch341-usb 1-1.5.3:1.0: ch341_spi_probe: SPI device /dev/spidev1.0 created
[ 409.578487] spi-ch341-usb 1-1.5.3:1.0: ch341_spi_probe: SPI device /dev/spidev1.1 created
[ 409.579272] spi-ch341-usb 1-1.5.3:1.0: ch341_spi_probe: SPI device /dev/spidev1.2 created
[ 409.579670] gpio gpiochip4: Detected name collision for GPIO name 'gpio4'
[ 409.579683] gpio gpiochip4: Detected name collision for GPIO name 'gpio5'
[ 409.580055] sysfs: cannot create duplicate filename '/class/gpio/gpio4'
[ 409.580071] CPU: 0 PID: 531 Comm: kworker/0:0 Tainted: G C O 4.19.75-v7+ #1270
[ 409.580076] Hardware name: BCM2835
[ 409.580100] Workqueue: usb_hub_wq hub_event
[ 409.580156] [<80111fcc>] (unwind_backtrace) from [<8010d544>] (show_stack+0x20/0x24)
[ 409.580181] [<8010d544>] (show_stack) from [<80819bc0>] (dump_stack+0xd4/0x118)
[ 409.580203] [<80819bc0>] (dump_stack) from [<80333de0>] (sysfs_warn_dup+0x6c/0x78)
[ 409.580219] [<80333de0>] (sysfs_warn_dup) from [<80334128>] (sysfs_do_create_link_sd+0xc4/0xd4)
[ 409.580232] [<80334128>] (sysfs_do_create_link_sd) from [<80334170>] (sysfs_create_link+0x38/0x44)
[ 409.580250] [<80334170>] (sysfs_create_link) from [<805a774c>] (device_add+0x2a8/0x600)
[ 409.580268] [<805a774c>] (device_add) from [<805a7c6c>] (device_create_groups_vargs+0xc0/0xd0)
[ 409.580284] [<805a7c6c>] (device_create_groups_vargs) from [<805a7d54>] (device_create_with_groups+0x44/0x60)
[ 409.580302] [<805a7d54>] (device_create_with_groups) from [<8052d680>] (gpiod_export+0x170/0x1e0)
[ 409.580334] [<8052d680>] (gpiod_export) from [<7f64116c>] (ch341_usb_probe+0x5d8/0xa58 [spi_ch341_usb])
[ 409.580383] [<7f64116c>] (ch341_usb_probe [spi_ch341_usb]) from [<8062463c>] (usb_probe_interface+0x110/0x294)
[ 409.580402] [<8062463c>] (usb_probe_interface) from [<805aae78>] (really_probe+0x23c/0x2d4)
[ 409.580421] [<805aae78>] (really_probe) from [<805ab0e4>] (driver_probe_device+0x70/0x1ac)
[ 409.580441] [<805ab0e4>] (driver_probe_device) from [<805ab3f4>] (__device_attach_driver+0x98/0xa8)
[ 409.580459] [<805ab3f4>] (__device_attach_driver) from [<805a8ca8>] (bus_for_each_drv+0x88/0xcc)
[ 409.580476] [<805a8ca8>] (bus_for_each_drv) from [<805aabb8>] (__device_attach+0xe0/0x144)
[ 409.580493] [<805aabb8>] (__device_attach) from [<805ab420>] (device_initial_probe+0x1c/0x20)
[ 409.580510] [<805ab420>] (device_initial_probe) from [<805a9e7c>] (bus_probe_device+0x94/0x9c)
[ 409.580527] [<805a9e7c>] (bus_probe_device) from [<805a790c>] (device_add+0x468/0x600)
[ 409.580543] [<805a790c>] (device_add) from [<8062220c>] (usb_set_configuration+0x51c/0xa5c)
[ 409.580559] [<8062220c>] (usb_set_configuration) from [<8062db58>] (generic_probe+0x3c/0x88)
[ 409.580574] [<8062db58>] (generic_probe) from [<80624514>] (usb_probe_device+0x34/0x4c)
[ 409.580590] [<80624514>] (usb_probe_device) from [<805aae78>] (really_probe+0x23c/0x2d4)
[ 409.580608] [<805aae78>] (really_probe) from [<805ab0e4>] (driver_probe_device+0x70/0x1ac)
[ 409.580626] [<805ab0e4>] (driver_probe_device) from [<805ab3f4>] (__device_attach_driver+0x98/0xa8)
[ 409.580643] [<805ab3f4>] (__device_attach_driver) from [<805a8ca8>] (bus_for_each_drv+0x88/0xcc)
[ 409.580660] [<805a8ca8>] (bus_for_each_drv) from [<805aabb8>] (__device_attach+0xe0/0x144)
[ 409.580677] [<805aabb8>] (__device_attach) from [<805ab420>] (device_initial_probe+0x1c/0x20)
[ 409.580695] [<805ab420>] (device_initial_probe) from [<805a9e7c>] (bus_probe_device+0x94/0x9c)
[ 409.580711] [<805a9e7c>] (bus_probe_device) from [<805a790c>] (device_add+0x468/0x600)
[ 409.580728] [<805a790c>] (device_add) from [<80618534>] (usb_new_device+0x27c/0x450)
[ 409.580747] [<80618534>] (usb_new_device) from [<8061a048>] (hub_event+0xdc0/0x11d8)
[ 409.580765] [<8061a048>] (hub_event) from [<8013bf64>] (process_one_work+0x170/0x458)
[ 409.580782] [<8013bf64>] (process_one_work) from [<8013c2a8>] (worker_thread+0x5c/0x5a4)
[ 409.580799] [<8013c2a8>] (worker_thread) from [<80142594>] (kthread+0x138/0x168)
[ 409.580816] [<80142594>] (kthread) from [<801010ac>] (ret_from_fork+0x14/0x28)
[ 409.580824] Exception stack(0xb7257fb0 to 0xb7257ff8)
[ 409.580834] 7fa0: 00000000 00000000 00000000 00000000
[ 409.580846] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 409.580856] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000
[ 409.580976] spi-ch341-usb 1-1.5.3:1.0: ch341_gpio_probe: failed to export GPIO gpio4: -17
[ 409.581122] gpio gpiochip4: REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED
[ 409.590168] ------------[ cut here ]------------
[ 409.590201] WARNING: CPU: 0 PID: 531 at lib/refcount.c:187 refcount_sub_and_test_checked+0xa8/0xb8
[ 409.590207] refcount_t: underflow; use-after-free.
[ 409.590213] Modules linked in: spidev spi_ch341_usb(O) bnep hci_uart btbcm serdev bluetooth ecdh_generic brcmfmac brcmutil sha256_generic cfg80211 snd_bcm2835(C) rfkill bcm2835_codec(C) bcm2835_v4l2(C) raspberrypi_hwmon v4l2_mem2mem hwmon snd_pcm bcm2835_mmal_vchiq(C) snd_timer v4l2_common videobuf2_dma_contig videobuf2_vmalloc snd videobuf2_memops videobuf2_v4l2 videobuf2_common videodev vc_sm_cma(C) media uio_pdrv_genirq uio fixed ip_tables x_tables ipv6
[ 409.590500] CPU: 0 PID: 531 Comm: kworker/0:0 Tainted: G C O 4.19.75-v7+ #1270
[ 409.590505] Hardware name: BCM2835
[ 409.590525] Workqueue: usb_hub_wq hub_event
[ 409.590557] [<80111fcc>] (unwind_backtrace) from [<8010d544>] (show_stack+0x20/0x24)
[ 409.590575] [<8010d544>] (show_stack) from [<80819bc0>] (dump_stack+0xd4/0x118)
[ 409.590594] [<80819bc0>] (dump_stack) from [<80120a88>] (__warn+0x104/0x11c)
[ 409.590610] [<80120a88>] (__warn) from [<80120af8>] (warn_slowpath_fmt+0x58/0x74)
[ 409.590627] [<80120af8>] (warn_slowpath_fmt) from [<80505078>] (refcount_sub_and_test_checked+0xa8/0xb8)
[ 409.590645] [<80505078>] (refcount_sub_and_test_checked) from [<805050a0>] (refcount_dec_and_test_checked+0x18/0x1c)
[ 409.590663] [<805050a0>] (refcount_dec_and_test_checked) from [<8081e694>] (kobject_put+0x2c/0xd4)
[ 409.590683] [<8081e694>] (kobject_put) from [<805a5440>] (put_device+0x24/0x28)
[ 409.590711] [<805a5440>] (put_device) from [<7f640af8>] (ch341_usb_free_device.part.0+0xd8/0x12c [spi_ch341_usb])
[ 409.590743] [<7f640af8>] (ch341_usb_free_device.part.0 [spi_ch341_usb]) from [<7f641450>] (ch341_usb_probe+0x8bc/0xa58 [spi_ch341_usb])
[ 409.590768] [<7f641450>] (ch341_usb_probe [spi_ch341_usb]) from [<8062463c>] (usb_probe_interface+0x110/0x294)
[ 409.590788] [<8062463c>] (usb_probe_interface) from [<805aae78>] (really_probe+0x23c/0x2d4)
[ 409.590807] [<805aae78>] (really_probe) from [<805ab0e4>] (driver_probe_device+0x70/0x1ac)
[ 409.590826] [<805ab0e4>] (driver_probe_device) from [<805ab3f4>] (__device_attach_driver+0x98/0xa8)
[ 409.590843] [<805ab3f4>] (__device_attach_driver) from [<805a8ca8>] (bus_for_each_drv+0x88/0xcc)
[ 409.590860] [<805a8ca8>] (bus_for_each_drv) from [<805aabb8>] (__device_attach+0xe0/0x144)
[ 409.590878] [<805aabb8>] (__device_attach) from [<805ab420>] (device_initial_probe+0x1c/0x20)
[ 409.590895] [<805ab420>] (device_initial_probe) from [<805a9e7c>] (bus_probe_device+0x94/0x9c)
[ 409.590912] [<805a9e7c>] (bus_probe_device) from [<805a790c>] (device_add+0x468/0x600)
[ 409.590928] [<805a790c>] (device_add) from [<8062220c>] (usb_set_configuration+0x51c/0xa5c)
[ 409.590945] [<8062220c>] (usb_set_configuration) from [<8062db58>] (generic_probe+0x3c/0x88)
[ 409.590960] [<8062db58>] (generic_probe) from [<80624514>] (usb_probe_device+0x34/0x4c)
[ 409.590977] [<80624514>] (usb_probe_device) from [<805aae78>] (really_probe+0x23c/0x2d4)
[ 409.590995] [<805aae78>] (really_probe) from [<805ab0e4>] (driver_probe_device+0x70/0x1ac)
[ 409.591013] [<805ab0e4>] (driver_probe_device) from [<805ab3f4>] (__device_attach_driver+0x98/0xa8)
[ 409.591030] [<805ab3f4>] (__device_attach_driver) from [<805a8ca8>] (bus_for_each_drv+0x88/0xcc)
[ 409.591046] [<805a8ca8>] (bus_for_each_drv) from [<805aabb8>] (__device_attach+0xe0/0x144)
[ 409.591064] [<805aabb8>] (__device_attach) from [<805ab420>] (device_initial_probe+0x1c/0x20)
[ 409.591081] [<805ab420>] (device_initial_probe) from [<805a9e7c>] (bus_probe_device+0x94/0x9c)
[ 409.591097] [<805a9e7c>] (bus_probe_device) from [<805a790c>] (device_add+0x468/0x600)
[ 409.591117] [<805a790c>] (device_add) from [<80618534>] (usb_new_device+0x27c/0x450)
[ 409.591136] [<80618534>] (usb_new_device) from [<8061a048>] (hub_event+0xdc0/0x11d8)
[ 409.591156] [<8061a048>] (hub_event) from [<8013bf64>] (process_one_work+0x170/0x458)
[ 409.591174] [<8013bf64>] (process_one_work) from [<8013c2a8>] (worker_thread+0x5c/0x5a4)
[ 409.591191] [<8013c2a8>] (worker_thread) from [<80142594>] (kthread+0x138/0x168)
[ 409.591210] [<80142594>] (kthread) from [<801010ac>] (ret_from_fork+0x14/0x28)
[ 409.591217] Exception stack(0xb7257fb0 to 0xb7257ff8)
[ 409.591227] 7fa0: 00000000 00000000 00000000 00000000
[ 409.591239] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 409.591249] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000
[ 409.591259] ---[ end trace b7780a7e024bdc6f ]---
[ 409.591340] spi-ch341-usb: probe of 1-1.5.3:1.0 failed with error -17
Would be very helpful to get some instructions on how to build the driver for Arch linux. The kernel source layout seems to be different:
linux-headers /usr/lib/modules/4.15.5-1-ARCH/
and simply changing the Makefile to point to
KERNEL_DIR = /usr/lib/modules/4.15.5-1-ARCH
results in the error
make -C /usr/lib/modules/4.15.5-1-ARCH M=/home/user/tmp/spi-ch341-usb modules
make[1]: Entering directory '/usr/lib/modules/4.15.5-1-ARCH'
make[1]: *** No rule to make target 'modules'. Stop.
make[1]: Leaving directory '/usr/lib/modules/4.15.5-1-ARCH'
make: *** [Makefile:21: spi-ch341-usb.ko] Error 2
using kernel 5.16 make fails to build, here is the output:
make
make -C /lib/modules/5.16.8-arch1-1/build M=/home/winford/github/gschorcht/spi-ch341-usb modules
make[1]: Entering directory '/usr/lib/modules/5.16.8-arch1-1/build'
CC [M] /home/winford/github/gschorcht/spi-ch341-usb/spi-ch341-usb.o
/home/winford/github/gschorcht/spi-ch341-usb/spi-ch341-usb.c: In function ‘ch341_spi_probe’:
/home/winford/github/gschorcht/spi-ch341-usb/spi-ch341-usb.c:598:33: error: implicit declaration of function ‘spi_busnum_to_master’ [-Werror=implicit-function-declaration]
598 | while ((ch341_dev->master = spi_busnum_to_master(bus)))
| ^~~~~~~~~~~~~~~~~~~~
/home/winford/github/gschorcht/spi-ch341-usb/spi-ch341-usb.c:598:31: warning: assignment to ‘struct spi_controller *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
598 | while ((ch341_dev->master = spi_busnum_to_master(bus)))
| ^
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:287: /home/winford/github/gschorcht/spi-ch341-usb/spi-ch341-usb.o] Error 1
make[1]: *** [Makefile:1846: /home/winford/github/gschorcht/spi-ch341-usb] Error 2
make[1]: Leaving directory '/usr/lib/modules/5.16.8-arch1-1/build'
make: *** [Makefile:20: spi-ch341-usb.ko] Error 2
I tried using the patch from pull request #20 and can verify that fixes the problem and works well. Please take a look at that pull request.
Changes to the kernel build process have broken installation on Linux 5.4+ kernels.
DKMS make.log for spi-ch341-usb-1.0.0 for kernel 5.4.0-42-generic (x86_64)
Fri 31 Jul 08:56:46 BST 2020
make[1]: Entering directory '/usr/src/linux-headers-5.4.0-42-generic'
DESCEND objtool
/usr/src/linux-headers-5.4.0-42-generic/tools/build/Makefile.build:37: /usr/src/linux-headers-5.4.0-42-generic/tools/build/Build.include: No such file or directory
make[5]: *** No rule to make target '/usr/src/linux-headers-5.4.0-42-generic/tools/build/Build.include'. Stop.
make[4]: *** [Makefile:43: /usr/src/linux-headers-5.4.0-42-generic/tools/objtool/fixdep-in.o] Error 2
make[3]: *** [/usr/src/linux-headers-5.4.0-42-generic/tools/build/Makefile.include:5: fixdep] Error 2
make[2]: *** [Makefile:67: objtool] Error 2
make[1]: *** [Makefile:1835: tools/objtool] Error 2
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-42-generic'
if
and else
branches seem identical.SCK_H
and SCK_L
probably need to be swapped between the two lines.In order to use this in Ubuntu 22 I had to change i2c-ch341-usb.c line 660 from
ch341_dev->irq_descs[i] = irq_to_desc(ch341_dev->irq_base + i);
to
ch341_dev->irq_descs[i] = irq_data_to_desc(irq_get_irq_data(ch341_dev->irq_base + i));
After this it worked fine with my BME280 env sensor.
hi,
I found that WCH released a reference CH341 linux driver for PARA mode (include SPI, IIC, MEM ), you may get it from here: http://www.wch.cn/downloads/file/202.html.
And for the CH341 SPI speed, in the official forum, a thread told that CH341 has SPI speed fixed in hardware about 56KB/s, this might be the reason that "SCK clock frequency of about 400 kHz can be reached".
thanks for your code.
Hi,
Is there any plan to modify the driver to show up as a /dev/gpiochip0 entry instead of /sys/class/gpio?
And thanks again for your work! Maybe one day it will be mainlined :-)
I've used your driver for some time on my 20.04 Ubuntu Mate installation but when I had my co-worker build and install it on his 22.04 Ubuntu it builds but not show up as /dev/spi*.
Oddly after the build and insmod pluggin in the adapter gives promising dmesg output but the mentioned devices /dev/spidev* devices do not show up in /dev
[ 8027.352416] spi-ch341-usb 3-13:1.0: ch341_cfg_probe: output cs0 SPI slave with cs=0
[ 8027.352418] spi-ch341-usb 3-13:1.0: ch341_cfg_probe: output cs1 SPI slave with cs=1
[ 8027.352418] spi-ch341-usb 3-13:1.0: ch341_cfg_probe: output cs2 SPI slave with cs=2
[ 8027.352419] spi-ch341-usb 3-13:1.0: ch341_cfg_probe: input gpio4 gpio=0 irq=0 (hwirq)
[ 8027.352420] spi-ch341-usb 3-13:1.0: ch341_cfg_probe: input gpio5 gpio=1 irq=1
[ 8027.360517] spi-ch341-usb 3-13:1.0: ch341_spi_probe: SPI master connected to SPI bus 1
[ 8027.360669] spi-ch341-usb 3-13:1.0: ch341_spi_probe: SPI device /dev/spidev1.0 created
[ 8027.360682] spi-ch341-usb 3-13:1.0: ch341_spi_probe: SPI device /dev/spidev1.1 created
[ 8027.360692] spi-ch341-usb 3-13:1.0: ch341_spi_probe: SPI device /dev/spidev1.2 created
[ 8027.361041] spi-ch341-usb 3-13:1.0: ch341_usb_probe: connected
Any ideas on how to resolve this issue would be appreciated.
Thanks!
Miller
I just found out how to install these drivers on red hat-based distros: you just need to change the seventh line (the one that says KERNEL_DIR = /usr/src/linux-headers-$(KVERSION)/
) to KERNEL_DIR = /usr/src/kernels/$(KVERSION)/
Also make sure that you have kernel-devel installed by using sudo dnf install kernel-devel
Maybe the author could add some logic to the makefile to detect if it's being executed on a debian based distro (which is what this makefile seems to be aimed at) or a redhat based distro.
After I installed the driver, I don't see any /dev/spidev and I got these warnings in 'dmesg':
[11212.412026] spi_ch341_usb: Unknown symbol spi_unregister_device (err 0)
[11212.412046] spi_ch341_usb: Unknown symbol spi_finalize_current_transfer (err 0)
[11212.412075] spi_ch341_usb: Unknown symbol spi_unregister_controller (err 0)
[11212.412098] spi_ch341_usb: Unknown symbol __spi_alloc_controller (err 0)
[11212.412116] spi_ch341_usb: Unknown symbol spi_register_controller (err 0)
There were errors when compiling the driver. There was no definition of at least a function in spi.h. So I replaced it with another spi.h file. Then the compilation went through.
How can I fix this ?
I am on CentOS 7 (3.10.0-1127.19.1.el7.x86_64). I am using this board https://www.amazon.com/dp/B082KQ75QM/ref=cm_sw_em_r_mt_dp_-3cNFb8VTDVM3?_encoding=UTF8&psc=1
Thanks
Hi,
I have tested your driver on my electrodragon board:
http://www.zoobab.com/ch341-usb-spi-i2c-uart-isp-dongle#toc5
I could manage to see 4 gpios in sysfs with the following pinout on the board:
D4 = GPIO4
D2 = GPIO3
D1 = GPIO2
??? = GPIO5
Now, I am trying to use them with urjtag, that needs 4 GPIOs to have a JTAG cable, but it complains GPIO5 cannot be set.
Is there a way to have 4 usable GPIOs, or for now the maximum is 3?
Thanks again for your work.
Trying to make
and
make[1]: Entering directory '/usr/lib/modules/6.5.4-arch2-1/build'
CC [M] /home/sc/t/spi-ch341-usb/spi-ch341-usb.o
/home/sc/t/spi-ch341-usb/spi-ch341-usb.c:163:30: error: field 'gpio' has incomplete type
163 | struct gpio_chip gpio; // chip descriptor for GPIOs
| ^~~~
/home/sc/t/spi-ch341-usb/spi-ch341-usb.c: In function 'ch341_spi_probe':
/home/sc/t/spi-ch341-usb/spi-ch341-usb.c:598:33: error: implicit declaration of function 'spi_busnum_to_master' [-Werror=implicit-function-declaration]
598 | while ((ch341_dev->master = spi_busnum_to_master(bus)))
Around line 796, there's irq_to_desc which shouldn't be used in a module. afaik, it's for kernel use only.
See https://patchwork.kernel.org/project/linux-rdma/patch/[email protected]/
Kernel 5.10 and on won't export irq_to_desc any longer. As mentioned, it is to stop the abuse of it.
From now on this usage will only result in an undefined error:
ERROR: modpost: "irq_to_desc" [/home/sysghost/Sources/spi-ch341-usb/spi-ch341-usb.ko] undefined!
EDIT: More information about this:
https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/
I recommend the MIT license
Hello,
I would like to use the character device interface /dev/gpiochip1.
The sysfs interface works perfectly fine
# echo 1 > /sys/class/gpio/gpio0/value
# echo 0 > /sys/class/gpio/gpio0/value
but the character device is busy
# gpiodetect
gpiochip0 [INT345D:00] (203 lines)
gpiochip1 [ch341] (8 lines)
# gpioinfo gpiochip1
gpiochip1 - 8 lines:
line 0: "gpio0" "gpio0" output active-high [used]
line 1: "gpio1" "gpio1" output active-high [used]
line 2: "gpio2" "gpio2" output active-high [used]
line 3: "gpio3" "gpio3" output active-high [used]
line 4: "gpio4" "gpio4" input active-high [used]
line 5: "gpio5" "gpio5" input active-high [used]
line 6: "gpio6" "gpio6" input active-high [used]
line 7: "gpio7" "gpio7" input active-high [used]
# gpioset gpiochip1 0=1
gpioset: error setting the GPIO line values: Device or resource busy
I tried unexporting gpio0
# ls /sys/class/gpio/
export gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7 gpiochip301 gpiochip309 unexport
# echo 0 > /sys/class/gpio/unexport
bash: echo: write error: Invalid argument
Why are the gpio pin indices starting at 0 even though the controller base index is 301?
# cat /sys/class/gpio/gpiochip301/label
ch341
# cat /sys/class/gpio/gpiochip301/base
301
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.