fx2/firmware/lib/fx2.mk
2013-10-02 10:43:54 +02:00

95 lines
3.3 KiB
Makefile

# 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.
# DEPS: list of any depedancies (like auto-generated header files) that need
# generated prior to compiling. You must provide the target definition
# for any DEPS you define.
# BASENAME: name of your firmware file, i.e., myfirmware, but not myfirmware.c
#
# Leave these alone or redefine as necessary to customize firmware.
# (Redefine after including this makefile)
# VID vendor id
# PID product id
# LIBS optional additional libraries to link with the firmware.
# SDCC build/link options
# CODE_SIZE: Default --code-size 0x3c00
# XRAM_SIZE: Default --xram-size 0x0200
# XRAM_LOC: Default --xram-loc 0x3c00
# BUILDDIR: build directory (default build)
# These two can be changed to be blank if no device descriptor is being used.
# DSCR_AREA: Default -Wl"-b DSCR_AREA=0x3e00"
# INT2JT: Default -Wl"-b INT2JT=0x3f00"
#
# 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.
ASM = sdcc-sdas8051
CC = sdcc-sdcc
VID ?= 0x04b4
PID ?= 0x2342
DSCR_AREA ?= -Wl"-b DSCR_AREA=0x3e00"
INT2JT ?= -Wl"-b INT2JT=0x3f00"
CODE_SIZE ?= --code-size 0x3c00
XRAM_SIZE ?= --xram-size 0x0200
XRAM_LOC ?= --xram-loc 0x3c00
BUILDDIR ?= build
CFLAGS = -mmcs51 $(CODE_SIZE) $(XRAM_SIZE) $(XRAM_LOC) $(DSCR_AREA) $(INT2JT)
FX2LIBDIR?=$(dir $(lastword $(MAKEFILE_LIST)))../
RELS=$(addprefix $(BUILDDIR)/, $(addsuffix .rel, $(notdir $(basename $(SOURCES) $(A51_SOURCES)))))
.PHONY: all ihx iic bix load clean clean-all
all: ihx
ihx: $(BUILDDIR)/$(BASENAME).ihx
bix: $(BUILDDIR)/$(BASENAME).bix
iic: $(BUILDDIR)/$(BASENAME).iic
$(FX2LIBDIR)/lib/fx2.lib: $(FX2LIBDIR)/lib/*.c $(FX2LIBDIR)/lib/*.a51
$(MAKE) -C $(FX2LIBDIR)/lib
$(BUILDDIR):
mkdir -p $(BUILDDIR)
# can't use default target %.rel because there is no way
# to differentiate the dependency. (Is it %.rel: %.c or %.a51)
$(BUILDDIR)/$(BASENAME).ihx: $(BUILDDIR) $(SOURCES) $(A51_SOURCES) $(FX2LIBDIR)/lib/fx2.lib $(DEPS)
for a in $(A51_SOURCES); do \
cp $$a $(BUILDDIR)/; \
cd $(BUILDDIR) && $(ASM) -logs `basename $$a` && cd ..; \
done
for s in $(SOURCES); do \
THISREL=$$(basename `echo "$$s" | sed -e 's/\.c$$/\.rel/'`); \
$(CC) $(CFLAGS) -c -I $(FX2LIBDIR)/include $$s -o $(BUILDDIR)/$$THISREL ; \
done
$(CC) $(CFLAGS) -o $@ $(RELS) fx2.lib -L $(FX2LIBDIR)/lib $(LIBS)
$(BUILDDIR)/$(BASENAME).bix: $(BUILDDIR)/$(BASENAME).ihx
objcopy -I ihex -O binary $< $@
$(BUILDDIR)/$(BASENAME).iic: $(BUILDDIR)/$(BASENAME).ihx
$(FX2LIBDIR)/utils/ihx2iic.py -v $(VID) -p $(PID) $< $@
load: $(BUILDDIR)/$(BASENAME).bix
#fx2load -v $(VID) -p $(PID) $(BUILDDIR)/$(BASENAME).bix
fx2load -v 0x1443 -p 0x0007 $(BUILDDIR)/$(BASENAME).bix
#fxload -vvv -t fx2 -D /dev/bus/usb/002/003 -I $(BUILDDIR)/$(BASENAME).bix
#fxload -vvv -t fx2 -D /dev/bus/usb/002/003 -I build/firmware.ihx
clean:
rm -f $(BUILDDIR)/*.{asm,ihx,lnk,lst,map,mem,rel,rst,sym,adb,cdb,bix}
clean-all: clean
$(MAKE) -C $(FX2LIBDIR)/lib clean