Merge pull request #1139 from hathach/nrf52_usb_serial
use unique DevicID for usb serial
This commit is contained in:
commit
728622f09d
|
@ -58,7 +58,7 @@ void usb_init(void) {
|
|||
|
||||
sd_power_usbregstatus_get(&usb_reg);
|
||||
}else
|
||||
#else
|
||||
#endif
|
||||
{
|
||||
// Power module init
|
||||
const nrfx_power_config_t pwr_cfg = { 0 };
|
||||
|
@ -72,7 +72,6 @@ void usb_init(void) {
|
|||
|
||||
usb_reg = NRF_POWER->USBREGSTATUS;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk ) {
|
||||
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_DETECTED);
|
||||
|
@ -82,6 +81,21 @@ void usb_init(void) {
|
|||
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
|
||||
}
|
||||
|
||||
// create serial number based on device unique id
|
||||
extern uint16_t usb_desc_str_serial[1 + 16];
|
||||
|
||||
char nibble_to_hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
uint8_t nibble = (NRF_FICR->DEVICEID[i] >> j * 4) & 0xf;
|
||||
|
||||
// Invert order since it is LE, +1 for skipping descriptor header
|
||||
uint8_t const idx = (15 - (i * 8 + j)) + 1;
|
||||
usb_desc_str_serial[idx] = nibble_to_hex[nibble];
|
||||
}
|
||||
}
|
||||
|
||||
tusb_init();
|
||||
|
||||
#if MICROPY_KBD_EXCEPTION
|
||||
|
|
|
@ -78,6 +78,8 @@ enum {
|
|||
// STRING DESCRIPTORS
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
uint16_t usb_desc_str_serial[1+16] = { TUD_DESC_STR_HEADER(16) };
|
||||
|
||||
// array of pointer to string descriptors
|
||||
uint16_t const * const string_desc_arr [] =
|
||||
{
|
||||
|
@ -91,7 +93,7 @@ uint16_t const * const string_desc_arr [] =
|
|||
TUD_DESC_STRCONV('C','i','r','c','u','i','t','P','y',' ','n','R','F','5','2'),
|
||||
|
||||
// 3 Serials TODO use chip ID
|
||||
TUD_DESC_STRCONV('1', '2', '3', '4', '5'),
|
||||
usb_desc_str_serial,
|
||||
|
||||
// 4 CDC Interface
|
||||
TUD_DESC_STRCONV('C','i','r','c','u','i','t','P','y',' ','S','e','r','i','a','l'),
|
||||
|
|
Loading…
Reference in New Issue