Skip to main content
Rob.Riggs
Senior
January 12, 2019
Solved

DFU Serial Number

  • January 12, 2019
  • 4 replies
  • 3365 views

I am looking at the code here that has the algorithm for producing the device serial number reported when the MCU is in USB DFU mode.

https://github.com/libopencm3/libopencm3/blob/master/lib/stm32/desig.c

The document they reference there, https://my.st.com/52d187b7, is now a dead link. Does anyone have the name of the document and its current location?

This topic has been closed for replies.
Best answer by Tesla DeLorean

It's is likely are very old forum reference. Perhaps @brk​ or @Amel NASRI​ can dig it out

The interference here is this is a 6-byte contraction used by the System Loader. I would suppose you could quickly verify this by pulling the 96-bit unique ID for a unit and contrasting that with the reported serial number.

UM0424 doesn't really cover this

https://www.st.com/content/ccc/resource/technical/document/user_manual/01/c6/32/df/79/ad/48/32/CD00158241.pdf/files/CD00158241.pdf/jcr:content/translations/en.CD00158241.pdf

And the Get_SerialNum() here has an 8-byte implementation

https://github.com/fthorey/swiftler-bones/blob/master/stm32/STM32_USB-FS-Device_Lib_V3.3.0/Project/Device_Firmware_Upgrade/src/hw_config.c

4 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
January 12, 2019

It's is likely are very old forum reference. Perhaps @brk​ or @Amel NASRI​ can dig it out

The interference here is this is a 6-byte contraction used by the System Loader. I would suppose you could quickly verify this by pulling the 96-bit unique ID for a unit and contrasting that with the reported serial number.

UM0424 doesn't really cover this

https://www.st.com/content/ccc/resource/technical/document/user_manual/01/c6/32/df/79/ad/48/32/CD00158241.pdf/files/CD00158241.pdf/jcr:content/translations/en.CD00158241.pdf

And the Get_SerialNum() here has an 8-byte implementation

https://github.com/fthorey/swiftler-bones/blob/master/stm32/STM32_USB-FS-Device_Lib_V3.3.0/Project/Device_Firmware_Upgrade/src/hw_config.c

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Brian Kling
Senior
January 14, 2019

The link is not a community link, perhaps @Amel NASRI​ can assist.

Amel NASRI
Technical Moderator
January 15, 2019

Yes this seems to be an old link in the platform used before migrating to Jive.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Tesla DeLorean
Guru
January 16, 2019

https://www.st.com/content/ccc/resource/technical/document/user_manual/01/c6/32/df/79/ad/48/32/CD00158241.pdf/files/CD00158241.pdf/jcr:content/translations/en.CD00158241.pdf

"In all available demos in the “STM32 USB-FS_Device developer kit�? there is an example implementing a unique serial number string descriptor based on the STM32 Device Unique ID register (12 digits)."

Here from V3.2.1 does not look consistent

/*******************************************************************************
* Function Name : Get_SerialNum.
* Description : Create the serial number string descriptor.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Get_SerialNum(void)
{
 uint32_t Device_Serial0, Device_Serial1, Device_Serial2;
 
 Device_Serial0 = *(__IO uint32_t*)(0x1FFFF7E8);
 Device_Serial1 = *(__IO uint32_t*)(0x1FFFF7EC);
 Device_Serial2 = *(__IO uint32_t*)(0x1FFFF7F0);
 
 Device_Serial0 += Device_Serial2;
 
 if (Device_Serial0 != 0)
 {
 IntToUnicode (Device_Serial0, &DFU_StringSerial[2] , 8);
 IntToUnicode (Device_Serial1, &DFU_StringSerial[18], 4);
 }
}
 
/*******************************************************************************
* Function Name : HexToChar.
* Description : Convert Hex 32Bits value into char.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
{
 uint8_t idx = 0;
 
 for( idx = 0 ; idx < len ; idx ++)
 {
 if( ((value >> 28)) < 0xA )
 {
 pbuf[ 2* idx] = (value >> 28) + '0';
 }
 else
 {
 pbuf[2* idx] = (value >> 28) + 'A' - 10;
 }
 
 value = value << 4;
 
 pbuf[ 2* idx + 1] = 0;
 }
} 

STM32 DFU Serial Unique

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
January 16, 2019

From F2 ROM

1FFF387A	SUB16	sub_1FFF387A:			; Xref 1FFF1F68
1FFF387A B538			push	{r3, r4, r5, lr}
1FFF387C 4811			ldr	r0, [pc, #68]	; ($1FFF38C4=$1FFF7A10)
1FFF387E 6801			ldr	r1, [r0, #0]
1FFF3880 6844			ldr	r4, [r0, #4]
1FFF3882 6880			ldr	r0, [r0, #8]
1FFF3884 1840			adds	r0, r0, r1
1FFF3886 D00A			beq.n	loc_1FFF389E
1FFF3888 4D0F			ldr	r5, [pc, #60]	; ($1FFF38C8=$200012C8)
1FFF388A 2208			movs	r2, #8
1FFF388C 1CA9			adds	r1, r5, #2
1FFF388E F000 F81D		bl	sub_1FFF38CC
1FFF3892 2204			movs	r2, #4
1FFF3894 F105 0112		add.w	r1, r5, #18	; $12
1FFF3898 4620			mov	r0, r4
1FFF389A F000 F817		bl	sub_1FFF38CC
1FFF389E	LOC	loc_1FFF389E:			; Xref 1FFF3886
1FFF389E BD31			pop	{r0, r4, r5, pc}

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
waclawek.jan
Super User
January 16, 2019

I doubt this is unique enough.

JW

Rob.Riggs
Rob.RiggsAuthor
Senior
January 16, 2019

Maybe ST would like to comment on why this implementation was chosen and what sort of uniqueness guarantees it does make.

Pavel A.
Super User
January 17, 2019

IIRC these ST serial numbers were documented in STM8 app.notes. They include date of producing the wafer and coordinates (X,Y) of the chip on the wafer. So each chip indeed has an unique id, if this scheme is actually applied in manufacturing process.

-- pa

Tesla DeLorean
Guru
January 17, 2019

The question however is more about the 12-byte ASCII serial number generated by the DFU/USB peripheral.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..