Atmel ICE USB 设备在 WSL ubuntu 下无法正确枚举

Atmel ICE USB 设备在 WSL ubuntu 下无法正确枚举

我最近一直在尝试让 Atmel ICE 调试器与在 WSL2 上运行的 ubuntu 20.04 下的 openOCD 一起工作。

当使用下面的 atmel 调试器配置运行 openOCD 时

source [find interface/cmsis-dap.cfg]
set CHIPNAME atsame54p20a
source [find target/atsame5x.cfg]

我收到此错误:

Error: 75 70 cmsis_dap.c:259 cmsis_dap_open(): unable to find a matching CMSIS-DAP device

完整的 openOCD 输出在这里:

Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
User : 13 0 options.c:63 configuration_output_handler(): debug_level: 3
User : 14 0 options.c:63 configuration_output_handler():
Debug: 15 0 options.c:244 add_default_dirs(): bindir=/usr/bin
Debug: 16 0 options.c:245 add_default_dirs(): pkgdatadir=/usr/share/openocd
Debug: 17 0 options.c:246 add_default_dirs(): exepath=/usr/bin
Debug: 18 0 options.c:247 add_default_dirs(): bin2data=../share/openocd
Debug: 19 0 configuration.c:42 add_script_search_dir(): adding /home/iwahdan/.config/openocd
Debug: 20 0 configuration.c:42 add_script_search_dir(): adding /home/iwahdan/.openocd
Debug: 21 0 configuration.c:42 add_script_search_dir(): adding /usr/bin/../share/openocd/site
Debug: 22 0 configuration.c:42 add_script_search_dir(): adding /usr/bin/../share/openocd/scripts
Debug: 23 0 configuration.c:97 find_file(): found openocd.cfg
Debug: 24 0 configuration.c:97 find_file(): found /usr/bin/../share/openocd/scripts/interface/cmsis-dap.cfg
Debug: 25 1 command.c:146 script_debug(): command - adapter driver cmsis-dap
Debug: 27 1 configuration.c:97 find_file(): found /usr/bin/../share/openocd/scripts/target/atsame5x.cfg
Debug: 28 1 configuration.c:97 find_file(): found /usr/bin/../share/openocd/scripts/target/swj-dp.tcl
Debug: 29 1 command.c:146 script_debug(): command - transport select
Info : 30 1 transport.c:275 jim_transport_select(): auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Debug: 31 1 command.c:146 script_debug(): command - transport select
Debug: 32 1 command.c:146 script_debug(): command - transport select
Debug: 33 1 command.c:146 script_debug(): command - swd newdap atsame54p20a cpu -irlen 4 -expected-id 0x4ba00477
Debug: 34 1 tcl.c:571 jim_newtap_cmd(): Creating New Tap, Chip: atsame54p20a, Tap: cpu, Dotted: atsame54p20a.cpu, 4 params
Debug: 35 1 core.c:1484 jtag_tap_init(): Created Tap: atsame54p20a.cpu @ abs position 0, irlen 0, capture: 0x0 mask: 0x0
Debug: 36 1 command.c:146 script_debug(): command - dap create atsame54p20a.dap -chain-position atsame54p20a.cpu
Debug: 37 1 command.c:146 script_debug(): command - target create atsame54p20a.cpu cortex_m -endian little -dap atsame54p20a.dap
Debug: 38 1 command.c:375 register_command(): command 'rtt' is already registered in '<global>' context
Debug: 39 1 command.c:146 script_debug(): command - atsame54p20a.cpu configure -work-area-phys 0x20000000 -work-area-size 0x8000 -work-area-backup 0
Debug: 40 1 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas
Debug: 41 1 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas
Debug: 42 1 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas
Debug: 43 1 command.c:146 script_debug(): command - atsame54p20a.cpu configure -event reset-deassert-post
        atsame5 dsu_reset_deassert

Debug: 44 1 command.c:146 script_debug(): command - reset_config srst_gates_jtag
Debug: 46 1 command.c:146 script_debug(): command - adapter speed 2000
Debug: 48 1 core.c:1822 jtag_config_khz(): handle jtag khz
Debug: 49 1 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 50 1 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 51 1 command.c:146 script_debug(): command - transport select
Debug: 52 1 command.c:146 script_debug(): command - cortex_m reset_config sysresetreq
Debug: 54 1 command.c:146 script_debug(): command - flash bank atsame54p20a.flash atsame5 0x00000000 0 1 1 atsame54p20a.cpu
Debug: 56 1 tcl.c:1319 handle_flash_bank_command(): 'atsame5' driver usage field missing
Info : 57 1 server.c:311 add_service(): Listening on port 6666 for tcl connections
Info : 58 1 server.c:311 add_service(): Listening on port 4444 for telnet connections
Debug: 59 1 command.c:146 script_debug(): command - init
Debug: 61 1 command.c:146 script_debug(): command - target init
Debug: 63 1 command.c:146 script_debug(): command - target names
Debug: 64 1 command.c:146 script_debug(): command - atsame54p20a.cpu cget -event gdb-flash-erase-start
Debug: 65 1 command.c:146 script_debug(): command - atsame54p20a.cpu configure -event gdb-flash-erase-start reset init
Debug: 66 1 command.c:146 script_debug(): command - atsame54p20a.cpu cget -event gdb-flash-write-end
Debug: 67 1 command.c:146 script_debug(): command - atsame54p20a.cpu configure -event gdb-flash-write-end reset halt
Debug: 68 1 command.c:146 script_debug(): command - atsame54p20a.cpu cget -event gdb-attach
Debug: 69 1 command.c:146 script_debug(): command - atsame54p20a.cpu configure -event gdb-attach halt 1000
Debug: 70 1 target.c:1639 handle_target_init_command(): Initializing targets...
Debug: 71 1 semihosting_common.c:99 semihosting_common_init():
Debug: 72 3 cmsis_dap_usb_bulk.c:111 cmsis_dap_usb_open(): could not open device 0x1d6b:0x0003: Access denied (insufficient permissions)
Debug: 73 6 cmsis_dap_usb_bulk.c:156 cmsis_dap_usb_open(): found product string of 0x03eb:0x2141 'Atmel-ICE CMSIS-DAP'
Debug: 74 6 cmsis_dap_usb_bulk.c:176 cmsis_dap_usb_open(): enumerating interfaces of 0x03eb:0x2141
Debug: 75 7 cmsis_dap_usb_bulk.c:223 cmsis_dap_usb_open(): found interface 0 string 'Atmel-ICE CMSIS-DAP'
Debug: 76 7 cmsis_dap_usb_bulk.c:243 cmsis_dap_usb_open(): skipping interface 0, endpoint[0] is not bulk out
Debug: 77 8 cmsis_dap_usb_bulk.c:243 cmsis_dap_usb_open(): skipping interface 1, endpoint[0] is not bulk out
Debug: 78 24 cmsis_dap_usb_bulk.c:176 cmsis_dap_usb_open(): enumerating interfaces of 0x0483:0x3753
Debug: 79 72 cmsis_dap_usb_bulk.c:111 cmsis_dap_usb_open(): could not open device 0x1d6b:0x0002: Access denied (insufficient permissions)
Error: 80 72 cmsis_dap.c:259 cmsis_dap_open(): unable to find a matching CMSIS-DAP device
Debug: 81 72 command.c:628 run_command(): Command 'init' failed with error code -4
User : 82 72 command.c:694 command_run_line():
Debug: 83 72 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas

