summaryrefslogtreecommitdiff
path: root/usb-dfu-experiment
diff options
context:
space:
mode:
Diffstat (limited to 'usb-dfu-experiment')
-rw-r--r--usb-dfu-experiment/Makefile19
-rw-r--r--usb-dfu-experiment/main.c27
-rw-r--r--usb-dfu-experiment/sam3u_chipid_usbserial.c64
3 files changed, 71 insertions, 39 deletions
diff --git a/usb-dfu-experiment/Makefile b/usb-dfu-experiment/Makefile
index f273c65..95dd5b3 100644
--- a/usb-dfu-experiment/Makefile
+++ b/usb-dfu-experiment/Makefile
@@ -120,17 +120,15 @@ VPATH += $(UTILITY)
VPATH += $(PERIPH)/dbgu
VPATH += $(PERIPH)/pio
VPATH += $(PERIPH)/irq
-VPATH += $(PERIPH)/ssc
-VPATH += $(PERIPH)/twi
VPATH += $(PERIPH)/pmc
VPATH += $(PERIPH)/cp15
VPATH += $(BOARDS)/$(BOARD)
VPATH += $(BOARDS)/$(BOARD)/$(CHIP)
-VPATH += $(DRIVER)/twi
-VPATH += $(PERIPH)/mci
+VPATH += $(PERIPH)/eefc
VPATH += $(PERIPH)/dma
VPATH += $(DRIVER)/dmad
VPATH += $(EXT_LIBS)/cmsis
+VPATH += $(AT91LIB)/memories/flash
VPATH += $(USB)/device/core
VPATH += $(USB)/device/dfu
@@ -140,6 +138,7 @@ VPATH += $(USB)/common/audio
# Objects built from C source files
C_OBJECTS += main.o
C_OBJECTS += dfu_desc.o
+C_OBJECTS += sam3u_chipid_usbserial.o
C_OBJECTS += USBD_UDPHS.o
C_OBJECTS += USBDDriver.o
C_OBJECTS += USBDCallbacks_Initialized.o
@@ -161,17 +160,15 @@ C_OBJECTS += dfu_driver.o
C_OBJECTS += dbgu.o
C_OBJECTS += pio.o
C_OBJECTS += pio_it.o
-C_OBJECTS += ssc.o
-C_OBJECTS += twi.o
C_OBJECTS += pmc.o
C_OBJECTS += led.o
-C_OBJECTS += twid.o
C_OBJECTS += string.o
C_OBJECTS += stdio.o
C_OBJECTS += math.o
C_OBJECTS += trace.o
C_OBJECTS += board_memories.o
C_OBJECTS += board_lowlevel.o
+C_OBJECTS += flashd_eefc.o eefc.o
# Objects for different chips
@@ -185,14 +182,6 @@ C_OBJECTS += aic.o
C_OBJECTS += cp15.o
endif
-ifeq ($(CHIP_IP_MCI), MCI_DMA)
-C_OBJECTS += dmad.o
-C_OBJECTS += dma.o
-C_OBJECTS += mci_hs.o
-else
-C_OBJECTS += mci.o
-endif
-
# Objects built from Assembly source files
ifneq ($(CHIP_CORE), cortexm3)
ASM_OBJECTS += board_cstartup.o
diff --git a/usb-dfu-experiment/main.c b/usb-dfu-experiment/main.c
index 91c35b4..a939799 100644
--- a/usb-dfu-experiment/main.c
+++ b/usb-dfu-experiment/main.c
@@ -54,7 +54,6 @@
#include <usb/device/core/USBD.h>
#include <usb/device/core/USBDDriver.h>
-#include <usb/common/core/USBStringDescriptor.h>
#include <usb/device/dfu/dfu.h>
#include "dfu_desc.h"
@@ -260,28 +259,6 @@ void USBDCallbacks_Suspended(void)
USBState = STATE_SUSPEND;
}
-
-static int to_usb_string(char *out, int out_len, const char *in)
-{
- int in_len = strlen(in);
- int num_out = USBStringDescriptor_LENGTH(in_len);
- int i;
- char *cur = out;
-
- if (num_out > out_len || num_out >= 255 || num_out < 0)
- return -EINVAL;
-
- *cur++ = num_out;
- *cur++ = USBGenericDescriptor_STRING;
-
- for (i = 0; i < in_len; i++) {
- *cur++ = in[i];
- *cur++ = 0;
- }
-
- return cur - out;
-}
-
/* USBD callback */
void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
{
@@ -315,6 +292,7 @@ int USBDFU_handle_dnload(uint8_t altif, unsigned int offset,
uint8_t *buf, unsigned int len)
{
TRACE_INFO("DFU: handle_dnload(%u, %u, %u)\n\r", altif, offset, len);
+
return DFU_RET_ZLP;
}
@@ -324,7 +302,6 @@ void dfu_drv_updstatus(void)
TRACE_INFO("DFU: updstatus()\n\r");
}
-
/*----------------------------------------------------------------------------
* Exported functions
*----------------------------------------------------------------------------*/
@@ -341,6 +318,8 @@ int main(void)
printf("-- %s\n\r", BOARD_NAME);
printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
+ chipid_to_usbserial();
+
/* If they are present, configure Vbus & Wake-up pins */
PIO_InitializeInterrupts(0);
diff --git a/usb-dfu-experiment/sam3u_chipid_usbserial.c b/usb-dfu-experiment/sam3u_chipid_usbserial.c
new file mode 100644
index 0000000..c8d0e70
--- /dev/null
+++ b/usb-dfu-experiment/sam3u_chipid_usbserial.c
@@ -0,0 +1,64 @@
+#include <board.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#include <memories/flash/flashd.h>
+
+#include <usb/common/core/USBStringDescriptor.h>
+
+#include <usb/device/dfu/dfu.h>
+
+/* 128bit binary serial, equals 16 bytes -> 32 hex digits */
+static uint8_t usb_serial_string[USBStringDescriptor_LENGTH(32)];
+
+/* convert from 7-bit ASCII to USB string */
+static int to_usb_string(char *out, int out_len, const char *in)
+{
+ int in_len = strlen(in);
+ int num_out = USBStringDescriptor_LENGTH(in_len);
+ int i;
+ char *cur = out;
+
+ if (num_out > out_len || num_out >= 255 || num_out < 0)
+ return -EINVAL;
+
+ *cur++ = num_out;
+ *cur++ = USBGenericDescriptor_STRING;
+
+ for (i = 0; i < in_len; i++) {
+ *cur++ = in[i];
+ *cur++ = 0;
+ }
+
+ return cur - out;
+}
+
+static int chip_uid_to_usbstring(void)
+{
+ unsigned long uniqueID[4];
+ int rc;
+
+ FLASHD_Initialize(0);
+ rc = FLASHD_ReadUniqueID(&uniqueID);
+ if (rc != 0)
+ return -EIO;
+
+ /* we skip the step to transform the unique-id into hex before
+ * converting it into a USB string, as it seems to consist of ASCII
+ * characters instead of a true 128 bit binary unique identifier */
+ rc = to_usb_string(usb_serial_string, sizeof(usb_serial_string), (char *) uniqueID);
+ if (rc > 0)
+ return 0;
+
+ return rc;
+}
+
+int chipid_to_usbserial(void)
+{
+ chip_uid_to_usbstring();
+ set_usb_serial_str(usb_serial_string);
+}
personal git repositories of Harald Welte. Your mileage may vary