From 8f6efe5a7b8a830b6cd17b7c378fc4f2fa92f069 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 25 Nov 2019 00:25:57 -0500 Subject: [PATCH] stm32: Enable chipid as usb serial number Signed-off-by: Matt Baker Signed-off-by: Kevin O'Connor --- docs/Config_Changes.md | 6 +++--- src/stm32/Kconfig | 1 + src/stm32/Makefile | 2 +- src/stm32/chipid.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 src/stm32/chipid.c diff --git a/docs/Config_Changes.md b/docs/Config_Changes.md index f2a5c3c9..7b53b194 100644 --- a/docs/Config_Changes.md +++ b/docs/Config_Changes.md @@ -6,9 +6,9 @@ All dates in this document are approximate. # Changes -20191121: The USB name has changed on lpc176x. It now uses the unique -chip id by default. Update the "serial" setting in the "mcu" config -section accordingly. +20191124: The USB names have changed on lpc176x and stm32. They now +use the unique chip id by default. Update the "serial" setting in the +"mcu" config section accordingly. 20191121: The pressure_advance_lookahead_time parameter has been removed. See example.cfg for alternate configuration settings. diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig index 00ec72cd..bf1391b6 100644 --- a/src/stm32/Kconfig +++ b/src/stm32/Kconfig @@ -10,6 +10,7 @@ config STM32_SELECT select HAVE_GPIO_I2C select HAVE_GPIO_SPI select HAVE_GPIO_BITBANGING + select HAVE_CHIPID config BOARD_DIRECTORY string diff --git a/src/stm32/Makefile b/src/stm32/Makefile index c2511ee9..3a063402 100644 --- a/src/stm32/Makefile +++ b/src/stm32/Makefile @@ -37,7 +37,7 @@ src-$(CONFIG_MACH_STM32F4) += stm32/adc.c stm32/i2c.c src-$(CONFIG_HAVE_GPIO_SPI) += stm32/spi.c usb-src-$(CONFIG_HAVE_STM32_USBFS) := stm32/usbfs.c usb-src-$(CONFIG_HAVE_STM32_USBOTG) := stm32/usbotg.c -src-$(CONFIG_USBSERIAL) += $(usb-src-y) generic/usb_cdc.c +src-$(CONFIG_USBSERIAL) += $(usb-src-y) stm32/chipid.c generic/usb_cdc.c serial-src-y := stm32/serial.c serial-src-$(CONFIG_MACH_STM32F0) := stm32/stm32f0_serial.c src-$(CONFIG_SERIAL) += $(serial-src-y) generic/serial_irq.c diff --git a/src/stm32/chipid.c b/src/stm32/chipid.c new file mode 100644 index 00000000..73e27503 --- /dev/null +++ b/src/stm32/chipid.c @@ -0,0 +1,33 @@ +// Support for extracting the hardware chip id on stm32 +// +// Copyright (C) 2019 Kevin O'Connor +// +// This file may be distributed under the terms of the GNU GPLv3 license. + +#include "generic/usb_cdc.h" // usb_fill_serial +#include "generic/usbstd.h" // usb_string_descriptor +#include "internal.h" // UID_BASE +#include "sched.h" // DECL_INIT + +#define CHIP_UID_LEN 12 + +static struct { + struct usb_string_descriptor desc; + uint16_t data[CHIP_UID_LEN * 2]; +} cdc_chipid; + +struct usb_string_descriptor * +usbserial_get_serialid(void) +{ + return &cdc_chipid.desc; +} + +void +chipid_init(void) +{ + if (!CONFIG_USB_SERIAL_NUMBER_CHIPID) + return; + usb_fill_serial(&cdc_chipid.desc, ARRAY_SIZE(cdc_chipid.data) + , (void*)UID_BASE); +} +DECL_INIT(chipid_init);