TARGET = rx AVR = 1 EXTRAINCDIR = include CSTANDARD = gnu99 CPPSTANDARD = gnu++98 BUILDDIRBASE = build ifeq ($(AVR),1) MCU = attiny85 F_CPU = 16000000 BUILDDIR = $(BUILDDIRBASE)/avr else MCU = cortex-m3 BUILDDIR = $(BUILDDIRBASE)/arm endif RM = rm -rf MKDIR = mkdir -p ifeq ($(AVR),1) GCC = avr-gcc SIZE = avr-size OBJCOPY = avr-objcopy OBJDUMP = avr-objdump AVRDUDE = avrdude else GCC_BIN = ~/bin/mbed/gcc-arm-none-eabi/bin GCC = $(GCC_BIN)/arm-none-eabi-gcc GPP = $(GCC_BIN)/arm-none-eabi-g++ SIZE = $(GCC_BIN)/arm-none-eabi-size OBJCOPY = $(GCC_BIN)/arm-none-eabi-objcopy OBJDUMP = $(GCC_BIN)/arm-none-eabi-objdump endif SRC = src/main.c SRC += src/cc2500.c SRC += src/rx.c SRC += src/spi.c ifeq ($(AVR),1) SRC += src/avr/timer.c SRC += src/avr/cppm.c ifeq ($(DEBUG),1) SRC += src/avr/serial.c endif else CPPSRC += src/arm/cppm.cpp CPPSRC += src/arm/serial.cpp CPPSRC += src/arm/spi.cpp CPPSRC += src/arm/timer.cpp endif ifeq ($(AVR),1) CARGS = -I$(EXTRAINCDIR) CARGS += -Os CARGS += -std=$(CSTANDARD) CARGS += -Wall -Wextra -pedantic -Werror CARGS += -mmcu=$(MCU) CARGS += -funsigned-bitfields CARGS += -fpack-struct CARGS += -fshort-enums CARGS += -ffunction-sections CARGS += -Wshadow CARGS += -Wpointer-arith -Wcast-qual -Wstrict-prototypes CARGS += -Wno-main -Wno-write-strings -Wno-unused-parameter CARGS += -DF_CPU=$(F_CPU) LINKER = -Wl,--relax LINKER += -Wl,-Map -Wl,$(@:.elf=.map) else PRE_DEFS = -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -DARM_MATH_CM3 PRE_DEFS += -DTARGET_LIKE_CORTEX_M3 -DTARGET_CORTEX_M PRE_DEFS += -DMBED_BUILD_TIMESTAMP=1462534374.34 PRE_DEFS += -DTARGET_LIKE_MBED -DTARGET_LPC176X -DTARGET_NXP PRE_DEFS += -DTARGET_LPC1768 -D__CORTEX_M3 -DTARGET_M3 PRE_DEFS += -DTARGET_MBED_LPC1768 -D__MBED__=1 CARGS = -I$(EXTRAINCDIR) CARGS += -Ilib CARGS += -Os CARGS += -std=$(CSTANDARD) CARGS += -Wall -Wextra -pedantic -Werror CARGS += -Wno-main CARGS += -mcpu=$(MCU) CARGS += -mthumb CARGS += -fno-common -fmessage-length=0 CARGS += -fno-exceptions -ffunction-sections -fdata-sections CARGS += -fomit-frame-pointer CARGS += $(PRE_DEFS) CPPARGS = -I$(EXTRAINCDIR) CPPARGS += -Ilib/MODSERIAL CPPARGS += -Ilib/mbed CPPARGS += -Ilib/mbed/TARGET_LPC1768 CPPARGS += -Ilib/mbed/TARGET_LPC1768/TARGET_NXP CPPARGS += -Ilib/mbed/TARGET_LPC1768/TARGET_NXP/TARGET_LPC176X CPPARGS += -Ilib/mbed/TARGET_LPC1768/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768 CPPARGS += -Ilib/mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM CPPARGS += -Os CPPARGS += -std=$(CPPSTANDARD) CPPARGS += -Wall -Wextra -pedantic -Werror CPPARGS += -Wno-main CPPARGS += -mcpu=$(MCU) CPPARGS += -mthumb CPPARGS += -fno-common -fmessage-length=0 CPPARGS += -fno-exceptions -ffunction-sections -fdata-sections CPPARGS += -fomit-frame-pointer -fno-rtti CPPARGS += $(PRE_DEFS) LINKER = -mcpu=$(MCU) LINKER += -mthumb LINKER += -Wl,--gc-sections LINKER += --specs=nano.specs LINKER += -u _printf_float -u _scanf_float LINKER += -Wl,--wrap,main #LINKER += -Wl,--cref LINKER += -Tlib/mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/LPC1768.ld LINKER += -Llib/mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM LINKER += -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys LINKER += -lmbed CPPSRC += lib/MODSERIAL/FLUSH.cpp CPPSRC += lib/MODSERIAL/GETC.cpp CPPSRC += lib/MODSERIAL/INIT.cpp CPPSRC += lib/MODSERIAL/ISR_RX.cpp CPPSRC += lib/MODSERIAL/ISR_TX.cpp CPPSRC += lib/MODSERIAL/MODSERIAL_IRQ_INFO.cpp CPPSRC += lib/MODSERIAL/MODSERIAL.cpp CPPSRC += lib/MODSERIAL/PUTC.cpp CPPSRC += lib/MODSERIAL/RESIZE.cpp OBJ = lib/mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/board.o OBJ += lib/mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/cmsis_nvic.o OBJ += lib/mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/retarget.o OBJ += lib/mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/startup_LPC17xx.o OBJ += lib/mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/system_LPC17xx.o endif ifeq ($(DEBUG),1) CARGS += -DDEBUG endif ifeq ($(AVR),1) PROGRAMMER = arduino ISPPORT = /dev/tty.usbserial-A100OZQ1 ISPBAUD = 57600 else endif # ----------------------------------------------------------------------------- OBJ += $(addprefix $(BUILDDIR)/, $(SRC:.c=.o)) OBJ += $(addprefix $(BUILDDIR)/, $(CPPSRC:.cpp=.o)) .PHONY: all all: $(BUILDDIR)/$(TARGET).hex $(BUILDDIR)/$(TARGET).bin .PHONY: debugArduino debugArduino: $(MAKE) BUILDDIR=build/avr/debug TARGET=debug MCU=atmega328 DEBUG=1 all .PHONY: debugProgramArduino debugProgramArduino: $(MAKE) BUILDDIR=build/avr/debug TARGET=debug MCU=atmega328p DEBUG=1 program .PHONY: debugMbed debugMbed: $(MAKE) BUILDDIR=build/arm/debug TARGET=debug AVR=0 DEBUG=1 all .PHONY: debugProgramMbed debugProgramMbed: $(MAKE) BUILDDIR=build/arm/debug TARGET=debug AVR=0 DEBUG=1 copy .PHONY: program program: $(BUILDDIR)/$(TARGET).hex $(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -b $(ISPBAUD) -P $(ISPPORT) -e -D -U $(BUILDDIR)/$(TARGET).hex .PHONY: copy copy: $(BUILDDIR)/$(TARGET).bin cp $(BUILDDIR)/$(TARGET).bin /Volumes/MBED/$(TARGET).bin sync .PHONY: clean clean: $(RM) $(BUILDDIRBASE) -include $(OBJ:.o=.d) $(BUILDDIR)/%.o: %.c @$(MKDIR) $(BUILDDIR)/$(dir $<) $(GCC) $(CARGS) -c $< -o $@ @$(GCC) $(CARGS) -MM $*.c > $(BUILDDIR)/$*.d @mv -f $(BUILDDIR)/$*.d $(BUILDDIR)/$*.d.tmp @sed -e 's|.*:|$(BUILDDIR)/$*.o:|' < $(BUILDDIR)/$*.d.tmp > $(BUILDDIR)/$*.d @sed -e 's/.*://' < $(BUILDDIR)/$*.d.tmp | sed -e 's/\\$$//' | \ fmt -1 | sed -e 's/^ *//' | sed -e 's/$$/:/' >> $(BUILDDIR)/$*.d @rm -f $(BUILDDIR)/$*.d.tmp $(BUILDDIR)/%.o: %.cpp @$(MKDIR) $(BUILDDIR)/$(dir $<) $(GPP) $(CPPARGS) -c $< -o $@ @$(GPP) $(CPPARGS) -MM $*.cpp > $(BUILDDIR)/$*.d @mv -f $(BUILDDIR)/$*.d $(BUILDDIR)/$*.d.tmp @sed -e 's|.*:|$(BUILDDIR)/$*.o:|' < $(BUILDDIR)/$*.d.tmp > $(BUILDDIR)/$*.d @sed -e 's/.*://' < $(BUILDDIR)/$*.d.tmp | sed -e 's/\\$$//' | \ fmt -1 | sed -e 's/^ *//' | sed -e 's/$$/:/' >> $(BUILDDIR)/$*.d @rm -f $(BUILDDIR)/$*.d.tmp $(BUILDDIR)/$(TARGET).elf: $(OBJ) $(GCC) $(CARGS) $(OBJ) $(LINKER) --output $@ $(SIZE) $@ $(BUILDDIR)/$(TARGET).hex: $(BUILDDIR)/$(TARGET).elf $(OBJCOPY) -O ihex $< $@ $(OBJDUMP) -h -S $< > $(@:.hex=.lss) $(BUILDDIR)/$(TARGET).bin: $(BUILDDIR)/$(TARGET).elf $(OBJCOPY) -O binary $< $@