summaryrefslogtreecommitdiff
path: root/src/device
diff options
context:
space:
mode:
authorFan DANG <[email protected]>2026-04-13 08:56:36 +0800
committerFan DANG <[email protected]>2026-04-13 08:56:36 +0800
commit34aded88edd5b1403bb35b531985953502a0faab (patch)
tree0afc50460d2cd7eccd3f55029f2638d62c75dda2 /src/device
parent470715ad8cb07b496ad2c2e9bf0b95d32cf768c7 (diff)
fix(device): big-endian host support for SETUP packet handling
1. Add TU_LITTLE_ENDIAN_BITFIELD / TU_BIG_ENDIAN_BITFIELD macros in tusb_compiler.h (GCC and IAR), following Linux kernel style. 2. Update bmAttributes (tusb_desc_endpoint_t) and bmRequestType_bit (tusb_control_request_t) in tusb_types.h to use these macros with explicit #error fallback if undefined. 3. Add tu_le16toh() conversion in dcd_event_setup_received() for wValue/wIndex/wLength. Tested on CIU98320B (big-endian ARM Cortex-M, full-speed HID keyboard).
Diffstat (limited to 'src/device')
-rw-r--r--src/device/dcd.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/device/dcd.h b/src/device/dcd.h
index 850c37bc2..f861eb258 100644
--- a/src/device/dcd.h
+++ b/src/device/dcd.h
@@ -219,6 +219,11 @@ TU_ATTR_ALWAYS_INLINE static inline void dcd_event_setup_received(uint8_t rhport
event.rhport = rhport;
event.event_id = DCD_EVENT_SETUP_RECEIVED;
(void) memcpy(&event.setup_received, setup, sizeof(tusb_control_request_t));
+ // USB wire format is little-endian. Convert multi-byte fields to host byte order
+ // so the stack always sees correct values regardless of CPU endianness.
+ event.setup_received.wValue = tu_le16toh(event.setup_received.wValue);
+ event.setup_received.wIndex = tu_le16toh(event.setup_received.wIndex);
+ event.setup_received.wLength = tu_le16toh(event.setup_received.wLength);
dcd_event_handler(&event, in_isr);
}