wuxx / USB-HS-Bridge

81 stars 26 forks source link

Linux demo not working #1

Closed orangecms closed 2 years ago

orangecms commented 2 years ago

I compiled the kernel module, insmodded it, and changed the comments in the demo, then ran it.

However, I only get 0:

  Flash_ID: 0
>>Flash读:从[0]地址开始读入256字节...成功.用时0.001S
Read: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>>Flash写:从[0]地址开始写入260字节...成功.用时0.000S
>>Flash读:从[0]地址开始读入256字节...成功.用时0.001S
Read: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Close device succesed

As you can see, even the detection fails already.

The flash part is a GigaDevice, and it works fine with flashrom and a CH341A:

flashrom -p ch341a_spi
flashrom v1.2 on Linux 5.19.0-76051900-generic (x86_64)
flashrom is free software, get the source code at https://flashrom.org

Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns).
Found GigaDevice flash chip "GD25B128B/GD25Q128B" (16384 kB, SPI) on ch341a_spi.
Found GigaDevice flash chip "GD25Q127C/GD25Q128C" (16384 kB, SPI) on ch341a_spi.
Multiple flash chip definitions match the detected chip(s): "GD25B128B/GD25Q128B", "GD25Q127C/GD25Q128C"
Please specify which chip definition to use with the -c <chipname> option.
orangecms commented 2 years ago

I also tried including this library in the Rust implementation, see https://github.com/ma6254/ch347-rs/pull/5

It is hanging there in CH347SPI_Init.

ma6254 commented 2 years ago

The demo didn't work on my machine either, so I wrote a minimal test program

In any case, the CH347OpenDevice returns 0. There should be an internal problem with ch34x_pis.ko

How should I do this soft link operation https://github.com/ma6254/ch347-rs/pull/5#issue-1450197122 , is not work

Using kmod in this repo: https://github.com/orangecms/ch34x_pis/tree/CH347

test code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include "lib/x86_64/CH347SPILIB.h"

int main()
{
    ULONG dev_i = 0;
    int dev_fd = -1;
    BOOL ret = FALSE;

    dev_fd = CH347OpenDevice(dev_i);
    printf("dev_i=%ld dev_fd=%d\r\n", dev_i, dev_fd);
}

terminal output

➜  demo git:(master) ✗ ls /dev/ch34*
zsh: no matches found: /dev/ch34*
➜  demo git:(master) ✗ ./a.out      
open /dev/ch34x_pis error, LINE : 55
dev_i=0 dev_fd=0
➜  demo git:(master) ✗ ls /dev/ch34*
/dev/ch34x_pis0
➜  demo git:(master) ✗ ./a.out      
open /dev/ch34x_pis error, LINE : 55
dev_i=0 dev_fd=0

image

kmod ch34x_pis build output

➜  ch347_linux rm -rf CH34x_pis 
➜  ch347_linux git clone https://github.com/orangecms/CH34x_pis.git
Cloning into 'CH34x_pis'...
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 7 (delta 0), reused 2 (delta 0), pack-reused 4
Unpacking objects: 100% (7/7), 16.16 KiB | 8.08 MiB/s, done.
➜  ch347_linux cd CH34x_pis 
➜  CH34x_pis git:(master) make
make -C /lib/modules/5.13.0-41-generic/build  M=/home/mjc/prog/ch347_linux/CH34x_pis  
make[1]: Entering directory '/usr/src/linux-headers-5.13.0-41-generic'
  CC [M]  /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.o
In file included from ./include/linux/printk.h:7,
                 from ./include/linux/kernel.h:17,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:12,
                 from /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:17:
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c: In function ‘ch34x_write_bulk_callback’:
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:251:4: note: in expansion of macro ‘err’
  251 |    err("%s - nonzero write bulk status received: %d", __func__, urb->status );
      |    ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c: In function ‘ch34x_fops_read’:
