3
\$\begingroup\$

I captured the usb packets on a usb1.1 mouse using a generic 24mhz logic analyzer.

here is the sigrok capture for the first token. enter image description here

as per the usb docs.. a CRC5 is calculated for the token by taking into account the address(7bits) and endpoint(4bits) fields.

since both the addr and endp are zero for this transaction, the 11 bits are - 00000000000 so the crc calculated by the crc5 polynomial( 100101) should give zero, but i'm not able to understand that the crc field is 0x2.

now for a different transaction.. after the host has allocated address to the device. enter image description here

fields are-- addr - 11; endp - 0;

so, from the datasheet(pg 173), the final 11 bit field is - 11010000000 . when crc5 is calculated on this field.. it gives 4 which matches correctly with the crc field. I used the long division method to calculate the crc.

am i miscalculating the crc for the first token?

\$\endgroup\$
  • \$\begingroup\$ See this document: link \$\endgroup\$ – Arsenal Mar 22 '18 at 15:16
2
\$\begingroup\$

The USB CRC5 uses an initial shift register value of 11111b (5 ones in a row). The reason for this is that without it the CRC cannot detect lengthening or shortening of a message that leads with zeros. This is demonstrated in your particular sequence, where the CRC is always zero for any length of leading zeros if you use an initial value of 00000b.

This is quite a common problem in CRC implementations.

\$\endgroup\$
  • \$\begingroup\$ yes. XOR feedback must never use all 00's for init and XNOR feedback must never use all 11's for init. These are invalid starting conditions. \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Mar 22 '18 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.