pico_usb-cdc example fails with panic
I built the rp2xxx examples with zig 0.15.1 on a Linux (Mint) system and uploaded the pico_usb-cdc example to a Raspberry Pi Pico with the command:
```
openocd -f interface/cmsis-dap.cfg \
-f target/rp2040.cfg \
-c "adapter speed 5000" \
-c "program zig-out/firmware/pico_usb-cdc.elf verify reset exit"
```
The serial port output shows the "STARTING NEW LOGGER" banner, then nothing. The device does not show up when using the `lsusb` command on the Raspberry Pi 5 to which the Pico's USB port is connected and nothing appears in the Pi's logs.
If I unplug the Pico from the USB Port and plug it back in, the serial port log shows:
```
================ STARTING NEW LOGGER ================
[5.355586] error: panic: reached unreachable code
[5.361085] error: panic: Unhandled exception: HardFault
```
Looking at the log on the Raspberry Pi I see that it did recognise that something was connected:
```
Apr 05 08:25:17 hal kernel: usb 3-2: new full-speed USB device number 123 using xhci-hcd
Apr 05 08:25:32 hal kernel: usb 3-2: device descriptor read/64, error -110
Apr 05 08:25:48 hal kernel: usb 3-2: device descriptor read/64, error -110
Apr 05 08:25:48 hal kernel: usb 3-2: new full-speed USB device number 124 using xhci-hcd
Apr 05 08:26:03 hal kernel: usb 3-2: device descriptor read/64, error -110
```
Note that after the panic happens before the second of these log lines is printed so the read error is unsurprising.
I ran the program again omitting the "exit" from the openocd command. Then after unplugging and plugging in the USB I connected to the Pico with gdb. The stack trace shows:
```
(gdb) bt
#0 usb_cdc.panic (message=...) at /home/craig/Git_Projects/microzig/examples/raspberrypi/rp2xxx/src/usb_cdc.zig:37
#1 0x100002e0 in builtin.panic__struct_2051.panic (msg=..., ra=...) at /home/craig/.zvm/0.15.1/lib/std/builtin.zig:1091
#2 0x10000ce0 in debug.FullPanic((function 'panic')).reachedUnreachable () at /home/craig/.zvm/0.15.1/lib/std/debug.zig:64
#3 0x10000308 in debug.assert (ok=false) at /home/craig/.zvm/0.15.1/lib/std/debug.zig:559
#4 0x1000fa04 in hal.usb.Polled(.{ .max_endpoints_count = 16, .max_interfaces_count = 16, .sync_noops = 3 }).ep_writev (itf=0x20000120 <usb_cdc.usb_device+264>, ep_num=ep0, data=...)
at /home/craig/Git_Projects/microzig/port/raspberrypi/rp2xxx/src/hal/usb.zig:287
#5 0x10009f52 in core.usb.DeviceInterface.ep_writev (self=0x20000120 <usb_cdc.usb_device+264>, ep_num=ep0, data=...) at /home/craig/Git_Projects/microzig/core/src/core/usb.zig:128
#6 0x100060ee in core.usb.DeviceController(.{ .bcd_usb = .{ ... }, .device_triple = .{ ... }, .vendor = .{ ... }, .product = .{ ... }, .bcd_device = .{ ... }, .language = .English, .serial = &.{ ... }[0..(...)], .max_supported_packet_size = 64, .configurations = &.{ ... }[0..(...)], .unique_endpoints = true },.{ .{ ... } }).on_setup_req (self=0x20000124 <usb_cdc.usb_controller>,
device_itf=0x20000120 <usb_cdc.usb_device+264>, setup=0x2003f9d0) at /home/craig/Git_Projects/microzig/core/src/core/usb.zig:482
#7 0x1000491a in hal.usb.Polled(.{ .max_endpoints_count = 16, .max_interfaces_count = 16, .sync_noops = 3 }).poll__anon_16389 (self=0x20000018 <usb_cdc.usb_device>,
controller=0x20000124 <usb_cdc.usb_controller>) at /home/craig/Git_Projects/microzig/port/raspberrypi/rp2xxx/src/hal/usb.zig:131
#8 0x10003f04 in usb_cdc.main () at /home/craig/Git_Projects/microzig/examples/raspberrypi/rp2xxx/src/usb_cdc.zig:76
#9 0x1000598a in start.microzig_main () at start.zig:62
#10 0x1000f15e in cortex_m.startup_logic._start () at /home/craig/Git_Projects/microzig/core/src/cpus/cortex_m.zig:761
```
Running uname on the Pi:
```
Linux hal 6.12.75+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.12.75-1+rpt1 (2026-03-11) aarch64 GNU/Linux
```
10 条评论