99 * Copyright (c) 2019 Damien P. George 
1010 */ 
1111
12+ #include  <hardware/flash.h> 
1213#include  <tusb.h> 
1314
1415#define  DESC_STR_MAX  20
3637#define  USBD_STR_MANUF  0x01
3738#define  USBD_STR_PRODUCT  0x02
3839#define  USBD_STR_SERIAL  0x03
40+ #define  USBD_STR_SERIAL_LEN  17
3941#define  USBD_STR_CDC  0x04
4042
4143static  const  tusb_desc_device_t  usbd_desc_device  =  {
@@ -68,10 +70,12 @@ static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = {
6870		USBD_CDC_IN_OUT_MAX_SIZE ),
6971};
7072
73+ static  char  usbd_serial [USBD_STR_SERIAL_LEN ] =  "000000000000" ;
74+ 
7175static  const  char  * const  usbd_desc_str [] =  {
7276	[USBD_STR_MANUF ] =  "Raspberry Pi" ,
7377	[USBD_STR_PRODUCT ] =  "Pico" ,
74- 	[USBD_STR_SERIAL ] =  "000000000000" ,
78+ 	[USBD_STR_SERIAL ] =  usbd_serial ,
7579	[USBD_STR_CDC ] =  "Board CDC" ,
7680};
7781
@@ -95,6 +99,7 @@ const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid)
9599		len  =  1 ;
96100	} else  {
97101		const  char  * str ;
102+ 		char  serial [USBD_STR_SERIAL_LEN ];
98103
99104		if  (index  >= sizeof (usbd_desc_str ) / sizeof (usbd_desc_str [0 ]))
100105			return  NULL ;
@@ -108,3 +113,13 @@ const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid)
108113
109114	return  desc_str ;
110115}
116+ 
117+ void  usbd_serial_init (void )
118+ {
119+ 	uint8_t  id [8 ];
120+ 
121+ 	flash_get_unique_id (id );
122+ 
123+ 	snprintf (usbd_serial , USBD_STR_SERIAL_LEN , "%02X%02X%02X%02X%02X%02X%02X%02X" ,
124+ 		 id [0 ], id [1 ], id [2 ], id [3 ], id [4 ], id [5 ], id [6 ], id [7 ]);
125+ }
0 commit comments