+#.PHONY: all info flash picocom clean
+#$(shell mkdir -p dist >/dev/null)
+#$(shell mkdir -p build >/dev/null)
+#$(shell mkdir -p sim >/dev/null)
+
+#NAME="bootloader-arduino_nano-644"
+#DEVICE="atmega644p"
+#SRC= $(wildcard src/*.c)
+#OBJ = $(SRC:src/%.c=build/%.o)
+#OBJ_SIM = $(SRC:src/%.c=sim/%.o)
+
+#CC= avr-gcc
+#CFLAGS_DEFINES= -DF_CPU=12000000 -DBAUD_RATE=115200 -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4'
+#LFLAGS_DEFINES= -DF_CPU=12000000
+#CFLAGS= -Wall -mmcu=$(DEVICE) -Os $(CFLAGS_DEFINES) -c
+#LFLAGS= -Wall -mmcu=$(DEVICE) -Os $(LFLAGS_DEFINES) -Wl,--section-start=.text=0xe000
+
+#CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -O1 $(CFLAGS_DEFINES) -g -c
+#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -O1 $(LFLAGS_DEFINES) -g -Wl,--section-start=.text=0xe000
+
.PHONY: all info flash picocom clean
$(shell mkdir -p dist >/dev/null)
$(shell mkdir -p build >/dev/null)
$(shell mkdir -p sim >/dev/null)
+$(shell mkdir -p sim/build >/dev/null)
NAME="bootloader-arduino_nano-644"
-DEVICE="atmega644p"
-SRC= $(wildcard src/*.c)
-OBJ = $(SRC:src/%.c=build/%.o)
-OBJ_SIM = $(SRC:src/%.c=sim/%.o)
-
-CC= avr-gcc
-CFLAGS_DEFINES= -DF_CPU=12000000 -DBAUD_RATE=115200 -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4'
-LFLAGS_DEFINES= -DF_CPU=12000000
-CFLAGS= -Wall -mmcu=$(DEVICE) -Os $(CFLAGS_DEFINES) -c
-LFLAGS= -Wall -mmcu=$(DEVICE) -Os $(LFLAGS_DEFINES) -Wl,--section-start=.text=0xe000
-
-CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -O1 $(CFLAGS_DEFINES) -g -c
-LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -O1 $(LFLAGS_DEFINES) -g -Wl,--section-start=.text=0xe000
+SRC= $(wildcard src/*.c src/*.cpp src/*/*.c src/*/*.cpp)
+HDR= $(wildcard src/*.h src/*.hpp src/*/*.h src/*/*.hpp)
+OBJ_CPP = $(SRC:src/%.cpp=build/%.o)
+OBJ = $(OBJ_CPP:src/%.c=build/%.o)
+OBJ_SIM_CPP = $(SRC:src/%.cpp=sim/build/%.o)
+OBJ_SIM = $(OBJ_SIM_CPP:src/%.c=sim/build/%.o)
+
+DEVICE=atmega644p
+
+CC= avr-g++
+CFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=12000000 -DBAUD_RATE=115200 -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c
+#LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=12000000 -Wl,-u,vfprintf -lprintf_flt -lm
+LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=12000000 -Wl,--section-start=.text=0xe000
+
+CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=12000000 -g -DBAUD_RATE=115200 -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c
+#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=12000000 -g -Wl,-u,vfprintf -lprintf_flt -lm
+LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=12000000 -g -Wl,--section-start=.text=0xe000
+
+
+all: dist/$(NAME).elf dist/$(NAME).s dist/$(NAME).hex sim/$(NAME).elf sim/$(NAME).s info
+
+dbg:
+ @echo --HDR---------------------------------
+ @echo $(HDR)
+ @echo --SRC---------------------------------
+ @echo $(SRC)
+ @echo --OBJ---------------------------------
+ @echo $(OBJ)
+ @echo --OBJ_CPP-----------------------------
+ @echo $(OBJ_CPP)
+ @echo --OBJ---------------------------------
+ @echo $(OBJ)
+ @echo ===================================
+ @echo
-
-all: dist/$(NAME).elf dist/$(NAME).s dist/$(NAME).hex sim/$(NAME).elf sim/$(NAME).s info
-
info:
- @echo
@avr-size --mcu=$(DEVICE) --format=avr dist/$(NAME).elf
-.depend: $(SRC)
- $(CC) -mmcu=$(DEVICE) -MM $(SRC) > .depend
+.depend: $(SRC) $(HDR)
+ $(CC) --mcu=$(DEVICE) -MM $(SRC) | sed --regexp-extended 's/^(.*\.o)\: src\/(.*)(\.cpp|\.c) (.*)/build\/\2\.o\: src\/\2\3 \4/g' > .depend
+
+-include .depend
--include $(DEPENDFILE)
+# .depend solte auch auf Header Files achten!
dist/$(NAME).elf: .depend $(OBJ)
$(CC) $(LFLAGS) -o $@ $(OBJ)
avr-objdump -d $< > $@
dist/%.hex: dist/%.elf
- avr-objcopy -j .text -j .data -O ihex $< $@
+ #avr-objcopy -j .text -j .data -O ihex $< $@
+ avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
sim/$(NAME).elf: .depend $(OBJ_SIM)
$(CC) $(LFLAGS_SIM) -o $@ $(OBJ_SIM)
+
build/%.o: src/%.c
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) -o $@ $<
+
+build/%.o: src/%.cpp
+ @mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $<
-sim/%.o: src/%.c
+sim/build/%.o: src/%.c
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS_SIM) -o $@ $<
+
+sim/build/%.o: src/%.cpp
+ @mkdir -p $(dir $@)
$(CC) $(CFLAGS_SIM) -o $@ $<
sim/%.s: sim/%.elf
gdb: sim/$(NAME).elf
avr-gdb $<
-picocom:
- # picocom sends CR for ENTER -> convert cr (\r) to lf (\n)
- picocom -b 115200 --omap crlf /dev/ttyUSB0
+isp-644p:
+ avrdude -c usbasp -p m644p
-flash: dist/$(NAME).elf all
- avrdude -c arduino -P /dev/ttyUSB0 -p m644p -e -U flash:w:$<
+isp-flash-644p: dist/$(NAME).elf all
+ avrdude -c usbasp -p m644p -e -U flash:w:$<
-isp:
- avrdude -c usbasp -p m644p -U lock:r:-:h
+flash-644p: dist/$(NAME).elf all
+ avrdude -c arduino -p m644p -P /dev/ttyUSB0 -b 115200 -e -U flash:w:$<
-isp-flash: dist/$(NAME).elf all
- avrdude -c usbasp -p m644p -e -U flash:w:$<
-isp-read:
- avrdude -c usbasp -p m644p -U flash:r:/tmp/flash.bin
+picocom:
+ # picocom sends CR for ENTER -> convert cr (\r) to lf (\n)
+ picocom -b 115200 --omap crlf /dev/ttyUSB0
-isp-erase:
+isp-erase-644p:
avrdude -c usbasp -p m644p -e
-
-isp-fuse:
+
+isp-fuse-644p:
#avrdude -c usbasp -p m644p -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xFF:m -U lock:w:0xFF:m
- avrdude -c usbasp -p m644p -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xFE:m -U lock:w:0xEF:m
+ #avrdude -c usbasp -p m644p -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xFE:m -U lock:w:0xEF:m
+ # LFUSE=0xEE -> startuptime 1K CLOCKS + 0ms -> 83us
+ #avrdude -c usbasp -p m644p -U lfuse:w:0xEE:m -U hfuse:w:0xD8:m -U efuse:w:0xFE:m -U lock:w:0xEF:m
+ # LFUSE=0xE7 -> startuptime 16K CLOCKS + 4.1ms -> 5.4ms
+ avrdude -c usbasp -p m644p -U lfuse:w:0xE7:m -U hfuse:w:0xD8:m -U efuse:w:0xFE:m -U lock:w:0xEF:m
clean:
@rm -r dist