Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stacker): use actual serial number in usb serial number descriptor #497

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions stm32-modules/flex-stacker/firmware/host_comms_task/usbd_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,18 @@ uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *le
*/
static void Get_SerialNum(void)
{
uint32_t deviceserial0, deviceserial1, deviceserial2;
uint32_t sg_0, sg_1;
uint32_t pointer = USB_STRING_SERIAL_BASE;
// Serial number is stored in 6 32-bit words
for (uint8_t idx = 0; idx < 4; idx++) {
sg_0 = *(uint32_t *)(pointer + 4);
sg_1 = *(uint32_t *)(pointer);

deviceserial0 = *(uint32_t *)(UID_BASE+4);
deviceserial1 = *(uint32_t *)(UID_BASE+8);
deviceserial2 = *(uint32_t *)(UID_BASE+12);
if (sg_0 == 0U) break;

deviceserial0 += deviceserial2;

if (deviceserial0 != 0U)
{
IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8U);
IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4U);
IntToUnicode(sg_0, &USBD_StringSerial[2 + 16*idx], 4U);
IntToUnicode(sg_1, &USBD_StringSerial[10 + 16*idx], 4U);
pointer += 8;
}
}

Expand All @@ -259,20 +259,15 @@ static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len)
{
uint8_t idx = 0U;

for (idx = 0U ; idx < len ; idx ++)
for (idx = 0U; idx < len; idx++)
{
if (((value >> 28)) < 0xAU)
{
pbuf[ 2U * idx] = (value >> 28) + '0';
}
else
{
pbuf[2U * idx] = (value >> 28) + 'A' - 10U;
}

value = value << 4;

// Extract the most significant byte
pbuf[2U * idx] = (value >> 24) & 0xFF;
// Add a null byte for Unicode (UTF-16)
pbuf[2U * idx + 1] = 0U;

// Shift the value to process the next byte
value = value << 8;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/

#define USB_SIZ_STRING_SERIAL 0x1A
#define USB_SIZ_STRING_SERIAL 0x32
#define USB_STRING_SERIAL_BASE 0x0807F800

/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
Expand Down
Loading