拉出我发现的 dmesg 日志:

[ 1588.445948] usb 1-2: new high-speed USB device number 3 using vhci_hcd
[ 1588.605960] usb 1-2: SetAddress Request (3) to port 1
[ 1588.639106] usb 1-2: New USB device found, idVendor=03eb, idProduct=2141, bcdDevice= 
1.01
[ 1588.639529] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1588.639913] usb 1-2: Product: Atmel-ICE CMSIS-DAP
[ 1588.640129] usb 1-2: Manufacturer: Atmel Corp.
[ 1588.640308] usb 1-2: SerialNumber: J42700004736
[ 1588.646303] hid-generic 0003:03EB:2141.0001: device has no listeners, quitting

如您所见,似乎存在一个问题:

hid-generic 0003:03EB:2141.0001: device has no listeners, quitting

以下是 lsusb 的输出:

/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=vhci_hcd/8p, 5000M
ID 1d6b:0003 Linux Foundation 3.0 root hub
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=vhci_hcd/8p, 480M
ID 1d6b:0002 Linux Foundation 2.0 root hub
|__ Port 2: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 480M
    ID 03eb:2141 Atmel Corp. ICE debugger
|__ Port 2: Dev 3, If 1, Class=Vendor Specific Class, Driver=, 480M
    ID 03eb:2141 Atmel Corp. ICE debugger

知道这里可能出了什么问题吗?

答案1

您需要重新编译发现的 Microsoft Linux 内核这里CONFIG_USB_HIDDEV=y在 WSL 中。从文件中取消注释该选项config-wsl

完整说明如下:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git build-essential flex bison libssl-dev libelf-dev bc dwarves
git clone https://github.com/microsoft/WSL2-Linux-Kernel wsl2
cd wsl2
  • 使用您选择的文本编辑器打开Microsoft/config-wsl。我更喜欢使用 Vim。

  • 搜索注释掉的行# CONFIG_USB_HIDDEV is not set

  • 取消注释并将其更改为CONFIG_USB_HIDDEV=y

  • 您还需要更改内核名称。

  • 保存更改并运行:

    make O=out KCONFIG_CONFIG=Microsoft/config-wsl
    

    这将开始构建新的内核映像。您可能会收到有关要包含的新功能的提示。我选择拒绝每一个。编译大概需要 20 到 30 分钟。

  • bzImage编译完成后,目录中将有一个名为的文件out/arch/x86/boot。将此文件复制到 Windows 计算机上的某个位置。我刚刚做了:

    cp out/arch/x86/boot/bzImage /mnt/c/Users/username/Desktop
    

    这会将文件直接复制到我的 Windows 桌面。

  • 重命名bzImagekernel

  • 关闭 WSL2 并输入wsl --shutdown以确保 WSL2 已正确关闭。

  • 转到C:\Windows\System32\lxss\tools并将当前内核文件重命名为stock-kernel.old

  • 您生成的内核文件复制并粘贴到此目录中。

  • 重新启动 Ubuntu。

  • 您可能会收到一条错误消息Process cannot access the file because it is being used by another process。如果是这种情况,请cmd以管理员模式运行并输入netsh winsock reset

  • 然后重新启动计算机。

  • 打开 Ubuntu,您将看到您的自定义内核名称。

连接 Atmel Ice 后,您可以通过键入 来验证它是否被正确枚举dmesg

这是我的输出显示的内容:

[    7.193727] usb 1-1: New USB device found, idVendor=03eb, idProduct=2141, bcdDevice= 1.01
[    7.193731] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    7.193733] usb 1-1: Product: Atmel-ICE CMSIS-DAP
[    7.193734] usb 1-1: Manufacturer: Atmel Corp.
[    7.193735] usb 1-1: SerialNumber: J42700061718
[    7.197202] hid-generic 0003:03EB:2141.0001: hiddev96: USB HID v1.11 Device
[Atmel Corp. Atmel-ICE CMSIS-DAP] on usb-vhci_hcd.0-1/input0

相关内容