summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2023-09-20 19:07:45 +1000
committerDamien George <damien@micropython.org>2023-12-20 17:25:10 +1100
commit7cf1118831e71670dc237b5256a54856f6fdf0c2 (patch)
tree93601ab2062d8082181b53508599a8aa159cea26
parentf46269a1d16a5d0890bbc97d1141af7173050013 (diff)
downloadmicropython-7cf1118831e71670dc237b5256a54856f6fdf0c2.tar.gz
micropython-7cf1118831e71670dc237b5256a54856f6fdf0c2.zip
stm32/usbdev: Optionally pass through vendor requests to Setup function.
Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/stm32/usbd_conf.h5
-rw-r--r--ports/stm32/usbdev/core/src/usbd_ctlreq.c8
2 files changed, 13 insertions, 0 deletions
diff --git a/ports/stm32/usbd_conf.h b/ports/stm32/usbd_conf.h
index 83805a6e4d..e61e7ce7ef 100644
--- a/ports/stm32/usbd_conf.h
+++ b/ports/stm32/usbd_conf.h
@@ -49,6 +49,11 @@
#endif
#define USBD_DEBUG_LEVEL 0
+// Whether the core USBD driver passes through vendor device requests to the class implementation.
+#ifndef USBD_ENABLE_VENDOR_DEVICE_REQUESTS
+#define USBD_ENABLE_VENDOR_DEVICE_REQUESTS (0)
+#endif
+
// For MCUs with a device-only USB peripheral
#define USBD_PMA_RESERVE (64)
#define USBD_PMA_NUM_FIFO (16) // Maximum 8 endpoints, 2 FIFOs each
diff --git a/ports/stm32/usbdev/core/src/usbd_ctlreq.c b/ports/stm32/usbdev/core/src/usbd_ctlreq.c
index f25f252d64..97888918a8 100644
--- a/ports/stm32/usbdev/core/src/usbd_ctlreq.c
+++ b/ports/stm32/usbdev/core/src/usbd_ctlreq.c
@@ -120,6 +120,14 @@ USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev , USBD_SetupReqType
{
USBD_StatusTypeDef ret = USBD_OK;
+ #if USBD_ENABLE_VENDOR_DEVICE_REQUESTS
+ // Pass through vendor device requests directly to the implementation.
+ // It must call `USBD_CtlError(pdev, req);` if it does not respond to the request.
+ if ((req->bmRequest & 0xe0) == 0xc0) {
+ return pdev->pClass->Setup (pdev, req);
+ }
+ #endif
+
switch (req->bRequest)
{
case USB_REQ_GET_DESCRIPTOR: