From 52b8063301b1a50d4907dc29c7f62dac5ee0362e Mon Sep 17 00:00:00 2001
From: "Wesley W. Terpstra" <w.terpstra@gsi.de>
Date: Thu, 4 Apr 2013 11:44:23 +0200
Subject: [PATCH] usb: eeprom erase scripts added

---
 hdl/eb_usb_core/.gitignore     | 10 ++++++++++
 hdl/eb_usb_core/Makefile       |  2 +-
 hdl/eb_usb_core/erase_eeprom.c | 10 +++++++++-
 hdl/eb_usb_core/flash-fx2lp.sh |  8 +++++++-
 4 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/hdl/eb_usb_core/.gitignore b/hdl/eb_usb_core/.gitignore
index 1db6c31..1e2f888 100644
--- a/hdl/eb_usb_core/.gitignore
+++ b/hdl/eb_usb_core/.gitignore
@@ -8,3 +8,13 @@ cdc_acm.omf
 cdc_acm.rel
 cdc_acm.rst
 cdc_acm.sym
+erase_eeprom.asm
+erase_eeprom.cdb
+erase_eeprom.lk
+erase_eeprom.lst
+erase_eeprom.map
+erase_eeprom.mem
+erase_eeprom.omf
+erase_eeprom.rel
+erase_eeprom.rst
+erase_eeprom.sym
diff --git a/hdl/eb_usb_core/Makefile b/hdl/eb_usb_core/Makefile
index 1c685ff..507b0fe 100644
--- a/hdl/eb_usb_core/Makefile
+++ b/hdl/eb_usb_core/Makefile
@@ -1,4 +1,4 @@
-TARGETS = cdc_acm.ihx
+TARGETS = cdc_acm.ihx erase_eeprom.ihx
 
 all:	$(TARGETS)
 
diff --git a/hdl/eb_usb_core/erase_eeprom.c b/hdl/eb_usb_core/erase_eeprom.c
index 0f21f4d..86a49ef 100644
--- a/hdl/eb_usb_core/erase_eeprom.c
+++ b/hdl/eb_usb_core/erase_eeprom.c
@@ -12,7 +12,15 @@
  * 
  */
 
-#include <fx2regs.h>
+#define ALLOCATE_EXTERN
+#define xdata __xdata
+#define at __at
+#define sfr __sfr
+#define bit __bit
+#define code __code
+#define sbit __sbit
+
+#include "fx2regs.h"
 #define SYNCDELAY       _asm  nop; _endasm
         
 #define I2CREAD     0x01    /* 00000001 */
diff --git a/hdl/eb_usb_core/flash-fx2lp.sh b/hdl/eb_usb_core/flash-fx2lp.sh
index de95492..63e2b0b 100755
--- a/hdl/eb_usb_core/flash-fx2lp.sh
+++ b/hdl/eb_usb_core/flash-fx2lp.sh
@@ -17,5 +17,11 @@ busid() {
 
 dev=`busid $PROGRAMMED $RAW_CYPRESS`
 
+# If unprogrammed, "usbtest" steals the device
 rmmod usbtest 2>/dev/null
-fxload -D "$dev" -tfx2lp -I cdc_acm.ihx -s vend_ax.hex -c 0x41 -v
+
+if [ "$1" = "-E" ]; then
+  fxload -D "$dev" -tfx2lp -I erase_eeprom.ihx -v
+else
+  fxload -D "$dev" -tfx2lp -I cdc_acm.ihx -s vend_ax.hex -c 0x41 -v
+fi
-- 
GitLab