./include/linux/kern_levels.h:5:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:15:20: note: in expansion of macro ‘KERN_SOH’
   15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
      |                    ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:37:13: note: in expansion of macro ‘KERN_DEBUG’
   37 |     printk( KERN_DEBUG "%s %d: " format "\n", __FILE__, __LINE__, ##arg )
      |             ^~~~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:290:2: note: in expansion of macro ‘dbg’
  290 |  dbg("count %d,->bytes_read %d,->mNewlen %d,->mBuffer[0] %d,->[1] %d,->[2]%d,->[3]%d",count,bytes_read,mNewlen,mBuffer[0],mBuffer[1],mBuffer[2],mBuffer[3]);
      |  ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:290:14: note: format string is defined here
  290 |  dbg("count %d,->bytes_read %d,->mNewlen %d,->mBuffer[0] %d,->[1] %d,->[2]%d,->[3]%d",count,bytes_read,mNewlen,mBuffer[0],mBuffer[1],mBuffer[2],mBuffer[3]);
      |             ~^
      |              |
      |              int
      |             %ld
In file included from ./include/linux/printk.h:7,
                 from ./include/linux/kernel.h:17,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:12,
                 from /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:17:
./include/linux/kern_levels.h:5:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘long unsigned int’ [-Wformat=]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:15:20: note: in expansion of macro ‘KERN_SOH’
   15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
      |                    ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:37:13: note: in expansion of macro ‘KERN_DEBUG’
   37 |     printk( KERN_DEBUG "%s %d: " format "\n", __FILE__, __LINE__, ##arg )
      |             ^~~~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:290:2: note: in expansion of macro ‘dbg’
  290 |  dbg("count %d,->bytes_read %d,->mNewlen %d,->mBuffer[0] %d,->[1] %d,->[2]%d,->[3]%d",count,bytes_read,mNewlen,mBuffer[0],mBuffer[1],mBuffer[2],mBuffer[3]);
      |  ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:290:30: note: format string is defined here
  290 |  dbg("count %d,->bytes_read %d,->mNewlen %d,->mBuffer[0] %d,->[1] %d,->[2]%d,->[3]%d",count,bytes_read,mNewlen,mBuffer[0],mBuffer[1],mBuffer[2],mBuffer[3]);
      |                             ~^
      |                              |
      |                              int
      |                             %ld
In file included from ./include/linux/printk.h:7,
                 from ./include/linux/kernel.h:17,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:12,
                 from /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:17:
./include/linux/kern_levels.h:5:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 6 has type ‘long unsigned int’ [-Wformat=]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:15:20: note: in expansion of macro ‘KERN_SOH’
   15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
      |                    ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:37:13: note: in expansion of macro ‘KERN_DEBUG’
   37 |     printk( KERN_DEBUG "%s %d: " format "\n", __FILE__, __LINE__, ##arg )
      |             ^~~~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:290:2: note: in expansion of macro ‘dbg’
  290 |  dbg("count %d,->bytes_read %d,->mNewlen %d,->mBuffer[0] %d,->[1] %d,->[2]%d,->[3]%d",count,bytes_read,mNewlen,mBuffer[0],mBuffer[1],mBuffer[2],mBuffer[3]);
      |  ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:290:43: note: format string is defined here
  290 |  dbg("count %d,->bytes_read %d,->mNewlen %d,->mBuffer[0] %d,->[1] %d,->[2]%d,->[3]%d",count,bytes_read,mNewlen,mBuffer[0],mBuffer[1],mBuffer[2],mBuffer[3]);
      |                                          ~^
      |                                           |
      |                                           int
      |                                          %ld
In file included from ./include/linux/printk.h:7,
                 from ./include/linux/kernel.h:17,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:12,
                 from /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:17:
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:306:3: note: in expansion of macro ‘err’
  306 |   err("bulk_in_buffer malloc error");
      |   ^~~
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:329:4: note: in expansion of macro ‘err’
  329 |    err("usb_bulk_msg out error");
      |    ^~~
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:343:4: note: in expansion of macro ‘err’
  343 |    err("usb_bulk_msg in error");
      |    ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c: In function ‘ch34x_fops_write’:
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:377:3: note: in expansion of macro ‘err’
  377 |   err("Data Overlimited,Must Under MAX_BUFFER_LENGTH");
      |   ^~~
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:458:4: note: in expansion of macro ‘err’
  458 |    err("%s - failed submitting write urb,line:%d",
      |    ^~~
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:513:3: note: in expansion of macro ‘err’
  513 |   err( "%s -failed to write submit urb,line:%d",
      |   ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c: In function ‘ch34x_WriteData’:
./include/linux/kern_levels.h:5:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘const char *’ [-Wformat=]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:615:3: note: in expansion of macro ‘err’
  615 |   err("%s - failed to submit writing urb,error %d,line %d",
      |   ^~~
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:615:3: note: in expansion of macro ‘err’
  615 |   err("%s - failed to submit writing urb,error %d,line %d",
      |   ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c: In function ‘ch34x_data_write_read’:
./include/linux/kern_levels.h:5:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:15:20: note: in expansion of macro ‘KERN_SOH’
   15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
      |                    ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:37:13: note: in expansion of macro ‘KERN_DEBUG’
   37 |     printk( KERN_DEBUG "%s %d: " format "\n", __FILE__, __LINE__, ##arg )
      |             ^~~~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:656:2: note: in expansion of macro ‘dbg’
  656 |  dbg("iLength is %d",iLength );
      |  ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:656:19: note: format string is defined here
  656 |  dbg("iLength is %d",iLength );
      |                  ~^
      |                   |
      |                   int
      |                  %ld
In file included from ./include/linux/printk.h:7,
                 from ./include/linux/kernel.h:17,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:12,
                 from /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:17:
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:659:3: note: in expansion of macro ‘err’
  659 |   err(" The length input error");
      |   ^~~
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:667:3: note: in expansion of macro ‘err’
  667 |   err("copy error");
      |   ^~~
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:738:3: note: in expansion of macro ‘err’
  738 |   err("%s-failed submitting write urb in write_read", __func__);
      |   ^~~
./include/linux/kern_levels.h:5:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 6 has type ‘long unsigned int’ [-Wformat=]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:15:20: note: in expansion of macro ‘KERN_SOH’
   15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
      |                    ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:37:13: note: in expansion of macro ‘KERN_DEBUG’
   37 |     printk( KERN_DEBUG "%s %d: " format "\n", __FILE__, __LINE__, ##arg )
      |             ^~~~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:744:2: note: in expansion of macro ‘dbg’
  744 |  dbg("mSave : %d, readtimes : %d, totallen : %d", mSave, readtimes, totallen);
      |  ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:744:47: note: format string is defined here
  744 |  dbg("mSave : %d, readtimes : %d, totallen : %d", mSave, readtimes, totallen);
      |                                              ~^
      |                                               |
      |                                               int
      |                                              %ld
In file included from ./include/linux/printk.h:7,
                 from ./include/linux/kernel.h:17,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:12,
                 from /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:17:
./include/linux/kern_levels.h:5:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:15:20: note: in expansion of macro ‘KERN_SOH’
   15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
      |                    ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:37:13: note: in expansion of macro ‘KERN_DEBUG’
   37 |     printk( KERN_DEBUG "%s %d: " format "\n", __FILE__, __LINE__, ##arg )
      |             ^~~~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:757:2: note: in expansion of macro ‘dbg’
  757 |  dbg("The actual length of Read is %d", totallen);
      |  ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:757:37: note: format string is defined here
  757 |  dbg("The actual length of Read is %d", totallen);
      |                                    ~^
      |                                     |
      |                                     int
      |                                    %ld
In file included from ./include/linux/printk.h:7,
                 from ./include/linux/kernel.h:17,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:12,
                 from /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:17:
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c: In function ‘ch34x_fops_open’:
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:813:3: note: in expansion of macro ‘err’
  813 |   err( "%s-error,cannot find device for minor :%d",
      |   ^~~
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:822:3: note: in expansion of macro ‘err’
  822 |   err("Get interface data error");
      |   ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c: In function ‘ch34x_fops_ioctl’:
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:905:6: note: in expansion of macro ‘err’
  905 |      err("CH34x_FUNCTION_SETPARA_MODE Error");
      |      ^~~
./include/linux/kern_levels.h:5:18: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:15:20: note: in expansion of macro ‘KERN_SOH’
   15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
      |                    ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:37:13: note: in expansion of macro ‘KERN_DEBUG’
   37 |     printk( KERN_DEBUG "%s %d: " format "\n", __FILE__, __LINE__, ##arg )
      |             ^~~~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:906:5: note: in expansion of macro ‘dbg’
  906 |     dbg("------>SetParaMode - ch34x_arg %x", ch34x_arg);
      |     ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:906:42: note: format string is defined here
  906 |     dbg("------>SetParaMode - ch34x_arg %x", ch34x_arg);
      |                                         ~^
      |                                          |
      |                                          unsigned int
      |                                         %lx
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:947:44: warning: passing argument 2 of ‘copy_from_user’ makes pointer from integer without a cast [-Wint-conversion]
  947 |     if (copy_from_user(&bytes_write, rwData.oReadlen, sizeof(bytes_write) ) ){
      |                                      ~~~~~~^~~~~~~~~
      |                                            |
      |                                            long unsigned int
In file included from ./include/linux/sched/task.h:11,
                 from ./include/linux/sched/signal.h:9,
                 from ./include/linux/rcuwait.h:6,
                 from ./include/linux/percpu-rwsem.h:7,
                 from ./include/linux/fs.h:33,
                 from ./include/linux/poll.h:10,
                 from /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:22:
./include/linux/uaccess.h:189:45: note: expected ‘const void *’ but argument is of type ‘long unsigned int’
  189 | copy_from_user(void *to, const void __user *from, unsigned long n)
      |                          ~~~~~~~~~~~~~~~~~~~^~~~
In file included from ./include/linux/printk.h:7,
                 from ./include/linux/kernel.h:17,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:12,
                 from /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:17:
./include/linux/kern_levels.h:5:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:15:20: note: in expansion of macro ‘KERN_SOH’
   15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
      |                    ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:37:13: note: in expansion of macro ‘KERN_DEBUG’
   37 |     printk( KERN_DEBUG "%s %d: " format "\n", __FILE__, __LINE__, ##arg )
      |             ^~~~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:969:5: note: in expansion of macro ‘dbg’
  969 |     dbg("Input number is %d",rwData.oReadlen);
      |     ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:969:27: note: format string is defined here
  969 |     dbg("Input number is %d",rwData.oReadlen);
      |                          ~^
      |                           |
      |                           int
      |                          %ld
In file included from ./include/linux/printk.h:7,
                 from ./include/linux/kernel.h:17,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:12,
                 from /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:17:
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:974:6: note: in expansion of macro ‘err’
  974 |      err("Read Error");
      |      ^~~
./include/linux/kern_levels.h:5:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:15:20: note: in expansion of macro ‘KERN_SOH’
   15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
      |                    ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:37:13: note: in expansion of macro ‘KERN_DEBUG’
   37 |     printk( KERN_DEBUG "%s %d: " format "\n", __FILE__, __LINE__, ##arg )
      |             ^~~~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:977:5: note: in expansion of macro ‘dbg’
  977 |     dbg("Read bytes is %d", bytes_read);
      |     ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:977:25: note: format string is defined here
  977 |     dbg("Read bytes is %d", bytes_read);
      |                        ~^
      |                         |
      |                         int
      |                        %ld
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:979:33: warning: passing argument 1 of ‘copy_to_user’ makes pointer from integer without a cast [-Wint-conversion]
  979 |     retval = copy_to_user(rwData.oReturnlen,  &bytes_read,sizeof(unsigned long));
      |                           ~~~~~~^~~~~~~~~~~
      |                                 |
      |                                 long unsigned int
In file included from ./include/linux/sched/task.h:11,
                 from ./include/linux/sched/signal.h:9,
                 from ./include/linux/rcuwait.h:6,
                 from ./include/linux/percpu-rwsem.h:7,
                 from ./include/linux/fs.h:33,
                 from ./include/linux/poll.h:10,
                 from /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:22:
./include/linux/uaccess.h:197:27: note: expected ‘void *’ but argument is of type ‘long unsigned int’
  197 | copy_to_user(void __user *to, const void *from, unsigned long n)
      |              ~~~~~~~~~~~~~^~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:960:19: warning: unused variable ‘addr’ [-Wunused-variable]
  960 |     unsigned long addr;
      |                   ^~~~
In file included from ./include/linux/printk.h:7,
                 from ./include/linux/kernel.h:17,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:12,
                 from /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:17:
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:988:6: note: in expansion of macro ‘err’
  988 |      err("Init Parallel Error");
      |      ^~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:858:6: warning: unused variable ‘err’ [-Wunused-variable]
  858 |  int err = 0;
      |      ^~~
In file included from ./include/linux/printk.h:7,
                 from ./include/linux/kernel.h:17,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:12,
                 from /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:17:
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c: In function ‘ch34x_pis_probe’:
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:1040:3: note: in expansion of macro ‘err’
 1040 |   err("Out of Memory");
      |   ^~~
./include/linux/kern_levels.h:5:18: warning: too many arguments for format [-Wformat-extra-args]
    5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
      |                  ^~~~~~
./include/linux/kern_levels.h:11:18: note: in expansion of macro ‘KERN_SOH’
   11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
      |                  ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:43:13: note: in expansion of macro ‘KERN_ERR’
   43 |     printk( KERN_ERR KBUILD_MODNAME ":" format "\n", __FILE__, __LINE__, ##arg)
      |             ^~~~~~~~
/home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.c:1092:3: note: in expansion of macro ‘err’
 1092 |   err( "usb_get_dev error,disable to use this device" );
      |   ^~~
  MODPOST /home/mjc/prog/ch347_linux/CH34x_pis/Module.symvers
  CC [M]  /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.mod.o
  LD [M]  /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.ko
  BTF [M] /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.ko
Skipping BTF generation for /home/mjc/prog/ch347_linux/CH34x_pis/ch34x_pis.ko due to unavailability of vmlinux
make[1]: Leaving directory '/usr/src/linux-headers-5.13.0-41-generic'
➜  CH34x_pis git:(master) ✗ sudo make load 
modprobe usbserial
insmod ch34x_pis.ko
➜  CH34x_pis git:(master) ✗ cd ../USB-HS-Bridge/doc/CH347SPI_LINUX_VTEST/demo 
➜  demo git:(master) ✗ ./a.out
open /dev/ch34x_pis error, LINE : 55
dev_i=0 dev_fd=0
➜  demo git:(master) ✗ 
➜  demo git:(master) ✗ ./a.out
open /dev/ch34x_pis error, LINE : 55
dev_i=0 dev_fd=0
➜  demo git:(master) ✗ 
orangecms commented 2 years ago

The updated driver is in the CH347 branch. Note that is coming from this repository's tar archive, so you can as well use that directly.

The closed source library is looking for /dev/ch34x_pis, but the driver only creates /dev/ch34x_pis0, hence the symlink as described in the issue on the Rust repo. On most systems, you'd need to be root in order to create it.

wuxx commented 2 years ago

https://github.com/wuxx/USB-HS-Bridge/blob/master/doc/CH347PAR_Linux_V1.01.zip

wuxx commented 2 years ago

hello, just commit the latest SDK under Linux, got from WCH technical support, please try it, thanks~!

ma6254 commented 2 years ago

CH347PAR_Linux_V1.01 it's worked !!!

orangecms commented 2 years ago

We added it and with a fixup, I got the GPIOs to work in the Rust :crab: tool: https://github.com/ma6254/ch347-rs/pull/7

Some methods are still missing in the Linux library, but it's basically working, so I'm closing this for now. Thank you!