aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/Config_Changes.md6
-rw-r--r--src/atsamd/Kconfig1
-rw-r--r--src/atsamd/Makefile2
-rw-r--r--src/atsamd/chipid.c45
4 files changed, 50 insertions, 4 deletions
diff --git a/docs/Config_Changes.md b/docs/Config_Changes.md
index 7b53b194..fed5f79d 100644
--- a/docs/Config_Changes.md
+++ b/docs/Config_Changes.md
@@ -6,9 +6,9 @@ All dates in this document are approximate.
# Changes
-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.
+20191124: The USB names have changed on lpc176x, stm32, and atsamd.
+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/atsamd/Kconfig b/src/atsamd/Kconfig
index b847291c..5fb0b26b 100644
--- a/src/atsamd/Kconfig
+++ b/src/atsamd/Kconfig
@@ -11,6 +11,7 @@ config ATSAMD_SELECT
select HAVE_GPIO_SPI
select HAVE_GPIO_HARD_PWM if MACH_SAMD21
select HAVE_GPIO_BITBANGING
+ select HAVE_CHIPID
config BOARD_DIRECTORY
string
diff --git a/src/atsamd/Makefile b/src/atsamd/Makefile
index 2ff91df1..3fe2a4e9 100644
--- a/src/atsamd/Makefile
+++ b/src/atsamd/Makefile
@@ -21,7 +21,7 @@ $(OUT)klipper.elf: $(OUT)src/generic/armcm_link.ld
# Add source files
src-y += atsamd/main.c atsamd/gpio.c generic/crc16_ccitt.c
src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_reset.c
-src-$(CONFIG_USBSERIAL) += atsamd/usbserial.c generic/usb_cdc.c
+src-$(CONFIG_USBSERIAL) += atsamd/usbserial.c atsamd/chipid.c generic/usb_cdc.c
src-$(CONFIG_SERIAL) += atsamd/serial.c generic/serial_irq.c
src-$(CONFIG_HAVE_GPIO_ADC) += atsamd/adc.c
src-$(CONFIG_HAVE_GPIO_I2C) += atsamd/i2c.c
diff --git a/src/atsamd/chipid.c b/src/atsamd/chipid.c
new file mode 100644
index 00000000..a4e378bc
--- /dev/null
+++ b/src/atsamd/chipid.c
@@ -0,0 +1,45 @@
+// Support for extracting the hardware chip id on atsamd
+//
+// Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
+#include "autoconf.h" // CONFIG_USB_SERIAL_NUMBER_CHIPID
+#include "generic/usb_cdc.h" // usb_fill_serial
+#include "generic/usbstd.h" // usb_string_descriptor
+#include "sched.h" // DECL_INIT
+
+#define CHIP_UID_LEN 16
+
+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;
+
+ uint32_t id[4];
+ if (CONFIG_MACH_SAMD21) {
+ id[0] = *(uint32_t*)0x0080A00C;
+ id[1] = *(uint32_t*)0x0080A040;
+ id[2] = *(uint32_t*)0x0080A044;
+ id[3] = *(uint32_t*)0x0080A048;
+ } else {
+ id[0] = *(uint32_t*)0x008061FC;
+ id[1] = *(uint32_t*)0x00806010;
+ id[2] = *(uint32_t*)0x00806014;
+ id[3] = *(uint32_t*)0x00806018;
+ }
+ usb_fill_serial(&cdc_chipid.desc, ARRAY_SIZE(cdc_chipid.data), id);
+}
+DECL_INIT(chipid_init);