From 407aeb4affd32da6f500050bd22c925a5929cbbd Mon Sep 17 00:00:00 2001 From: jsanchez-2g Date: Thu, 20 Aug 2026 12:49:45 -0500 Subject: [PATCH] arm/stm32: Decode saved M0 USB setup requests. Decode the saved setup request fields after processing the optional OUT data phase. This ensures the fields are initialized when the EP0 handler is entered again to complete an OUT control transfer. This also fixes Clang builds that treat the resulting maybe-uninitialized diagnostics as errors. Assisted-by: Codex:GPT-5 Signed-off-by: jsanchez-2g --- .../arm/src/common/stm32/stm32_usbdev_m0_v1.c | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/arch/arm/src/common/stm32/stm32_usbdev_m0_v1.c b/arch/arm/src/common/stm32/stm32_usbdev_m0_v1.c index c37b559fffb..af2660767ab 100644 --- a/arch/arm/src/common/stm32/stm32_usbdev_m0_v1.c +++ b/arch/arm/src/common/stm32/stm32_usbdev_m0_v1.c @@ -1685,20 +1685,13 @@ static void stm32_ep0setup(struct stm32_usbdev_s *priv) stm32_copyfrompma((uint8_t *)&priv->ctrl, stm32_geteprxaddr(EP0), USB_SIZEOF_CTRLREQ); - /* And extract the little-endian 16-bit values to host order */ + /* Is this an OUT setup request with a data phase? */ - value.w = GETUINT16(priv->ctrl.value); - index.w = GETUINT16(priv->ctrl.index); - len.w = GETUINT16(priv->ctrl.len); - - uinfo("SETUP: type=%02x req=%02x value=%04x index=%04x len=%04x\n", - priv->ctrl.type, priv->ctrl.req, value.w, index.w, len.w); - - /* Is this an setup with OUT and data of length > 0 */ - - if (USB_REQ_ISOUT(priv->ctrl.type) && len.w > 0) + if (USB_REQ_ISOUT(priv->ctrl.type) && + GETUINT16(priv->ctrl.len) > 0) { - usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EP0SETUPOUT), len.w); + usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EP0SETUPOUT), + GETUINT16(priv->ctrl.len)); /* At this point priv->ctrl is the setup packet. */ @@ -1711,6 +1704,17 @@ static void stm32_ep0setup(struct stm32_usbdev_s *priv) } } + /* Extract the little-endian 16-bit values from the saved SETUP request. + * This function may be called again after receiving an OUT data phase. + */ + + value.w = GETUINT16(priv->ctrl.value); + index.w = GETUINT16(priv->ctrl.index); + len.w = GETUINT16(priv->ctrl.len); + + uinfo("SETUP: type=%02x req=%02x value=%04x index=%04x len=%04x\n", + priv->ctrl.type, priv->ctrl.req, value.w, index.w, len.w); + /* Dispatch any non-standard requests */ if ((priv->ctrl.type & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_STANDARD)