From 0bb2be3727fcd09ef38624e8684e629595dc1760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Fri, 27 Nov 2020 16:04:07 +0100 Subject: [PATCH] DFU: set serial to match STM32 DFU bootloader --- lib/usb_dfu.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/usb_dfu.c b/lib/usb_dfu.c index 71f31da..76ca150 100644 --- a/lib/usb_dfu.c +++ b/lib/usb_dfu.c @@ -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