diff options
Diffstat (limited to 'platforms/avr/platform.mk')
| -rw-r--r-- | platforms/avr/platform.mk | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/platforms/avr/platform.mk b/platforms/avr/platform.mk new file mode 100644 index 000000000..b45108736 --- /dev/null +++ b/platforms/avr/platform.mk | |||
| @@ -0,0 +1,179 @@ | |||
| 1 | # Hey Emacs, this is a -*- makefile -*- | ||
| 2 | ############################################################################## | ||
| 3 | # Compiler settings | ||
| 4 | # | ||
| 5 | CC = $(CC_PREFIX) avr-gcc | ||
| 6 | OBJCOPY = avr-objcopy | ||
| 7 | OBJDUMP = avr-objdump | ||
| 8 | SIZE = avr-size | ||
| 9 | AR = avr-ar | ||
| 10 | NM = avr-nm | ||
| 11 | HEX = $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature | ||
| 12 | EEP = $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) | ||
| 13 | BIN = | ||
| 14 | |||
| 15 | COMPILEFLAGS += -funsigned-char | ||
| 16 | COMPILEFLAGS += -funsigned-bitfields | ||
| 17 | COMPILEFLAGS += -ffunction-sections | ||
| 18 | COMPILEFLAGS += -fdata-sections | ||
| 19 | COMPILEFLAGS += -fpack-struct | ||
| 20 | COMPILEFLAGS += -fshort-enums | ||
| 21 | |||
| 22 | ASFLAGS += $(AVR_ASFLAGS) | ||
| 23 | |||
| 24 | CFLAGS += $(COMPILEFLAGS) $(AVR_CFLAGS) | ||
| 25 | CFLAGS += -fno-inline-small-functions | ||
| 26 | CFLAGS += -fno-strict-aliasing | ||
| 27 | |||
| 28 | CXXFLAGS += $(COMPILEFLAGS) | ||
| 29 | CXXFLAGS += -fno-exceptions -std=c++11 | ||
| 30 | |||
| 31 | LDFLAGS +=-Wl,--gc-sections | ||
| 32 | |||
| 33 | OPT_DEFS += -DF_CPU=$(F_CPU)UL | ||
| 34 | |||
| 35 | MCUFLAGS = -mmcu=$(MCU) | ||
| 36 | |||
| 37 | # List any extra directories to look for libraries here. | ||
| 38 | # Each directory must be seperated by a space. | ||
| 39 | # Use forward slashes for directory separators. | ||
| 40 | # For a directory that has spaces, enclose it in quotes. | ||
| 41 | EXTRALIBDIRS = | ||
| 42 | |||
| 43 | |||
| 44 | #---------------- External Memory Options ---------------- | ||
| 45 | |||
| 46 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), | ||
| 47 | # used for variables (.data/.bss) and heap (malloc()). | ||
| 48 | #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff | ||
| 49 | |||
| 50 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), | ||
| 51 | # only used for heap (malloc()). | ||
| 52 | #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff | ||
| 53 | |||
| 54 | EXTMEMOPTS = | ||
| 55 | |||
| 56 | #---------------- Debugging Options ---------------- | ||
| 57 | |||
| 58 | # Debugging format. | ||
| 59 | # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. | ||
| 60 | # AVR Studio 4.10 requires dwarf-2. | ||
| 61 | # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. | ||
| 62 | DEBUG = dwarf-2 | ||
| 63 | |||
| 64 | # For simulavr only - target MCU frequency. | ||
| 65 | DEBUG_MFREQ = $(F_CPU) | ||
| 66 | |||
| 67 | # Set the DEBUG_UI to either gdb or insight. | ||
| 68 | # DEBUG_UI = gdb | ||
| 69 | DEBUG_UI = insight | ||
| 70 | |||
| 71 | # Set the debugging back-end to either avarice, simulavr. | ||
| 72 | DEBUG_BACKEND = avarice | ||
| 73 | #DEBUG_BACKEND = simulavr | ||
| 74 | |||
| 75 | # GDB Init Filename. | ||
| 76 | GDBINIT_FILE = __avr_gdbinit | ||
| 77 | |||
| 78 | # When using avarice settings for the JTAG | ||
| 79 | JTAG_DEV = /dev/com1 | ||
| 80 | |||
| 81 | # Debugging port used to communicate between GDB / avarice / simulavr. | ||
| 82 | DEBUG_PORT = 4242 | ||
| 83 | |||
| 84 | # Debugging host used to communicate between GDB / avarice / simulavr, normally | ||
| 85 | # just set to localhost unless doing some sort of crazy debugging when | ||
| 86 | # avarice is running on a different computer. | ||
| 87 | DEBUG_HOST = localhost | ||
| 88 | |||
| 89 | #============================================================================ | ||
| 90 | |||
| 91 | # Convert hex to bin. | ||
| 92 | bin: $(BUILD_DIR)/$(TARGET).hex | ||
| 93 | ifeq ($(BOOTLOADER),lufa-ms) | ||
| 94 | $(eval BIN_PADDING=$(shell n=`expr 32768 - $(BOOTLOADER_SIZE)` && echo $$(($$n)) || echo 0)) | ||
| 95 | $(OBJCOPY) -Iihex -Obinary $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin --pad-to $(BIN_PADDING) | ||
| 96 | else | ||
| 97 | $(OBJCOPY) -Iihex -Obinary $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin | ||
| 98 | endif | ||
| 99 | $(COPY) $(BUILD_DIR)/$(TARGET).bin $(TARGET).bin; | ||
| 100 | |||
| 101 | # copy bin to FLASH.bin | ||
| 102 | flashbin: bin | ||
| 103 | $(COPY) $(BUILD_DIR)/$(TARGET).bin FLASH.bin; | ||
| 104 | |||
| 105 | # Generate avr-gdb config/init file which does the following: | ||
| 106 | # define the reset signal, load the target file, connect to target, and set | ||
| 107 | # a breakpoint at main(). | ||
| 108 | gdb-config: | ||
| 109 | @$(REMOVE) $(GDBINIT_FILE) | ||
| 110 | @echo define reset >> $(GDBINIT_FILE) | ||
| 111 | @echo SIGNAL SIGHUP >> $(GDBINIT_FILE) | ||
| 112 | @echo end >> $(GDBINIT_FILE) | ||
| 113 | @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE) | ||
| 114 | @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE) | ||
| 115 | ifeq ($(DEBUG_BACKEND),simulavr) | ||
| 116 | @echo load >> $(GDBINIT_FILE) | ||
| 117 | endif | ||
| 118 | @echo break main >> $(GDBINIT_FILE) | ||
| 119 | |||
| 120 | debug: gdb-config $(BUILD_DIR)/$(TARGET).elf | ||
| 121 | ifeq ($(DEBUG_BACKEND), avarice) | ||
| 122 | @echo Starting AVaRICE - Press enter when "waiting to connect" message displays. | ||
| 123 | @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \ | ||
| 124 | $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT) | ||
| 125 | @$(WINSHELL) /c pause | ||
| 126 | |||
| 127 | else | ||
| 128 | @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \ | ||
| 129 | $(DEBUG_MFREQ) --port $(DEBUG_PORT) | ||
| 130 | endif | ||
| 131 | @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE) | ||
| 132 | |||
| 133 | |||
| 134 | |||
| 135 | |||
| 136 | # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. | ||
| 137 | COFFCONVERT = $(OBJCOPY) --debugging | ||
| 138 | COFFCONVERT += --change-section-address .data-0x800000 | ||
| 139 | COFFCONVERT += --change-section-address .bss-0x800000 | ||
| 140 | COFFCONVERT += --change-section-address .noinit-0x800000 | ||
| 141 | COFFCONVERT += --change-section-address .eeprom-0x810000 | ||
| 142 | |||
| 143 | |||
| 144 | |||
| 145 | coff: $(BUILD_DIR)/$(TARGET).elf | ||
| 146 | @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof | ||
| 147 | $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof | ||
| 148 | |||
| 149 | |||
| 150 | extcoff: $(BUILD_DIR)/$(TARGET).elf | ||
| 151 | @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof | ||
| 152 | $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof | ||
| 153 | |||
| 154 | ifeq ($(strip $(BOOTLOADER)), qmk-dfu) | ||
| 155 | QMK_BOOTLOADER_TYPE = DFU | ||
| 156 | else ifeq ($(strip $(BOOTLOADER)), qmk-hid) | ||
| 157 | QMK_BOOTLOADER_TYPE = HID | ||
| 158 | endif | ||
| 159 | |||
| 160 | bootloader: | ||
| 161 | ifeq ($(strip $(QMK_BOOTLOADER_TYPE)),) | ||
| 162 | $(error Please set BOOTLOADER to "qmk-dfu" or "qmk-hid" first!) | ||
| 163 | else | ||
| 164 | make -C lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/ clean | ||
| 165 | $(QMK_BIN) generate-dfu-header --quiet --keyboard $(KEYBOARD) --output lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/Keyboard.h | ||
| 166 | $(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) -D__ASSEMBLER__ $(CFLAGS) $(OPT_DEFS) platforms/avr/bootloader_size.c 2> /dev/null | sed -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0)) | ||
| 167 | $(eval PROGRAM_SIZE_KB=$(shell n=`expr $(MAX_SIZE) / 1024` && echo $$(($$n)) || echo 0)) | ||
| 168 | $(eval BOOT_SECTION_SIZE_KB=$(shell n=`expr $(BOOTLOADER_SIZE) / 1024` && echo $$(($$n)) || echo 0)) | ||
| 169 | $(eval FLASH_SIZE_KB=$(shell n=`expr $(PROGRAM_SIZE_KB) + $(BOOT_SECTION_SIZE_KB)` && echo $$(($$n)) || echo 0)) | ||
| 170 | make -C lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/ MCU=$(MCU) ARCH=$(ARCH) F_CPU=$(F_CPU) FLASH_SIZE_KB=$(FLASH_SIZE_KB) BOOT_SECTION_SIZE_KB=$(BOOT_SECTION_SIZE_KB) | ||
| 171 | printf "Bootloader$(QMK_BOOTLOADER_TYPE).hex copied to $(TARGET)_bootloader.hex\n" | ||
| 172 | cp lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/Bootloader$(QMK_BOOTLOADER_TYPE).hex $(TARGET)_bootloader.hex | ||
| 173 | endif | ||
| 174 | |||
| 175 | production: $(BUILD_DIR)/$(TARGET).hex bootloader cpfirmware | ||
| 176 | @cat $(BUILD_DIR)/$(TARGET).hex | awk '/^:00000001FF/ == 0' > $(TARGET)_production.hex | ||
| 177 | @cat $(TARGET)_bootloader.hex >> $(TARGET)_production.hex | ||
| 178 | echo "File sizes:" | ||
| 179 | $(SIZE) $(TARGET).hex $(TARGET)_bootloader.hex $(TARGET)_production.hex | ||
