DFU: set serial to match STM32 DFU bootloader

This commit is contained in:
King Kévin 2020-11-27 16:04:07 +01:00
parent a781fc5b3b
commit 0bb2be3727
1 changed files with 5 additions and 6 deletions

View File

@ -112,7 +112,7 @@ static const struct usb_config_descriptor usb_dfu_configuration = {
};
/** device ID used as serial number */
static char usb_serial[] = "00112233445566778899aabb";
static char usb_serial[] = "0123456789ab";
/** USB string table
* @note starts with index 1
@ -340,15 +340,14 @@ static enum usbd_request_return_codes usb_dfu_control_request(usbd_device *usbd_
void usb_dfu_setup(void)
{
// set serial
// set serial according to STM32 USB-FS_Device developer kit
// see https://community.st.com/s/question/0D50X0000ADCaTJSQ1/dfu-serial-number
for (uint8_t i = 0; i < LENGTH(usb_serial) - 1; i++) { // write the serial
uint32_t id; // current ID part
if (i < 8) {
id = DESIG_UNIQUE_ID2;
} else if (i < 16) {
id = DESIG_UNIQUE_ID1;
id = DESIG_UNIQUE_ID0 + DESIG_UNIQUE_ID2;
} else {
id = (DESIG_UNIQUE_ID0 << 16) + (DESIG_UNIQUE_ID0 >> 16);
id = DESIG_UNIQUE_ID1;
}
// transform into character
char c = (id >> ((7 - (i % 8)) * 4)) & 0x0f; // get nibble