Skip to content

Commit b7c8ce8

Browse files
committed
Fix endian mix-up in usb_core
USB uses little endian, as does ARM, so there should not be any byte swapping. Bytes were swapped back and forth inconsistently and would break word access of u16_u8 union types. It seems like this has gone unnoticed for long because the word values are mostly used for comparing against zero. Signed-off-by: Tormod Volden <[email protected]>
1 parent 3f42431 commit b7c8ce8

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

usb_lib/usb_core.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
#define USB_StatusIn() Send0LengthData()
3232
#define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID)
3333

34-
#define StatusInfo0 StatusInfo.bw.bb1 /* Reverse bb0 & bb1 */
35-
#define StatusInfo1 StatusInfo.bw.bb0
36-
3734
/* Private macro -------------------------------------------------------------*/
3835
/* Private variables ---------------------------------------------------------*/
3936
u16_u8 StatusInfo;
@@ -860,11 +857,11 @@ u8 Setup0_Process(void)
860857
pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
861858
pInformation->USBbRequest = *pBuf.b++; /* bRequest */
862859
pBuf.w++; /* word not accessed because of 32 bits addressing */
863-
pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */
860+
pInformation->USBwValue = *pBuf.w++; /* wValue in Little Endian */
864861
pBuf.w++; /* word not accessed because of 32 bits addressing */
865-
pInformation->USBwIndex = ByteSwap(*pBuf.w++); /* wIndex */
862+
pInformation->USBwIndex = *pBuf.w++; /* wIndex in Little Endian */
866863
pBuf.w++; /* word not accessed because of 32 bits addressing */
867-
pInformation->USBwLength = *pBuf.w; /* wLength */
864+
pInformation->USBwLength = *pBuf.w; /* wLength in Little Endian */
868865
}
869866

870867
pInformation->ControlState = SETTING_UP;

usb_lib/usb_core.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ typedef union
9797
u16 w;
9898
struct BW
9999
{
100-
u8 bb1;
100+
/* Little Endian */
101101
u8 bb0;
102+
u8 bb1;
102103
}
103104
bw;
104105
} u16_u8;
@@ -208,6 +209,8 @@ USER_STANDARD_REQUESTS;
208209
#define USBwLength USBwLengths.w
209210
#define USBwLength0 USBwLengths.bw.bb0
210211
#define USBwLength1 USBwLengths.bw.bb1
212+
#define StatusInfo0 StatusInfo.bw.bb0
213+
#define StatusInfo1 StatusInfo.bw.bb1
211214

212215
/* Exported macro ------------------------------------------------------------*/
213216
/* Exported functions ------------------------------------------------------- */

0 commit comments

Comments
 (0)