Commits

Anonymous committed 1fd1a01

Updated all examples to use a common make system to provide
targets for loading firmware, iic files etc to all examples uniformly.

Comments (0)

Files changed (10)

 The examples here show various firmware examples and also various ways to
-start communicating with your device.
+start new firmware projects as well as various ways to start communicating with your device.
+In addition, you can look at the fx2.mk include and the example project Makefiles
+to see how you might set up your own project.
+
+For simple examples, you can ignore the link warnings. (Those pertain to the usb jump table
+and device descriptor areas and are not used for all examples)
 
 You can move up the food chain of programming languages pretty quickly if you like:
 
  
  There is also an fx2load script for doing the same thing with the command line.
 
+eeprom:
+ Simple firmware for reading and writing information from the eeprom.  The client.py
+ file contains a function to read an existing prom image.
+
 
 lights:
  A really simple program that cycles the lights on the CY3864 development board.

examples/bulkloop/Makefile

-INCLUDES = -I../../include
-LIBS = fx2.lib -L../../lib
-CC = sdcc -mmcs51 --code-size 0x2000 --xram-loc 0x3000 \
-	 -Wl"-b DSCR_AREA = 0x2000" \
-	 -Wl"-b INT2JT = 0x2200"
-
+FX2LIBDIR=../../
 BASENAME = bulkloop
-DSCR = dscr.rel
-
-$(BASENAME).ihx: $(BASENAME).c $(DSCR)
-	$(CC) $(INCLUDES) $(BASENAME).c $(DSCR) $(LIBS)
-
-$(DSCR): dscr.a51
-	asx8051 -logs dscr.a51
-
-$(BASENAME).bix: $(BASENAME).ihx
-	objcopy -I ihex -O binary $(BASENAME).ihx $(BASENAME).bix
-
-clean:
-	rm -f *.{asm,ihx,lnk,lst,map,mem,rel,rst,sym,adb,cdb,bix}
+SOURCES=bulkloop.c
+A51_SOURCES=dscr.a51
 
-.PHONY:run bix
-run: $(BASENAME).bix
-	python load.py
 
-bix: $(BASENAME).bix
+include ../fx2.mk
 
 test: test.cpp
 	g++ -o test test.cpp -lusb-1.0

examples/eeprom/firmware/Makefile

-INCLUDES = -I../../../include
-LIBS = fx2.lib -L../../../lib
-CC = sdcc -mmcs51 \
-	--xram-loc 0x3000 \
-    --xram-size 0x1000 \
-	-Wl"-b DSCR_AREA = 0x2800" \
-	-Wl"-b INT2JT = 0x2b00"
-
+FX2LIBDIR=../../..
 BASENAME = eeprom
-DSCR = dscr.rel
-
-$(BASENAME).ihx: $(BASENAME).c $(DSCR)
-	$(CC) $(INCLUDES) $(BASENAME).c $(DSCR) $(LIBS)
-
-$(DSCR): dscr_asm
-	cp dscr_asm dscr.asm
-	asx8051 -logs dscr.asm
-
-$(BASENAME).bix: $(BASENAME).ihx
-	objcopy -I ihex -O binary $(BASENAME).ihx $(BASENAME).bix
-
-clean:
-	rm -f *.{asm,ihx,lnk,lst,map,mem,rel,rst,sym,adb,cdb,bix}
-
-.PHONY:bix
-
-bix: $(BASENAME).bix
+SOURCES=eeprom.c
+A51_SOURCES=dscr.a51
 
+include ../../fx2.mk

examples/eeprom/firmware/dscr.a51

