页次: 1
我换了一个驱动,驱动内部设计到了SPI总线的设备添加,下面是装载驱动之后,然后插入USB设备,成功识别后打印一下信息
[ 34.254274] usb 2-1: new full-speed USB device number 2 using ohci-platform
[ 34.521700] spi-ch341-usb 2-1:1.0: ch341_cfg_probe: output cs0 SPI slave with cs=0
[ 34.529412] spi-ch341-usb 2-1:1.0: ch341_cfg_probe: output cs1 SPI slave with cs=1
[ 34.537011] spi-ch341-usb 2-1:1.0: ch341_cfg_probe: output cs2 SPI slave with cs=2
[ 34.544597] spi-ch341-usb 2-1:1.0: ch341_cfg_probe: input gpio4 gpio=0 irq=0 (hwirq)
[ 34.552418] spi-ch341-usb 2-1:1.0: ch341_cfg_probe: input gpio5 gpio=1 irq=1
[ 34.559671] spi-ch341-usb 2-1:1.0: ch341_spi_probe: SPI master connected to SPI bus 1
[ 34.602516] spi-ch341-usb 2-1:1.0: ch341_spi_probe: SPI device /dev/spidev1.0 created
[ 34.620437] spi-ch341-usb 2-1:1.0: ch341_spi_probe: SPI device /dev/spidev1.1 created
[ 34.647415] spi-ch341-usb 2-1:1.0: ch341_spi_probe: SPI device /dev/spidev1.2 created
[ 34.684678] spi-ch341-usb 2-1:1.0: ch341_usb_probe: connected
但是我没找到在dev没有找到设备节点,驱动说明是会自动创建的,在bus目录下我也找到了
/ # find ./ -name "spi*"
./spi-ch341-usb.ko
./sys/devices/platform/soc/1c68000.spi/spi_master
./sys/devices/platform/soc/1c68000.spi/spi_master/spi0
./sys/devices/platform/soc/1c68000.spi/spi_master/spi0/spi0.0
./sys/devices/platform/soc/1c68000.spi/spi_master/spi0/spi0.0/statistics/spi_sync
./sys/devices/platform/soc/1c68000.spi/spi_master/spi0/spi0.0/statistics/spi_async
./sys/devices/platform/soc/1c68000.spi/spi_master/spi0/spi0.0/statistics/spi_sync_immediate
./sys/devices/platform/soc/1c68000.spi/spi_master/spi0/statistics/spi_sync
./sys/devices/platform/soc/1c68000.spi/spi_master/spi0/statistics/spi_async
./sys/devices/platform/soc/1c68000.spi/spi_master/spi0/statistics/spi_sync_immediate
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/statistics/spi_sync
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/statistics/spi_async
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/statistics/spi_sync_immediate
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/spi1.1
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/spi1.1/statistics/spi_sync
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/spi1.1/statistics/spi_async
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/spi1.1/statistics/spi_sync_immediate
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/spi1.2
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/spi1.2/statistics/spi_sync
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/spi1.2/statistics/spi_async
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/spi1.2/statistics/spi_sync_immediate
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/spi1.0
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/spi1.0/statistics/spi_sync
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/spi1.0/statistics/spi_async
./sys/devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/spi_master/spi1/spi1.0/statistics/spi_sync_immediate
./sys/class/spi_master
./sys/class/spi_master/spi0
./sys/class/spi_master/spi1
./sys/firmware/devicetree/base/soc/pinctrl@01c20800/spi0
./sys/firmware/devicetree/base/soc/spi@1c68000
./sys/firmware/devicetree/base/soc/spi@1c68000/w25q128@0/spi-max-frequency
./sys/firmware/devicetree/base/soc/spi@1c68000/spi-max-frequency
./sys/bus/platform/drivers/spi_gpio
./sys/bus/spi
./sys/bus/spi/devices/spi0.0
./sys/bus/spi/devices/spi1.1
./sys/bus/spi/devices/spi1.2
./sys/bus/spi/devices/spi1.0
./sys/bus/spi/drivers/m25p80/spi0.0
./sys/bus/usb/drivers/spi-ch341-usb
./sys/module/spi_ch341_usb
晕哥有没有什么解决办法,在线等急,谢谢回复
还有我发现应用层传递整形的指针地址给驱动层,驱动层只是访问该指针地址也出错了,总感觉问题不简单,如果问题出在内核那基本上无法解决了。。。
int retval = 0;
ULONG mLength, mReadlen;
ULONG iReadStep,iReadTimes;
struct{
ULONG oReadlen;
PUCHAR iBuf;
PUCHAR oBuffer;
ULONG oReturnlen;
}Read;
iReadStep =*(PUCHAR)(iWriteBuffer+iWriteLength-8);
iReadTimes = *(PUCHAR)(iWriteBuffer+iWriteLength-4);
mReadlen = iReadStep * iReadTimes;
if( mReadlen == 0 )
return false;
mLength = max( iWriteLength, mReadlen );
#if 0
printf("iWriteLength : %d\n",iWriteLength);
printf("iReadTimes : %d\n",iReadTimes);
printf("iReadStep : %d\n",iReadStep);
#endif
Read.iBuf = (PUCHAR)iWriteBuffer;
Read.oBuffer = (PUCHAR)oReadBuffer;
Read.oReturnlen = *oReadLength;
// printf("iBuffer Addr is ------>:%p\n",Read.iBuf);
Read.oReadlen = iWriteLength;
retval = ioctl( dev_fd, CH34x_PIPE_WRITE_READ, (unsigned long)&Read );
if( retval == -1 )
{
printf("Error in pipe write/read\n");
return false;
}
........................
驱动层
long ch34x_fops_ioctl( struct file *file, unsigned int ch34x_cmd,
unsigned long ch34x_arg )
...........................
case CH34x_PIPE_WRITE_READ:
{
unsigned long addr;
dbg("------> Use Pipe Date Write/Read\n");
dbg("????????????????????????????????");
dbg("Input number is %ld\n",*((unsigned long *)ch34x_arg)); //问题点
dbg("????????????????????????????????");
addr = (unsigned long)*(((long *)ch34x_arg) + 1 );
dbg("????????????????????????????????");
bytes_read = ch34x_data_write_read( *((unsigned long *)ch34x_arg),
(unsigned long)*(((long *)ch34x_arg) + 1),
*(((long *)ch34x_arg) + 2),ch34x_pis_tmp );
..........................
1035.572690] /home/yjy/samba/v3s/CH341PAR_LINUX/driver/ch34x_pis.c 886: ------> 2 Chip Version is sucessful 0xc00
VendorId : 0xc000[ 1035.583713] /home/yjy/samba/v3s/CH341PAR_LINUX/driver/ch34x_pis.c 941: ------> Use Pipe Date Write/Read
[ 1035.583713]
[ 1035.596143] /home/yjy/samba/v3s/CH341PAR_LINUX/driver/ch34x_pis.c 942: ????????????????????????????????
[ 1035.605616] Unhandled fault: page domain fault (0x01b) at 0xbeca7874
[ 1035.611962] pgd = c31b4000
[ 1035.614665] [beca7874] *pgd=430b9835, *pte=42d8175f, *ppte=42d81c7f
[ 1035.620940] Internal error: : 1b [#5] SMP ARM
[ 1035.625290] Modules linked in: ch34x_pis(O) [last unloaded: ch34x_pis]
[ 1035.631821] CPU: 0 PID: 219 Comm: test Tainted: G D W O 4.14.14-licheepi-zero #6
[ 1035.639984] Hardware name: Allwinner sun8i Family
[ 1035.644681] task: c3a32280 task.stack: c3be2000
[ 1035.649219] PC is at ch34x_fops_ioctl+0x370/0xc08 [ch34x_pis]
[ 1035.654959] LR is at ch34x_fops_ioctl+0x368/0xc08 [ch34x_pis]
[ 1035.660697] pc : [<bf01525c>] lr : [<bf015254>] psr: 600e0013
[ 1035.666953] sp : c3be3ed0 ip : 00000000 fp : 00000000
[ 1035.672170] r10: 00000000 r9 : c3be2000 r8 : beca7874
[ 1035.677387] r7 : 00000003 r6 : c3270300 r5 : c391f100 r4 : beca7874
[ 1035.683904] r3 : c0a0c458 r2 : c0a0c458 r1 : 000061bc r0 : 00006764
[ 1035.690423] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none
[ 1035.697547] Control: 10c5387d Table: 431b406a DAC: 00000051
[ 1035.703283] Process test (pid: 219, stack limit = 0xc3be2210)
[ 1035.709020] Stack: (0xc3be3ed0 to 0xc3be4000)
[ 1035.713373] 3ec0: c03bfb94 00024008 c3be3f80 00000000
[ 1035.721541] 3ee0: 00000012 00000000 beca7890 c01f9034 c0951a40 c0951a40 00000002 00000048
[ 1035.729708] 3f00: ffffffff c30ba000 00000001 beca7874 c30b2350 c3270300 00000003 beca7874
[ 1035.737876] 3f20: c3be2000 00000000 00000000 c020a8e8 c3be3f8c c31ff300 00000000 c3b961c0
[ 1035.746043] 3f40: 00000002 00000012 c31ff308 00000000 beca7890 c01f9330 00000000 00000000
[ 1035.754211] 3f60: c30b2350 c31ff300 c31ff300 00000000 c3270300 00000003 c3270300 0000000a
[ 1035.762378] 3f80: beca7874 c3be2000 00000000 c020b174 00000001 00000000 00000000 00000036
[ 1035.770545] 3fa0: c0107964 c0107780 00000001 00000000 00000003 0000000a beca7874 00000003
[ 1035.778712] 3fc0: 00000001 00000000 00000000 00000036 00000000 00000000 b6f1e000 00000000
[ 1035.786880] 3fe0: 00023b74 beca785c 00010ddf b6e98166 000e0030 00000003 00000000 00000000
[ 1035.795074] [<bf01525c>] (ch34x_fops_ioctl [ch34x_pis]) from [<c020a8e8>] (do_vfs_ioctl+0x9c/0x8f4)
[ 1035.804118] [<c020a8e8>] (do_vfs_ioctl) from [<c020b174>] (SyS_ioctl+0x34/0x5c)
[ 1035.811426] [<c020b174>] (SyS_ioctl) from [<c0107780>] (ret_fast_syscall+0x0/0x54)
[ 1035.818990] Code: e34b0f01 eb452ca4 e30611bc e3060764 (e5943000)
[ 1035.825078] ---[ end trace d40a735d917cf97a ]---
Segmentation fault
ch34x_fops_write 调用了 memcpy
估计 memcpy 的 第一个参数的指针指向的区域非法。
未初始化?或者已经被释放?
看了一下程序流程,在获取设备信息的“usb_control_msg”函数上就出了问题了,下面是打印log,不知道是不是usb_hcd_map_urb_for_dma这个内核函数,这是内核USB总线上的问题吗,感觉上越来越多,不清楚是这个驱动问题还是内核问题,如果是内核问题,我估计得放弃这种通讯方式了,晕哥你的建议是?
/nfs/v3s/CH341PAR_LINUX/demo # ./test[ 88.674253] usb 2-1: new full-speed USB device number 3 using ohci-platform
dev_path:/dev/ch34x_pis0[ 121.513736] ------------[ cut here ]------------
Open sucessfuldrv_version : WCH CH34x Driver Version V0.1
[ 121.520345] WARNING: CPU: 0 PID: 172 at drivers/usb/core/hcd.c:1598 usb_hcd_map_urb_for_dma+0x55c/0x674
[ 121.534963] transfer buffer is on stack
[ 121.538795] Modules linked in: ch34x_pis(O)
[ 121.542986] CPU: 0 PID: 172 Comm: test Tainted: G O 4.14.14-licheepi-zero #6
[ 121.551149] Hardware name: Allwinner sun8i Family
[ 121.555880] [<c010e808>] (unwind_backtrace) from [<c010b53c>] (show_stack+0x10/0x14)
[ 121.563625] [<c010b53c>] (show_stack) from [<c068b63c>] (dump_stack+0x84/0x98)
[ 121.570850] [<c068b63c>] (dump_stack) from [<c011b7e8>] (__warn+0xe8/0x100)
[ 121.577809] [<c011b7e8>] (__warn) from [<c011b838>] (warn_slowpath_fmt+0x38/0x48)
[ 121.585288] [<c011b838>] (warn_slowpath_fmt) from [<c048f228>] (usb_hcd_map_urb_for_dma+0x55c/0x674)
[ 121.594416] [<c048f228>] (usb_hcd_map_urb_for_dma) from [<c048f66c>] (usb_hcd_submit_urb+0x13c/0x888)
[ 121.603627] [<c048f66c>] (usb_hcd_submit_urb) from [<c04913cc>] (usb_start_wait_urb+0x4c/0xbc)
[ 121.612230] [<c04913cc>] (usb_start_wait_urb) from [<c04914dc>] (usb_control_msg+0xa0/0xcc)
[ 121.620582] [<c04914dc>] (usb_control_msg) from [<bf001698>] (ch34x_fops_ioctl+0x7ac/0xc50 [ch34x_pis])
[ 121.629973] [<bf001698>] (ch34x_fops_ioctl [ch34x_pis]) from [<c020a8e8>] (do_vfs_ioctl+0x9c/0x8f4)
[ 121.639013] [<c020a8e8>] (do_vfs_ioctl) from [<c020b174>] (SyS_ioctl+0x34/0x5c)
[ 121.646319] [<c020b174>] (SyS_ioctl) from [<c0107780>] (ret_fast_syscall+0x0/0x54)
[ 121.654032] ---[ end trace f58cb1ddabf1019c ]---
VendorId : 0x0000
安装之ch341是驱动?串口?
从官网下载的CH341 USB转SPI驱动,编译好了之后,尝试运行,就出现下面的错误
/dev # echo "fsdf" > ch34x_pis0
[ 114.877628] Unhandled fault: page domain fault (0x01b) at 0x000c51d8
[ 114.883993] pgd = c30ac000
[ 114.886697] [000c51d8] *pgd=43041835, *pte=409d475f, *ppte=409d4c7f
[ 114.892971] Internal error: : 1b [#1] SMP ARM
[ 114.897322] Modules linked in: ch34x_pis(O)
[ 114.901511] CPU: 0 PID: 124 Comm: sh Tainted: G O 4.14.14-licheepi-zero #6
[ 114.909500] Hardware name: Allwinner sun8i Family
[ 114.914197] task: c3a32e00 task.stack: c30e6000
[ 114.918734] PC is at memcpy+0xe4/0x330
[ 114.922490] LR is at ch34x_fops_write+0x3f8/0x558 [ch34x_pis]
[ 114.928226] pc : [<c0689d24>] lr : [<bf0007f0>] psr: 20070013
[ 114.934484] sp : c30e7eac ip : 00000003 fp : 000914e8
[ 114.939700] r10: 00000000 r9 : 00000000 r8 : 00000000
[ 114.944917] r7 : 000c51d8 r6 : 00000006 r5 : c30f84c0 r4 : c30ed500
[ 114.951434] r3 : 00000005 r2 : 00000001 r1 : 000c51d8 r0 : c30f84c1
[ 114.957953] Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none
[ 114.965077] Control: 10c5387d Table: 430ac06a DAC: 00000051
[ 114.970813] Process sh (pid: 124, stack limit = 0xc30e6210)
[ 114.976378] Stack: (0xc30e7eac to 0xc30e8000)
[ 114.980732] 7ea0: c30f84c1 c30ed500 bf0007f0 00000054 c0112ab8
[ 114.988899] 7ec0: 00000005 00000005 00000000 c303f900 bf0003f8 000c51d8 c30e7f80 00000000
[ 114.997067] 7ee0: 00000005 00000000 000914e8 c01f9034 00000007 c011281c 000678a8 c30e7fb0
[ 115.005234] 7f00: 000c3274 00000000 000914e8 c010138c 00000000 00000000 00000000 00000000
[ 115.013402] 7f20: 00000000 c3a32e00 c011daa8 00000100 00000200 fffffff6 c303f900 00000005
[ 115.021570] 7f40: 000c51d8 c30e7f80 00000000 00000005 00000000 c01f92b4 0000000a 00000406
[ 115.029737] 7f60: 00000001 c303f900 c303f900 00000000 00000000 000c51d8 00000005 c01f9478
[ 115.037904] 7f80: 00000000 00000000 00000006 000c2d6c 00000001 000c51d8 00000004 c0107964
[ 115.046072] 7fa0: c30e6000 c0107780 000c2d6c 00000001 00000001 000c51d8 00000005 00000000
[ 115.054239] 7fc0: 000c2d6c 00000001 000c51d8 00000004 000c51d8 00000020 00000000 000914e8
[ 115.062407] 7fe0: 00000000 be9a7644 00019eac b6f60056 20070030 00000001 00000000 00000000
[ 115.070598] [<c0689d24>] (memcpy) from [<bf0007f0>] (ch34x_fops_write+0x3f8/0x558 [ch34x_pis])
[ 115.079212] [<bf0007f0>] (ch34x_fops_write [ch34x_pis]) from [<c01f9034>] (__vfs_write+0x1c/0x128)
[ 115.088164] [<c01f9034>] (__vfs_write) from [<c01f92b4>] (vfs_write+0xa4/0x168)
[ 115.095468] [<c01f92b4>] (vfs_write) from [<c01f9478>] (SyS_write+0x3c/0x90)
[ 115.102517] [<c01f9478>] (SyS_write) from [<c0107780>] (ret_fast_syscall+0x0/0x54)
[ 115.110082] Code: 24c0c001 e8bd8011 e26cc004 e35c0002 (c4d13001)
[ 115.116169] ---[ end trace aadf6533c2b1c6a0 ]---
好像错误出现在open上,贴上源码
int ch34x_fops_open(struct inode *inode, struct file *file)
{
struct ch34x_pis *ch34x_p;
struct usb_interface *interface;
int retval = 0;
unsigned int subminor;
#if( LINUX_VERSION_CODE < KERNEL_VERSION( 2, 6, 35) )
subminor = iminor( inode );
#else
subminor = iminor( file->f_path.dentry->d_inode );
#endif
interface = usb_find_interface( &ch34x_pis_driver, subminor );
if ( !interface )
{
err( "%s-error,cannot find device for minor :%d",
__func__, subminor);
retval = -ENODEV;
goto exit;
}
ch34x_p = usb_get_intfdata( interface );
if( !ch34x_p )
{
err("Get interface data error");
retval = -ENODEV;
goto exit;
}
/* add the usage for device*/
kref_get( &ch34x_p->kref );
mutex_lock( &io_mutex );
if( !ch34x_p->open_count++ )
{
retval = usb_autopm_get_interface( interface );
if( retval )
{
ch34x_p->open_count--;
mutex_unlock( &io_mutex );
kref_put( &ch34x_p->kref, skel_delete );
goto exit;
}
}
file->private_data = ch34x_p;
mutex_unlock( &io_mutex );
exit:
return retval;
}
不知道晕哥看不看得懂
后面想试试内核自带的,结果内核自带的没编译通过,驱动层的东西很难受
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make modules
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make modules_install INSTALL_MOD_PATH=$PWD/../module先执行前面那个命令, 再执行后面的, 就可以了。
make ARCH=arm menuconfig先菜单选中
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make modules
scripts/kconfig/conf --silentoldconfig Kconfig
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CHK include/generated/bounds.h
CHK include/generated/timeconst.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
CHK scripts/mod/devicetable-offsets.h
Building modules, stage 2.
MODPOST 3 modules
@ubuntu:~/samba/v3s/linux-zero-4.14.y$
@ubuntu:~/samba/v3s/linux-zero-4.14.y$
@ubuntu:~/samba/v3s/linux-zero-4.14.y$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make modules_install INSTALL_MOD_PATH=$PWD/../module
INSTALL crypto/echainiv.ko
INSTALL drivers/staging/rtl8723bs/r8723bs.ko
INSTALL drivers/video/backlight/lcd.ko
DEPMOD 4.14.14-licheepi-zero
结果还是没有。。。泪奔
还有一个以为
就是我在linux-zero-4.14.y编译驱动模块
使用命令如下:
make ARCH=arm menuconfig
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make modules_install INSTALL_MOD_PATH=$PWD/../module
无论怎么菜单里加使能驱动模块,一直都是编译出下面这几个模块
INSTALL crypto/echainiv.ko
INSTALL drivers/staging/rtl8723bs/r8723bs.ko
INSTALL drivers/video/backlight/lcd.ko
DEPMOD 4.14.14-licheepi-zero
求解答。
我前面可能说错了, 你检查 PF6 引脚电平状态.
作为 HOST 估计是要上拉.
https://whycan.cn/t_561.html
https://whycan.cn/files/members/3/lichee_zero-new.pdf
谢谢回复
我昨晚好像也确认错了,我这边的PF6是按照lichee_zero-new.pdf原理图上一样,加上一个上拉电阻持续拉高的,不好意思,那在PF6拉高烧录正常的情况,是不是PF6拉低才是作为HOST?
g_serial 可以用
感谢云哥
yangzl 说:晕哥 说:@yangzl 先接 PB8, PB9 看是否有输出, 再谋划改代码吧。
尝试过将原有可用的固件烧写进去,用示波器查看PB8和PB9的电平输出,没有丝毫波动,应该是uboot并没有启动成功吧
注意: sunxi-fel 烧录的时候 不需要再短路 spi 的引脚了
sunxi-fel 没有校验机制, 到之后也不知道有没有写进去, 写进去的对不对,
你不接 flash, 他一样能告诉你写入成功。sunxi-fel 的 read 功能貌似也有问题, 读的数据不对。
接逻辑分析仪或者 USB串口模块试一试.
至少能启动 u-boot 最开始的 spl(boot0),
这里有几行串口输出。最后, 你交换一下 荔枝派(能正常启动的板子)的flash测试。
在使用sunxi-fel烧录前都会使用“sunxi-fei spiflash-info”命令确认能否读取到flash芯片信息后再进行烧写,短接SPI引脚使用镊子短接,识别到就松开了。
然后在确认荔枝派开发板上的固件可以正常串口输出后,把两块板子的flash更换,结果发现SPI引脚都没有读取了,如图。
黄线DO,紫线是DI。
之前一块flash在荔枝派上重新烧写并检测能用,再更换回去,还是如上图......
我的内心好绝望。。。
感谢回复
页次: 1