移植一个AVR的程序到STM32,发现USB库中无聊的交换了wValue和wIndex的字节序。如下代码: pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
pInformation->USBbRequest = *pBuf.b++; /* bRequest */
pBuf.w += offset; /* word not accessed because of 32 bits addressing */
pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */
pBuf.w += offset; /* word not accessed because of 32 bits addressing */
pInformation->USBwIndex = ByteSwap(*pBuf.w++); /* wIndex */
pBuf.w += offset; /* word not accessed because of 32 bits addressing */
pInformation->USBwLength = *pBuf.w; /* wLength */
搜索所有的历程,只有DFU用到word值,还蛋疼的再交换回来,如下:
B0 = pInfo->USBwValues.bw.bb0;
B1 = pInfo->USBwValues.bw.bb1;
wBlockNum = (uint16_t)B1;
wBlockNum = wBlockNum * 0x100;
wBlockNum += (uint16_t)B0; /* wBlockNum value updated*/
B0 = pInfo->USBwLengths.bw.bb0;
B1 = pInfo->USBwLengths.bw.bb1;
wlength = (uint16_t)B0;
wlength = wlength * 0x100;
wlength += (uint16_t)B1; /* wlength value updated*/
USB传输和STM32都是little-endian字节序,为何要多此一举呢?有达人可以给解释一下吗? |