我给我自己放了个暑假后本周也开学了,我在书架上浏览找事做的时候,发现了十年前买的<圈圈教你学USB>,十年前我用51+usb芯片做过一个小鼠标,原理图及焊接都是我自己做的,但是现在已经把usb协议忘记了。我的老本行是做通信的,也可以说是做与业务无关的中间件,那么usb通信也和我有点关系,再加上我需要培养我自己的视觉全栈工程师的技术能力,说不定有usb camera的技能需求,我看了usb协议文档(2.0)的,现在usb 4.0都出来的。主要是了解下usb通信原理。然后就开始动手咯~
网上下载最新的5.8.5版本,结果和我之前学习的TI的4.1版本区别很大。我就先按我的理解配置了usb host部分。
问题:bb black开发板的usb1作为host device识别不了
那么开始查问题【有问题让我查,这是我觉得最有挑战的时刻的,福尔摩斯AppleCai上场咯】
- 看设备树是否匹配,结果发现compliance的关键字都改了。使用了ti-sysc。网上搜索了下changelog,原来现在统一有sysc bus来初始化所有ti外设驱动。为了降低调查难度,我通过changelog发现5.4版本还是和4.1版本一样的。5.5设备树就修改为了ti-sysc了。
- 于是降低难度,采用5.4版本进行移植,添加usb驱动,结果依然识别不了device,首先调查设备树是否匹配,检查conpliance正确,并且state=okey。那么是什么原因呢?
- 首先查看usb文件夹及musb文件夹包括makefile,并且确定了musb-hdrc是和usb host相关的c文件。学习了解各种c文件的函数。来检查对应的配置设置。修改配置后依然无法识别usb host。
- 复习了下设备树probe的调用流程和函数,都是在drivers/bus文件夹下的。总的来说就是都添加到bus后,若有驱动添加则检查对应的设备进行match,若有设备添加则检查对应的驱动绑定。
通过在probe函数添加dev_info打印go here消息,结果usb host的go here没有走到。难道是probe不成功,到底哪个环节出问题了,不是只要设备树名字一致就可以匹配了吗? -
只能靠打印了,通过查看具体代码,它里面有很多pr_debug函数。配置Device Driver下的DEBUG_DRIVER。
打开后可以看到如下信息
[ 1.264434] Registering platform device 'musb-hdrc.1'. Parent at 47401c00.usb
[ 1.264440] device: 'musb-hdrc.1': device_add
[ 1.264459] bus: 'platform': add device musb-hdrc.1
[ 1.264491] PM: Adding info for platform:musb-hdrc.1
[ 1.264693] bus: 'platform': driver_probe_device: matched device musb-hdrc.1 with driver musb-hdrc
[ 1.264703] bus: 'platform': really_probe: probing driver musb-hdrc with device musb-hdrc.1
[ 1.264859] platform musb-hdrc.1: Driver musb-hdrc requests probe deferral
[ 1.264867] platform musb-hdrc.1: Added to deferred list
[ 1.264879] bus: 'platform': driver_probe_device: matched device musb-hdrc.1 with driver musb-dsps
[ 1.264887] bus: 'platform': really_probe: probing driver musb-dsps with device musb-hdrc.1
[ 1.264924] musb-dsps: probe of musb-hdrc.1 rejects match -19
-
终于找到问题点了,really_probe函数都没有调用设备probe,因为一开始检查功能脚是否准备好的时候,返回的是错误。问题来了,musb我理解不使用phy将usb转以太网,那么不需要配置功能脚的呀?赶紧再看看am335x的技术手册吧
-
原来musb有功能脚要设置的,而且pin都是连接到phy的。所以phy是需要配置的,而且需要用到pinctrl模块来配置USB1_DP和USB1_DM是在我比较熟悉的Control Module中。而我之前的理解中phy是不需要配置的。
解决方案
- 原因已经定位了,所以解决方案是Device Drivers->USB support->USB Physical Layer drivers添加NOP USB Transceicer Driver和AM335x USB PHY Driver即可
当然后来我将usb驱动配置为上电加载的module也通过了host识别。
Starting kernel ...
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 5.4.61 (root@applecaiHP) (gcc version 8.3.0 (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))) #1 SMP Sun Sep 6 11:20:55 CST 2020
[ 0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=10c5387d
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] OF: fdt: Machine model: TI AM335x BeagleBone Black
[ 0.000000] Memory policy: Data cache writeback
[ 0.000000] cma: Reserved 16 MiB at 0x9e800000
[ 0.000000] CPU: All CPU(s) started in SVC mode.
[ 0.000000] AM335X ES2.1 (sgx neon)
[ 0.000000] percpu: Embedded 19 pages/cpu s48780 r8192 d20852 u77824
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 129412
[ 0.000000] Kernel command line: console=ttyO0,115200n8 root=PARTUUID=252433a3-02 rw rootfstype=ext4 rootwait
[ 0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes, linear)
[ 0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes, linear)
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[ 0.000000] Memory: 486208K/522240K available (9216K kernel code, 722K rwdata, 2116K rodata, 1024K init, 260K bss, 19648K reserved, 16384K cma-reserved, 0K highmem)
[ 0.000000] rcu: Hierarchical RCU implementation.
[ 0.000000] rcu: RCU event tracing is enabled.
[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=2 to nr_cpu_ids=1.
[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
[ 0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[ 0.000000] IRQ: Found an INTC at 0x(ptrval) (revision 5.0) with 128 interrupts
[ 0.000000] random: get_random_bytes called from start_kernel+0x2a8/0x4e0 with crng_init=0
[ 0.000000] OMAP clockevent source: timer2 at 24000000 Hz
[ 0.000017] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns
[ 0.000038] clocksource: timer1: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[ 0.000050] OMAP clocksource: timer1 at 24000000 Hz
[ 0.000824] timer_probe: no matching timers found
[ 0.001285] Console: colour dummy device 80x30
[ 0.001321] WARNING: Your 'console=ttyO0' has been replaced by 'ttyS0'
[ 0.001328] This ensures that you still see kernel messages. Please
[ 0.001334] update your kernel commandline.
[ 0.001374] Calibrating delay loop... 996.14 BogoMIPS (lpj=4980736)
[ 0.089099] pid_max: default: 32768 minimum: 301
[ 0.089292] LSM: Security Framework initializing
[ 0.089391] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.089405] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.090527] CPU: Testing write buffer coherency: ok
[ 0.090594] CPU0: Spectre v2: using BPIALL workaround
[ 0.091043] CPU0: thread -1, cpu 0, socket -1, mpidr 0
[ 0.091828] Setting up static identity map for 0x80100000 - 0x80100078
[ 0.092035] rcu: Hierarchical SRCU implementation.
[ 0.092439] smp: Bringing up secondary CPUs ...
[ 0.092453] smp: Brought up 1 node, 1 CPU
[ 0.092463] SMP: Total of 1 processors activated (996.14 BogoMIPS).
[ 0.092471] CPU: All CPU(s) started in SVC mode.
[ 0.093119] devtmpfs: initialized
[ 0.105027] VFP support v0.3: implementor 41 architecture 3 part 30 variant c rev 3
[ 0.105352] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[ 0.105379] futex hash table entries: 256 (order: 2, 16384 bytes, linear)
[ 0.106656] pinctrl core: initialized pinctrl subsystem
[ 0.108103] NET: Registered protocol family 16
[ 0.110854] DMA: preallocated 256 KiB pool for atomic coherent allocations
[ 0.138734] l3-aon-clkctrl:0000:0: failed to disable
[ 0.140351] audit: initializing netlink subsys (disabled)
[ 0.141522] cpuidle: using governor menu
[ 0.161116] audit: type=2000 audit(0.140:1): state=initialized audit_enabled=0 res=1
[ 0.162753] No ATAGs?
[ 0.162761] hw-breakpoint: debug architecture 0x4 unsupported.
[ 0.180715] edma 49000000.edma: TI EDMA DMA engine driver
[ 0.184165] iommu: Default domain type: Translated
[ 0.185907] vgaarb: loaded
[ 0.186497] SCSI subsystem initialized
[ 0.187141] usbcore: registered new interface driver usbfs
[ 0.187198] usbcore: registered new interface driver hub
[ 0.187267] usbcore: registered new device driver usb
[ 0.187830] pps_core: LinuxPPS API ver. 1 registered
[ 0.187843] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti
[ 0.187865] PTP clock support registered
[ 0.188862] clocksource: Switched to clocksource timer1
[ 0.655892] VFS: Disk quotas dquot_6.6.0
[ 0.656010] VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[ 0.665671] thermal_sys: Registered thermal governor 'fair_share'
[ 0.665680] thermal_sys: Registered thermal governor 'step_wise'
[ 0.665699] thermal_sys: Registered thermal governor 'user_space'
[ 0.666292] NET: Registered protocol family 2
[ 0.667102] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 6144 bytes, linear)
[ 0.667137] TCP established hash table entries: 4096 (order: 2, 16384 bytes, linear)
[ 0.667180] TCP bind hash table entries: 4096 (order: 3, 32768 bytes, linear)
[ 0.667241] TCP: Hash tables configured (established 4096 bind 4096)
[ 0.667353] UDP hash table entries: 256 (order: 1, 8192 bytes, linear)
[ 0.667377] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes, linear)
[ 0.667539] NET: Registered protocol family 1
[ 0.668398] RPC: Registered named UNIX socket transport module.
[ 0.668413] RPC: Registered udp transport module.
[ 0.668420] RPC: Registered tcp transport module.
[ 0.668427] RPC: Registered tcp NFSv4.1 backchannel transport module.
[ 0.668442] PCI: CLS 0 bytes, default 64
[ 0.670117] hw perfevents: enabled with armv7_cortex_a8 PMU driver, 5 counters available
[ 0.671696] Initialise system trusted keyrings
[ 0.672079] workingset: timestamp_bits=14 max_order=17 bucket_order=3
[ 0.673363] NFS: Registering the id_resolver key type
[ 0.673416] Key type id_resolver registered
[ 0.673425] Key type id_legacy registered
[ 0.673470] jffs2: version 2.2. (NAND) (SUMMARY) © 2001-2006 Red Hat, Inc.
[ 0.673823] Key type asymmetric registered
[ 0.673839] Asymmetric key parser 'x509' registered
[ 0.673858] io scheduler mq-deadline registered
[ 0.673867] io scheduler kyber registered
[ 0.678507] OMAP GPIO hardware version 0.1
[ 0.737500] ti-sysc 4a101200.target-module: OCP softreset timed out
[ 0.747605] ti-sysc 4a101200.target-module: OCP softreset timed out
[ 0.751470] pinctrl-single 44e10800.pinmux: 142 pins, size 568
[ 0.756478] Serial: 8250/16550 driver, 6 ports, IRQ sharing enabled
[ 0.760095] 44e09000.serial: ttyS0 at MMIO 0x44e09000 (irq = 29, base_baud = 3000000) is a 8250
[ 1.392354] printk: console [ttyS0] enabled
[ 1.409583] brd: module loaded
[ 1.421795] loop: module loaded
[ 1.426778] mtdoops: mtd device (mtddev=name/number) must be supplied
[ 1.435151] libphy: Fixed MDIO Bus: probed
[ 1.451303] ti-sysc 4a101200.target-module: OCP softreset timed out
[ 1.518891] davinci_mdio 4a101000.mdio: davinci mdio revision 1.6, bus freq 1000000
[ 1.526599] libphy: 4a101000.mdio: probed
[ 1.532493] davinci_mdio 4a101000.mdio: phy[0]: device 4a101000.mdio:00, driver SMSC LAN8710/LAN8720
[ 1.541882] cpsw 4a100000.ethernet: initialized cpsw ale version 1.4
[ 1.548266] cpsw 4a100000.ethernet: ALE Table size 1024
[ 1.553714] cpsw 4a100000.ethernet: cpts: overflow check period 500 (jiffies)
[ 1.561004] cpsw 4a100000.ethernet: Detected MACID = 50:33:8b:36:25:8e
[ 1.569546] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[ 1.576117] ehci-pci: EHCI PCI platform driver
[ 1.583334] am335x-phy-driver 47401300.usb-phy: 47401300.usb-phy supply vcc not found, using dummy regulator
[ 1.596037] am335x-phy-driver 47401b00.usb-phy: 47401b00.usb-phy supply vcc not found, using dummy regulator
[ 1.614589] i2c /dev entries driver
[ 1.620794] sdhci: Secure Digital Host Controller Interface driver
[ 1.627017] sdhci: Copyright(c) Pierre Ossman
[ 1.632569] omap_gpio 44e07000.gpio: Could not set line 6 debounce to 200000 microseconds (-22)
[ 1.641386] omap_hsmmc 48060000.mmc: Got CD GPIO
[ 1.698166] omap_hsmmc 47810000.mmc: RX DMA channel request failed
[ 1.705200] sdhci-pltfm: SDHCI platform and OF driver helper
[ 1.711603] ledtrig-cpu: registered to indicate activity on CPUs
[ 1.719634] oprofile: using arm/armv7
[ 1.723619] Initializing XFRM netlink socket
[ 1.728121] NET: Registered protocol family 10
[ 1.734250] Segment Routing with IPv6
[ 1.738060] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[ 1.744886] NET: Registered protocol family 17
[ 1.749454] NET: Registered protocol family 15
[ 1.754008] Key type dns_resolver registered
[ 1.758401] ThumbEE CPU extension supported.
[ 1.762738] Registering SWP/SWPB emulation handler
[ 1.767554] omap_voltage_late_init: Voltage driver support not added
[ 1.773965] sr_dev_init: Unknown instance smartreflex0
[ 1.779404] SmartReflex Class3 initialized
[ 1.784227] Loading compiled-in X.509 certificates
[ 1.809170] mmc0: host does not support reading read-only switch, assuming write-enable
[ 1.819249] mmc0: new high speed SDHC card at address 0007
[ 1.825793] mmcblk0: mmc0:0007 SD32G 29.0 GiB
[ 1.833026] mmcblk0: p1 p2
[ 1.840420] random: fast init done
[ 1.853828] tps65217 0-0024: TPS65217 ID 0xe version 1.2
[ 1.859671] omap_i2c 44e0b000.i2c: bus 0 rev0.11 at 400 kHz
[ 1.867335] omap_i2c 4819c000.i2c: bus 2 rev0.11 at 100 kHz
[ 1.881404] musb-hdrc musb-hdrc.1: MUSB HDRC host driver
[ 1.886783] musb-hdrc musb-hdrc.1: new USB bus registered, assigned bus number 1
[ 1.894645] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.04
[ 1.903000] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 1.910274] usb usb1: Product: MUSB HDRC host driver
[ 1.915260] usb usb1: Manufacturer: Linux 5.4.61 musb-hcd
[ 1.920698] usb usb1: SerialNumber: musb-hdrc.1
[ 1.926045] hub 1-0:1.0: USB hub found
[ 1.929981] hub 1-0:1.0: 1 port detected
- 主角登场,我的usb camera插入usb1口后能识别出。我下一个小项目的第一步完成咯~
[ 69.079117] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 69.086286] usb 1-1: Product: USB2.0 Camera
[ 69.090537] usb 1-1: Manufacturer: AVEO Technology Corp.
[ 80.242613] usb 1-1: USB disconnect, device number 2