+; Copyright (C) 2009 Ubixum, Inc. 
+;
+; This library is free software; you can redistribute it and/or
+; modify it under the terms of the GNU Lesser General Public
+; License as published by the Free Software Foundation; either
+; version 2.1 of the License, or (at your option) any later version.
+; 
+; This library is distributed in the hope that it will be useful,
+; but WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+; Lesser General Public License for more details.
+; 
+; You should have received a copy of the GNU Lesser General Public
+; License along with this library; if not, write to the Free Software
+; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+; this is a the default 
+; full speed and high speed 
+; descriptors found in the TRM
+; change however you want but leave 
+; the descriptor pointers so the setupdat.c file works right
+ 
+
+.module DEV_DSCR 
+
+; descriptor types
+; same as setupdat.h
+DSCR_DEVICE_TYPE=1
+DSCR_CONFIG_TYPE=2
+DSCR_STRING_TYPE=3
+DSCR_INTERFACE_TYPE=4
+DSCR_ENDPOINT_TYPE=5
+DSCR_DEVQUAL_TYPE=6
+
+; for the repeating interfaces
+DSCR_INTERFACE_LEN=9
+DSCR_ENDPOINT_LEN=7
+
+; endpoint types
+ENDPOINT_TYPE_CONTROL=0
+ENDPOINT_TYPE_ISO=1
+ENDPOINT_TYPE_BULK=2
+ENDPOINT_TYPE_INT=3
+
+    .globl	_dev_dscr, _dev_qual_dscr, _highspd_dscr, _fullspd_dscr, _dev_strings, _dev_strings_end
+; These need to be in code memory.  If
+; they aren't you'll have to manully copy them somewhere
+; in code memory otherwise SUDPTRH:L don't work right
+    .area  DSCR_AREA	(CODE)
+
+_dev_dscr:
+	.db	dev_dscr_end-_dev_dscr    ; len
+	.db	DSCR_DEVICE_TYPE		  ; type
+	.dw	0x0002					  ; usb 2.0
+	.db	0xff  					  ; class (vendor specific)
+	.db	0xff					  ; subclass (vendor specific)
+	.db	0xff					  ; protocol (vendor specific)
+	.db	64						  ; packet size (ep0)
+	.dw	0xb404			      ; vendor id 
+	.dw	0x8300					  ; product id
+	.dw	0x0100					  ; version id
+	.db	0		                  ; manufacturure str idx				
+	.db	1				          ; product str idx	
+	.db	0				          ; serial str idx 
+	.db	1			              ; n configurations
+dev_dscr_end:
+
+_dev_qual_dscr:
+	.db	dev_qualdscr_end-_dev_qual_dscr
+	.db	DSCR_DEVQUAL_TYPE
+	.dw	0x0002                              ; usb 2.0
+	.db	0xff
+	.db	0xff
+	.db	0xff
+	.db	64                                  ; max packet
+	.db	1									; n configs
+	.db	0									; extra reserved byte
+dev_qualdscr_end:
+
+_highspd_dscr:
+	.db	highspd_dscr_end-_highspd_dscr      ; dscr len											;; Descriptor length
+	.db	DSCR_CONFIG_TYPE
+    ; can't use .dw because byte order is different
+	.db	(highspd_dscr_realend-_highspd_dscr) % 256 ; total length of config lsb
+	.db	(highspd_dscr_realend-_highspd_dscr) / 256 ; total length of config msb
+	.db	1								 ; n interfaces
+	.db	1								 ; config number
+	.db	0								 ; config string
+	.db	0x80                             ; attrs = bus powered, no wakeup
+	.db	0x32                             ; max power = 100ma
+highspd_dscr_end:
+
+; all the interfaces next 
+; NOTE the default TRM actually has more alt interfaces
+; but you can add them back in if you need them.
+; here, we just use the default alt setting 1 from the trm
+	.db	DSCR_INTERFACE_LEN
+	.db	DSCR_INTERFACE_TYPE
+	.db	0				 ; index
+	.db	0				 ; alt setting idx
+	.db	6				 ; n endpoints	
+	.db	0xff			 ; class
+	.db	0xff
+	.db	0xff
+	.db	0	             ; string index	
+
+; endpoint 1 out
+	.db	DSCR_ENDPOINT_LEN
+	.db	DSCR_ENDPOINT_TYPE
+	.db	0x01				;  ep1 dir=out and address
+	.db	ENDPOINT_TYPE_BULK	; type
+	.db	0x00				; max packet LSB
+	.db	0x02				; max packet size=512 bytes
+	.db	0x00				; polling interval
+      
+; endpoint 1 in 
+	.db	DSCR_ENDPOINT_LEN
+	.db	DSCR_ENDPOINT_TYPE
+	.db	0x81				;  ep1 dir=in and address
+	.db	ENDPOINT_TYPE_BULK	; type
+	.db	0x00				; max packet LSB
+	.db	0x02				; max packet size=512 bytes
+	.db	0x00				; polling interval
+
+; endpoint 2 out
+	.db	DSCR_ENDPOINT_LEN
+	.db	DSCR_ENDPOINT_TYPE
+	.db	0x02				;  ep2 dir=OUT and address
+	.db	ENDPOINT_TYPE_BULK	; type
+	.db	0x00				; max packet LSB
+	.db	0x02				; max packet size=512 bytes
+	.db	0x00				; polling interval
+
+; endpoint 4 out
+	.db	DSCR_ENDPOINT_LEN
+	.db	DSCR_ENDPOINT_TYPE
+	.db	0x04				;  ep4 dir=OUT and address
+	.db	ENDPOINT_TYPE_BULK	; type
+	.db	0x00				; max packet LSB
+	.db	0x02				; max packet size=512 bytes
+	.db	0x00				; polling interval
+
+; endpoint 6 in
+	.db	DSCR_ENDPOINT_LEN
+	.db	DSCR_ENDPOINT_TYPE
+	.db	0x86				;  ep6 dir=in and address
+	.db	ENDPOINT_TYPE_BULK	; type
+	.db	0x00				; max packet LSB
+	.db	0x02				; max packet size=512 bytes
+	.db	0x00				; polling interval
+
+; endpoint 8 in
+	.db	DSCR_ENDPOINT_LEN
+	.db	DSCR_ENDPOINT_TYPE
+	.db	0x88				;  ep8 dir=in and address
+	.db	ENDPOINT_TYPE_BULK	; type
+	.db	0x00				; max packet LSB
+	.db	0x02				; max packet size=512 bytes
+	.db	0x00				; polling interval
+highspd_dscr_realend:
+
+_fullspd_dscr:
+	.db	fullspd_dscr_end-_fullspd_dscr      ; dscr len
+	.db	DSCR_CONFIG_TYPE
+    ; can't use .dw because byte order is different
+	.db	(fullspd_dscr_realend-_fullspd_dscr) % 256 ; total length of config lsb
+	.db	(fullspd_dscr_realend-_fullspd_dscr) / 256 ; total length of config msb
+	.db	1								 ; n interfaces
+	.db	1								 ; config number
+	.db	0								 ; config string
+	.db	0x80                             ; attrs = bus powered, no wakeup
+	.db	0x32                             ; max power = 100ma
+fullspd_dscr_end:
+
+; all the interfaces next 
+; NOTE the default TRM actually has more alt interfaces
+; but you can add them back in if you need them.
+; here, we just use the default alt setting 1 from the trm
+	.db	DSCR_INTERFACE_LEN
+	.db	DSCR_INTERFACE_TYPE
+	.db	0				 ; index
+	.db	0				 ; alt setting idx
+	.db	6				 ; n endpoints	
+	.db	0xff			 ; class
+	.db	0xff
+	.db	0xff
+	.db	0	             ; string index	
+
+; endpoint 1 out
+	.db	DSCR_ENDPOINT_LEN
+	.db	DSCR_ENDPOINT_TYPE
+	.db	0x01				;  ep1 dir=out and address
+	.db	ENDPOINT_TYPE_BULK	; type
+	.db	0x40				; max packet LSB
+	.db	0x00				; max packet size=64 bytes
+	.db	0x00				; polling interval
+      
+; endpoint 1 in 
+	.db	DSCR_ENDPOINT_LEN
+	.db	DSCR_ENDPOINT_TYPE
+	.db	0x81				;  ep1 dir=in and address
+	.db	ENDPOINT_TYPE_BULK	; type
+	.db	0x40				; max packet LSB
+	.db	0x00				; max packet size=64 bytes
+	.db	0x00				; polling interval
+
+; endpoint 2 out
+	.db	DSCR_ENDPOINT_LEN
+	.db	DSCR_ENDPOINT_TYPE
+	.db	0x02				;  ep2 dir=OUT and address
+	.db	ENDPOINT_TYPE_BULK	; type
+	.db	0x40				; max packet LSB
+	.db	0x00				; max packet size=64 bytes
+	.db	0x00				; polling interval
+
+; endpoint 4 out
+	.db	DSCR_ENDPOINT_LEN
+	.db	DSCR_ENDPOINT_TYPE
+	.db	0x04				;  ep4 dir=OUT and address
+	.db	ENDPOINT_TYPE_BULK	; type
+	.db	0x40				; max packet LSB
+	.db	0x00				; max packet size=64 bytes
+	.db	0x00				; polling interval
+
+; endpoint 6 in
+	.db	DSCR_ENDPOINT_LEN
+	.db	DSCR_ENDPOINT_TYPE
+	.db	0x86				;  ep6 dir=in and address
+	.db	ENDPOINT_TYPE_BULK	; type
+	.db	0x40				; max packet LSB
+	.db	0x00				; max packet size=64 bytes
+	.db	0x00				; polling interval
+; endpoint 6 in
+	.db	DSCR_ENDPOINT_LEN
+	.db	DSCR_ENDPOINT_TYPE
+	.db	0x88				;  ep6 dir=in and address
+	.db	ENDPOINT_TYPE_BULK	; type
+	.db	0x40				; max packet LSB
+	.db	0x00				; max packet size=64 bytes
+	.db	0x00				; polling interval
+fullspd_dscr_realend:
+
+_dev_strings:
+; sample string
+_string0:
+	.db	string0end-_string0 ; len
+	.db	DSCR_STRING_TYPE
+    .db 0x09, 0x04 ; 0x0409 is the language code for English.  Possible to add more codes after this. 
+string0end:
+; add more strings here
+
+string1:
+    .db string1end-string1
+    .db DSCR_STRING_TYPE
+    .ascii 'U'
+    .db 0
+    .ascii 's'
+    .db 0
+    .ascii 'b'
+    .db 0
+    .ascii ' '
+    .db 0
+    .ascii 'T'
+    .db 0
+    .ascii 'e'
+    .db 0
+    .ascii 'r'
+    .db 0
+    .ascii 'm'
+    .db 0
+string1end:
+
+_dev_strings_end:
+    .dw 0x0000
+; in case you wanted to look at memory between _dev_strings and _dev_strings_end

examples/eeprom/firmware/dscr_asm

-; Copyright (C) 2009 Ubixum, Inc. 
-;
-; This library is free software; you can redistribute it and/or
-; modify it under the terms of the GNU Lesser General Public
-; License as published by the Free Software Foundation; either
-; version 2.1 of the License, or (at your option) any later version.
-; 
-; This library is distributed in the hope that it will be useful,
-; but WITHOUT ANY WARRANTY; without even the implied warranty of
-; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-; Lesser General Public License for more details.
-; 
-; You should have received a copy of the GNU Lesser General Public
-; License along with this library; if not, write to the Free Software
-; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-
-; this is a the default 
-; full speed and high speed 
-; descriptors found in the TRM
-; change however you want but leave 
-; the descriptor pointers so the setupdat.c file works right
- 
-
-.module DEV_DSCR 
-
-; descriptor types
-; same as setupdat.h
-DSCR_DEVICE_TYPE=1
-DSCR_CONFIG_TYPE=2
-DSCR_STRING_TYPE=3
-DSCR_INTERFACE_TYPE=4
-DSCR_ENDPOINT_TYPE=5
-DSCR_DEVQUAL_TYPE=6
-
-; for the repeating interfaces
-DSCR_INTERFACE_LEN=9
-DSCR_ENDPOINT_LEN=7
-
-; endpoint types
-ENDPOINT_TYPE_CONTROL=0
-ENDPOINT_TYPE_ISO=1
-ENDPOINT_TYPE_BULK=2
-ENDPOINT_TYPE_INT=3
-
-    .globl	_dev_dscr, _dev_qual_dscr, _highspd_dscr, _fullspd_dscr, _dev_strings, _dev_strings_end
-; These need to be in code memory.  If
-; they aren't you'll have to manully copy them somewhere
-; in code memory otherwise SUDPTRH:L don't work right
-    .area  DSCR_AREA	(CODE)
-
-_dev_dscr:
-	.db	dev_dscr_end-_dev_dscr    ; len
-	.db	DSCR_DEVICE_TYPE		  ; type
-	.dw	0x0002					  ; usb 2.0
-	.db	0xff  					  ; class (vendor specific)
-	.db	0xff					  ; subclass (vendor specific)
-	.db	0xff					  ; protocol (vendor specific)
-	.db	64						  ; packet size (ep0)
-	.dw	0xb404			      ; vendor id 
-	.dw	0x8300					  ; product id
-	.dw	0x0100					  ; version id
-	.db	0		                  ; manufacturure str idx				
-	.db	1				          ; product str idx	
-	.db	0				          ; serial str idx 
-	.db	1			              ; n configurations
-dev_dscr_end:
-
-_dev_qual_dscr:
-	.db	dev_qualdscr_end-_dev_qual_dscr
-	.db	DSCR_DEVQUAL_TYPE
-	.dw	0x0002                              ; usb 2.0
-	.db	0xff
-	.db	0xff
-	.db	0xff
-	.db	64                                  ; max packet
-	.db	1									; n configs
-	.db	0									; extra reserved byte
-dev_qualdscr_end:
-
-_highspd_dscr:
-	.db	highspd_dscr_end-_highspd_dscr      ; dscr len											;; Descriptor length
-	.db	DSCR_CONFIG_TYPE
-    ; can't use .dw because byte order is different
-	.db	(highspd_dscr_realend-_highspd_dscr) % 256 ; total length of config lsb
-	.db	(highspd_dscr_realend-_highspd_dscr) / 256 ; total length of config msb
-	.db	1								 ; n interfaces
-	.db	1								 ; config number
-	.db	0								 ; config string
-	.db	0x80                             ; attrs = bus powered, no wakeup
-	.db	0x32                             ; max power = 100ma
-highspd_dscr_end:
-
-; all the interfaces next 
-; NOTE the default TRM actually has more alt interfaces
-; but you can add them back in if you need them.
-; here, we just use the default alt setting 1 from the trm
-	.db	DSCR_INTERFACE_LEN
-	.db	DSCR_INTERFACE_TYPE
-	.db	0				 ; index
-	.db	0				 ; alt setting idx
-	.db	6				 ; n endpoints	
-	.db	0xff			 ; class
-	.db	0xff
-	.db	0xff
-	.db	0	             ; string index	
-
-; endpoint 1 out
-	.db	DSCR_ENDPOINT_LEN
-	.db	DSCR_ENDPOINT_TYPE
-	.db	0x01				;  ep1 dir=out and address
-	.db	ENDPOINT_TYPE_BULK	; type
-	.db	0x00				; max packet LSB
-	.db	0x02				; max packet size=512 bytes
-	.db	0x00				; polling interval
-      
-; endpoint 1 in 
-	.db	DSCR_ENDPOINT_LEN
-	.db	DSCR_ENDPOINT_TYPE
-	.db	0x81				;  ep1 dir=in and address
-	.db	ENDPOINT_TYPE_BULK	; type
-	.db	0x00				; max packet LSB
-	.db	0x02				; max packet size=512 bytes
-	.db	0x00				; polling interval
-
-; endpoint 2 out
-	.db	DSCR_ENDPOINT_LEN
-	.db	DSCR_ENDPOINT_TYPE
-	.db	0x02				;  ep2 dir=OUT and address
-	.db	ENDPOINT_TYPE_BULK	; type
-	.db	0x00				; max packet LSB
-	.db	0x02				; max packet size=512 bytes
-	.db	0x00				; polling interval
-
-; endpoint 4 out
-	.db	DSCR_ENDPOINT_LEN
-	.db	DSCR_ENDPOINT_TYPE
-	.db	0x04				;  ep4 dir=OUT and address
-	.db	ENDPOINT_TYPE_BULK	; type
-	.db	0x00				; max packet LSB
-	.db	0x02				; max packet size=512 bytes
-	.db	0x00				; polling interval
-
-; endpoint 6 in
-	.db	DSCR_ENDPOINT_LEN
-	.db	DSCR_ENDPOINT_TYPE
-	.db	0x86				;  ep6 dir=in and address
-	.db	ENDPOINT_TYPE_BULK	; type
-	.db	0x00				; max packet LSB
-	.db	0x02				; max packet size=512 bytes
-	.db	0x00				; polling interval
-
-; endpoint 8 in
-	.db	DSCR_ENDPOINT_LEN
-	.db	DSCR_ENDPOINT_TYPE
-	.db	0x88				;  ep8 dir=in and address
-	.db	ENDPOINT_TYPE_BULK	; type
-	.db	0x00				; max packet LSB
-	.db	0x02				; max packet size=512 bytes
-	.db	0x00				; polling interval
-highspd_dscr_realend:
-
-_fullspd_dscr:
-	.db	fullspd_dscr_end-_fullspd_dscr      ; dscr len
-	.db	DSCR_CONFIG_TYPE
-    ; can't use .dw because byte order is different
-	.db	(fullspd_dscr_realend-_fullspd_dscr) % 256 ; total length of config lsb
-	.db	(fullspd_dscr_realend-_fullspd_dscr) / 256 ; total length of config msb
-	.db	1								 ; n interfaces
-	.db	1								 ; config number
-	.db	0								 ; config string
-	.db	0x80                             ; attrs = bus powered, no wakeup
-	.db	0x32                             ; max power = 100ma
-fullspd_dscr_end:
-
-; all the interfaces next 
-; NOTE the default TRM actually has more alt interfaces
-; but you can add them back in if you need them.
-; here, we just use the default alt setting 1 from the trm
-	.db	DSCR_INTERFACE_LEN
-	.db	DSCR_INTERFACE_TYPE
-	.db	0				 ; index
-	.db	0				 ; alt setting idx
-	.db	6				 ; n endpoints	
-	.db	0xff			 ; class
-	.db	0xff
-	.db	0xff
-	.db	0	             ; string index	
-
-; endpoint 1 out
-	.db	DSCR_ENDPOINT_LEN
-	.db	DSCR_ENDPOINT_TYPE
-	.db	0x01				;  ep1 dir=out and address
-	.db	ENDPOINT_TYPE_BULK	; type
-	.db	0x40				; max packet LSB
-	.db	0x00				; max packet size=64 bytes
-	.db	0x00				; polling interval
-      
-; endpoint 1 in 
-	.db	DSCR_ENDPOINT_LEN
-	.db	DSCR_ENDPOINT_TYPE
-	.db	0x81				;  ep1 dir=in and address
-	.db	ENDPOINT_TYPE_BULK	; type
-	.db	0x40				; max packet LSB
-	.db	0x00				; max packet size=64 bytes
-	.db	0x00				; polling interval
-
-; endpoint 2 out
-	.db	DSCR_ENDPOINT_LEN
-	.db	DSCR_ENDPOINT_TYPE
-	.db	0x02				;  ep2 dir=OUT and address
-	.db	ENDPOINT_TYPE_BULK	; type
-	.db	0x40				; max packet LSB
-	.db	0x00				; max packet size=64 bytes
-	.db	0x00				; polling interval
-
-; endpoint 4 out
-	.db	DSCR_ENDPOINT_LEN
-	.db	DSCR_ENDPOINT_TYPE
-	.db	0x04				;  ep4 dir=OUT and address
-	.db	ENDPOINT_TYPE_BULK	; type
-	.db	0x40				; max packet LSB
-	.db	0x00				; max packet size=64 bytes
-	.db	0x00				; polling interval
-
-; endpoint 6 in
-	.db	DSCR_ENDPOINT_LEN
-	.db	DSCR_ENDPOINT_TYPE
-	.db	0x86				;  ep6 dir=in and address
-	.db	ENDPOINT_TYPE_BULK	; type
-	.db	0x40				; max packet LSB
-	.db	0x00				; max packet size=64 bytes
-	.db	0x00				; polling interval
-; endpoint 6 in
-	.db	DSCR_ENDPOINT_LEN
-	.db	DSCR_ENDPOINT_TYPE
-	.db	0x88				;  ep6 dir=in and address
-	.db	ENDPOINT_TYPE_BULK	; type
-	.db	0x40				; max packet LSB
-	.db	0x00				; max packet size=64 bytes
-	.db	0x00				; polling interval
-fullspd_dscr_realend:
-
-_dev_strings:
-; sample string
-_string0:
-	.db	string0end-_string0 ; len
-	.db	DSCR_STRING_TYPE
-    .db 0x09, 0x04 ; 0x0409 is the language code for English.  Possible to add more codes after this. 
-string0end:
-; add more strings here
-
-string1:
-    .db string1end-string1
-    .db DSCR_STRING_TYPE
-    .ascii 'U'
-    .db 0
-    .ascii 's'
-    .db 0
-    .ascii 'b'
-    .db 0
-    .ascii ' '
-    .db 0
-    .ascii 'T'
-    .db 0
-    .ascii 'e'
-    .db 0
-    .ascii 'r'
-    .db 0
-    .ascii 'm'
-    .db 0
-string1end:
-
-_dev_strings_end:
-    .dw 0x0000
-; in case you wanted to look at memory between _dev_strings and _dev_strings_end
+# common make targets for compiling fx2 firmware
+#
+# In your Makefile, define:
+# SOURCES: list of c files to compile
+# A51_SOURCES: list of any a51 files.
+# BASENAME: name of your firmware file, i.e., myfirmware, but not myfirmware.c
+# FX2LIBDIR: top directory of fx2lib.  Contains lib and include dirs
+#
+# Provided targets:
+#
+# default target: creates $(BASENAME).ihx
+# bix: creates $(BASENAME).bix
+# iic: creates $(BASENAME).iic
+# load: uses fx2load to load firmware.bix onto the development board
+#  (You can customize VID/PID if you need to load the firmware onto a device that has different vendor and product id
+#  The default is  0x04b4, 0x8613
+# clean: delete all the temp files.
+#
+#
+#
+
+ifndef VID
+VID=0x04b4
+endif
+ifndef PID
+PID=0x8613
+endif
+
+RELS=$(SOURCES:.c=.rel) $(A51_SOURCES:.a51=.rel)
+# these are pretty good settings for most firmwares.  
+# Have to be careful with memory locations for 
+# firmwares that require more xram etc.
+CC = sdcc -mmcs51 \
+	$(SDCCFLAGS) \
+   --code-size 0x3c00 \
+   --xram-size 0x0200 \
+    --xram-loc 0x3c00 \
+	-Wl"-b DSCR_AREA = 0x3e00" \
+	-Wl"-b INT2JT = 0x3f00" \
+
+
+.PHONY: ihx iic bix load clean
+
+
+ihx: $(BASENAME).ihx
+bix: $(BASENAME).bix
+iic: $(BASENAME).iic
+
+$(BASENAME).ihx: $(SOURCES) $(A51_SOURCES)
+	# can't use default target %.rel because there is no way
+	# to differentiate the dependency.  (Is it %.rel: %.c or %.a51)
+	for a in $(A51_SOURCES); do \
+	 asx8051 -logs $$a; done
+	for s in $(SOURCES); do \
+	 $(CC) -c -I $(FX2LIBDIR)/include $$s; done
+	$(CC) -o $(BASENAME).ihx $(RELS) fx2.lib -L $(FX2LIBDIR)/lib
+
+
+$(BASENAME).bix: $(BASENAME).ihx
+	objcopy -I ihex -O binary $< $@
+$(BASENAME).iic: $(BASENAME).ihx
+	$(FX2LIBDIR)/utils/ihx2iic.py -v $(VID) -p $(PID) $< $@
+
+load: $(BASENAME).bix
+	fx2load -v $(VID) -p $(PID) $(BASENAME).bix
+	
+clean:
+	rm -f *.{asm,ihx,lnk,lst,map,mem,rel,rst,sym,adb,cdb,bix}

examples/i2c/Makefile

-INCLUDES = -I../../include
-LIBS = fx2.lib -L ../../lib/
-CC = sdcc -mmcs51
+FX2LIBDIR=../..
 BASENAME = i2c
+SOURCES=i2c.c
 
-$(BASENAME).ihx: $(BASENAME).c
-	$(CC) $(INCLUDES) $(BASENAME).c $(LIBS)
-
-$(BASENAME).bix: $(BASENAME).ihx
-	objcopy -I ihex -O binary $(BASENAME).ihx $(BASENAME).bix
-
-clean:
-	rm -f $(BASENAME).{asm,ihx,lnk,lst,map,mem,rel,rst,sym,adb,cdb,bix}
-
-.PHONY:run bix
-run: $(BASENAME).bix
-	python load.py
-
-bix: $(BASENAME).bix
-	
+include ../fx2.mk	
 
 

examples/lights/Makefile

-INCLUDES = -I../../include
-LIBS = fx2.lib -L ../../lib
-CC = sdcc -mmcs51 --debug
+FX2LIBDIR=../..
 BASENAME = lights
+SOURCES=lights.c
 
-$(BASENAME).ihx: $(BASENAME).c
-	$(CC) $(INCLUDES) $(BASENAME).c $(LIBS)
-
-$(BASENAME).bix: $(BASENAME).ihx
-	objcopy -I ihex -O binary $(BASENAME).ihx $(BASENAME).bix
-
-clean:
-	rm -f $(BASENAME).{asm,ihx,lnk,lst,map,mem,rel,rst,sym,adb,cdb,bix}
-
-.PHONY:bix
-bix: $(BASENAME).bix
+include ../fx2.mk
 

