From 3c787e5850087707b93c0eaeee7c89bbde0c0172 Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Sun, 11 Oct 2026 13:35:42 -0700 Subject: [PATCH] zephyr-cp: report the hwinfo device ID as the USB serial number zephyr-cp boards enumerate with no iSerial, so a host cannot tell two identical boards apart and udev's /dev/serial/by-id names collide. The TinyUSB ports report the chip's unique ID there. Add Zephyr's serial number string descriptor, which the USB device stack fills from hwinfo_get_device_id() (CONFIG_HWINFO is already on in prj.conf). Only add it when the SoC has a hwinfo driver; without one the stack logs an error and the descriptor request fails. Co-Authored-By: Claude Opus 5.5 (1M context) --- ports/zephyr-cp/supervisor/usb.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ports/zephyr-cp/supervisor/usb.c b/ports/zephyr-cp/supervisor/usb.c index da22cbb0d35..a926bc1554e 100644 --- a/ports/zephyr-cp/supervisor/usb.c +++ b/ports/zephyr-cp/supervisor/usb.c @@ -49,6 +49,10 @@ USBD_DEVICE_DEFINE(main_usbd, USBD_DESC_LANG_DEFINE(main_lang); USBD_DESC_MANUFACTURER_DEFINE(main_mfr, USB_MANUFACTURER); USBD_DESC_PRODUCT_DEFINE(main_product, USB_PRODUCT); +// The stack fills this from hwinfo and fails the request without a driver. +#if defined(CONFIG_HWINFO_HAS_DRIVER) +USBD_DESC_SERIAL_NUMBER_DEFINE(main_sn); +#endif USBD_DESC_CONFIG_DEFINE(fs_cfg_desc, "FS Configuration"); USBD_DESC_CONFIG_DEFINE(hs_cfg_desc, "HS Configuration"); @@ -268,6 +272,14 @@ void usb_init(void) { return; } + #if defined(CONFIG_HWINFO_HAS_DRIVER) + err = usbd_add_descriptor(&main_usbd, &main_sn); + if (err) { + LOG_ERR("Failed to initialize serial number descriptor (%d)", err); + return; + } + #endif + bool console = usb_cdc_console_enabled(); if (console) { uint8_t *receiver_buffer = port_malloc(128, true);