Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

pico_usb-cdc example fails with panic

Aperta
#928 10 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
22/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Ambito
embedded-iot

Direzione di ricerca

The gdb backtrace points to the assert in ep_writev in port/raspberrypi/rp2xxx/src/hal/usb.zig (around line 287), reached from on_setup_req in core/src/core/usb.zig (line 482) and the poll loop in examples/raspberrypi/rp2xxx/src/usb_cdc.zig (line 76). Start by reading why the endpoint 0 write assertion fails during setup handling, then check the device descriptor response. Done means the pico_usb-cdc example enumerates on hardware without a HardFault.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

rp usb

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
Lingua principale
Zig
Stelle
2.3k
Fork
198
Merge medio
1g 8h
PR unite (30g)
37

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ZigEmbeddedGroup/microzig

Tutte le issue di ZigEmbeddedGroup/microzig

Issue simili

Altre issue su Embedded & IoT

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.