examples/reset/Makefile

-INCLUDES = -I../../include
-LIBS = fx2.lib -L../../lib
-CC = sdcc -mmcs51 --xram-loc 0x3000
+FX2LIBDIR=../..
 BASENAME = reset
+SOURCES=reset.c fx2_c0.c
 
-$(BASENAME).ihx: $(BASENAME).c fx2_c0.rel
-	$(CC) $(INCLUDES) $(BASENAME).c fx2_c0.rel $(LIBS)
+include ../fx2.mk
 
-fx2_c0.rel: fx2_c0.c
-	$(CC) -c fx2_c0.c
-
-clean:
-	rm -f *.{asm,ihx,lnk,lst,map,mem,rel,rst,sym,adb,cdb,bix}
-
-$(BASENAME).bix:
-	objcopy -I ihex -O binary $(BASENAME).ihx $(BASENAME).bix

examples/serial/Makefile

-INCLUDES = -I../../include
-LIBS = fx2.lib -L../../lib
-CC = sdcc -mmcs51 --xram-loc 0x3000 --xram-size 0x1000
+FX2LIBDIR=../..
 BASENAME = serial
-MEMSIZE = 4096
-
-$(BASENAME).ihx: $(BASENAME).c
-	$(CC) $(INCLUDES) $(BASENAME).c $(LIBS)
-
-clean:
-	rm -f $(BASENAME).{asm,ihx,lnk,lst,map,mem,rel,rst,sym,adb,cdb,bix}
-
-$(BASENAME).iic: $(BASENAME).ihx
-	../../utils/hex2bix -I -F 0xc2 -O serial.iic serial.ihx
-
-$(BASENAME).bix: $(BASENAME).ihx
-	objcopy -I ihex -O binary $(BASENAME).ihx $(BASENAME).bix
-
-bix: $(BASENAME).bix
+SOURCES=serial.c
 
+include ../fx2.mk