Skip to content

Commit 4291571

Browse files
committed
tinyusb: correct SAMD51 serial number extraction
TinyUSB does not match the exported serial numbers of the classic USB stack. The current code serializes the 32-bit words backwards, and the byte nibbles are also backwards serialized. A SAMD51 is exported like: EFADAF3113347335020202938343E0FF while it should read: 13FADAFE5337433139202020FF0E3438
1 parent 54be8f0 commit 4291571

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cores/arduino/Adafruit_TinyUSB_Core/Adafruit_TinyUSB_Core.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ uint8_t load_serial_number(uint16_t* serial_str)
9999

100100
for (int i=0; i<4; i++) {
101101
for (int k=0; k<4; k++) {
102-
raw_id[4 * i + k] = (*(id_addresses[i]) >> k * 8) & 0xff;
102+
raw_id[4 * i + (3 - k)] = (*(id_addresses[i]) >> k * 8) & 0xff;
103103
}
104104
}
105105

@@ -109,7 +109,7 @@ uint8_t load_serial_number(uint16_t* serial_str)
109109
for (int j = 0; j < 2; j++) {
110110
uint8_t nibble = (raw_id[i] >> (j * 4)) & 0xf;
111111
// Strings are UTF-16-LE encoded.
112-
serial_str[i * 2 + j] = nibble_to_hex[nibble];
112+
serial_str[i * 2 + (1 - j)] = nibble_to_hex[nibble];
113113
}
114114
}
115115

0 commit comments

Comments
 (0)