我給我自己放了個(gè)暑假后本周也開(kāi)學(xué)了,我在書(shū)架上瀏覽找事做的時(shí)候畴博,發(fā)現(xiàn)了十年前買(mǎi)的<圈圈教你學(xué)USB>笨忌,十年前我用51+usb芯片做過(guò)一個(gè)小鼠標(biāo),原理圖及焊接都是我自己做的俱病,但是現(xiàn)在已經(jīng)把usb協(xié)議忘記了官疲。我的老本行是做通信的,也可以說(shuō)是做與業(yè)務(wù)無(wú)關(guān)的中間件亮隙,那么usb通信也和我有點(diǎn)關(guān)系途凫,再加上我需要培養(yǎng)我自己的視覺(jué)全棧工程師的技術(shù)能力,說(shuō)不定有usb camera的技能需求溢吻,我看了usb協(xié)議文檔(2.0)的维费,現(xiàn)在usb 4.0都出來(lái)的。主要是了解下usb通信原理煤裙。然后就開(kāi)始動(dòng)手咯~
網(wǎng)上下載最新的5.8.5版本掩完,結(jié)果和我之前學(xué)習(xí)的TI的4.1版本區(qū)別很大。我就先按我的理解配置了usb host部分硼砰。
問(wèn)題:bb black開(kāi)發(fā)板的usb1作為host device識(shí)別不了
那么開(kāi)始查問(wèn)題【有問(wèn)題讓我查,這是我覺(jué)得最有挑戰(zhàn)的時(shí)刻的欣硼,福爾摩斯AppleCai上場(chǎng)咯】
- 看設(shè)備樹(shù)是否匹配题翰,結(jié)果發(fā)現(xiàn)compliance的關(guān)鍵字都改了。使用了ti-sysc。網(wǎng)上搜索了下changelog豹障,原來(lái)現(xiàn)在統(tǒng)一有sysc bus來(lái)初始化所有ti外設(shè)驅(qū)動(dòng)冯事。為了降低調(diào)查難度,我通過(guò)changelog發(fā)現(xiàn)5.4版本還是和4.1版本一樣的血公。5.5設(shè)備樹(shù)就修改為了ti-sysc了昵仅。
- 于是降低難度,采用5.4版本進(jìn)行移植累魔,添加usb驅(qū)動(dòng)摔笤,結(jié)果依然識(shí)別不了device,首先調(diào)查設(shè)備樹(shù)是否匹配垦写,檢查conpliance正確吕世,并且state=okey。那么是什么原因呢梯投?
- 首先查看usb文件夾及musb文件夾包括makefile命辖,并且確定了musb-hdrc是和usb host相關(guān)的c文件。學(xué)習(xí)了解各種c文件的函數(shù)分蓖。來(lái)檢查對(duì)應(yīng)的配置設(shè)置尔艇。修改配置后依然無(wú)法識(shí)別usb host。
- 復(fù)習(xí)了下設(shè)備樹(shù)probe的調(diào)用流程和函數(shù)么鹤,都是在drivers/bus文件夾下的终娃。總的來(lái)說(shuō)就是都添加到bus后午磁,若有驅(qū)動(dòng)添加則檢查對(duì)應(yīng)的設(shè)備進(jìn)行match尝抖,若有設(shè)備添加則檢查對(duì)應(yīng)的驅(qū)動(dòng)綁定。
通過(guò)在probe函數(shù)添加dev_info打印go here消息迅皇,結(jié)果usb host的go here沒(méi)有走到昧辽。難道是probe不成功,到底哪個(gè)環(huán)節(jié)出問(wèn)題了登颓,不是只要設(shè)備樹(shù)名字一致就可以匹配了嗎搅荞? -
只能靠打印了,通過(guò)查看具體代碼框咙,它里面有很多pr_debug函數(shù)咕痛。配置Device Driver下的DEBUG_DRIVER。
打開(kāi)后可以看到如下信息
[ 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
-
終于找到問(wèn)題點(diǎn)了喇嘱,really_probe函數(shù)都沒(méi)有調(diào)用設(shè)備probe茉贡,因?yàn)橐婚_(kāi)始檢查功能腳是否準(zhǔn)備好的時(shí)候,返回的是錯(cuò)誤者铜。問(wèn)題來(lái)了腔丧,musb我理解不使用phy將usb轉(zhuǎn)以太網(wǎng)放椰,那么不需要配置功能腳的呀?趕緊再看看am335x的技術(shù)手冊(cè)吧
-
原來(lái)musb有功能腳要設(shè)置的愉粤,而且pin都是連接到phy的砾医。所以phy是需要配置的,而且需要用到pinctrl模塊來(lái)配置USB1_DP和USB1_DM是在我比較熟悉的Control Module中衣厘。而我之前的理解中phy是不需要配置的如蚜。
解決方案
- 原因已經(jīng)定位了,所以解決方案是Device Drivers->USB support->USB Physical Layer drivers添加NOP USB Transceicer Driver和AM335x USB PHY Driver即可
當(dāng)然后來(lái)我將usb驅(qū)動(dòng)配置為上電加載的module也通過(guò)了host識(shí)別影暴。
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 <giometti@linux.it>
[ 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
- 主角登場(chǎng)错邦,我的usb camera插入usb1口后能識(shí)別出。我下一個(gè)小項(xiàng)目的第一步完成咯~
[ 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