diff options
Diffstat (limited to 'tmk_core/avr.mk')
| -rw-r--r-- | tmk_core/avr.mk | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/tmk_core/avr.mk b/tmk_core/avr.mk new file mode 100644 index 000000000..72be5e6da --- /dev/null +++ b/tmk_core/avr.mk | |||
| @@ -0,0 +1,185 @@ | |||
| 1 | # Hey Emacs, this is a -*- makefile -*- | ||
| 2 | ############################################################################## | ||
| 3 | # Compiler settings | ||
| 4 | # | ||
| 5 | CC = avr-gcc | ||
| 6 | OBJCOPY = avr-objcopy | ||
| 7 | OBJDUMP = avr-objdump | ||
| 8 | SIZE = avr-size | ||
| 9 | AR = avr-ar rcs | ||
| 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 | |||
| 14 | |||
| 15 | |||
| 16 | COMPILEFLAGS += -funsigned-char | ||
| 17 | COMPILEFLAGS += -funsigned-bitfields | ||
| 18 | COMPILEFLAGS += -ffunction-sections | ||
| 19 | COMPILEFLAGS += -fdata-sections | ||
| 20 | COMPILEFLAGS += -fpack-struct | ||
| 21 | COMPILEFLAGS += -fshort-enums | ||
| 22 | |||
| 23 | CFLAGS += $(COMPILEFLAGS) | ||
| 24 | CFLAGS += -fno-inline-small-functions | ||
| 25 | CFLAGS += -fno-strict-aliasing | ||
| 26 | |||
| 27 | CPPFLAGS += $(COMPILEFLAGS) | ||
| 28 | CPPFLAGS += -fno-exceptions | ||
| 29 | |||
| 30 | LDFLAGS +=-Wl,--gc-sections | ||
| 31 | |||
| 32 | OPT_DEFS += -DF_CPU=$(F_CPU)UL | ||
| 33 | |||
| 34 | MCUFLAGS = -mmcu=$(MCU) | ||
| 35 | |||
| 36 | # List any extra directories to look for libraries here. | ||
| 37 | # Each directory must be seperated by a space. | ||
| 38 | # Use forward slashes for directory separators. | ||
| 39 | # For a directory that has spaces, enclose it in quotes. | ||
| 40 | EXTRALIBDIRS = | ||
| 41 | |||
| 42 | |||
| 43 | #---------------- External Memory Options ---------------- | ||
| 44 | |||
| 45 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), | ||
| 46 | # used for variables (.data/.bss) and heap (malloc()). | ||
| 47 | #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff | ||
| 48 | |||
| 49 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), | ||
| 50 | # only used for heap (malloc()). | ||
| 51 | #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff | ||
| 52 | |||
| 53 | EXTMEMOPTS = | ||
| 54 | |||
| 55 | #---------------- Debugging Options ---------------- | ||
| 56 | |||
| 57 | # Debugging format. | ||
| 58 | # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. | ||
| 59 | # AVR Studio 4.10 requires dwarf-2. | ||
| 60 | # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. | ||
| 61 | DEBUG = dwarf-2 | ||
| 62 | |||
| 63 | # For simulavr only - target MCU frequency. | ||
| 64 | DEBUG_MFREQ = $(F_CPU) | ||
| 65 | |||
| 66 | # Set the DEBUG_UI to either gdb or insight. | ||
| 67 | # DEBUG_UI = gdb | ||
| 68 | DEBUG_UI = insight | ||
| 69 | |||
| 70 | # Set the debugging back-end to either avarice, simulavr. | ||
| 71 | DEBUG_BACKEND = avarice | ||
| 72 | #DEBUG_BACKEND = simulavr | ||
| 73 | |||
| 74 | # GDB Init Filename. | ||
| 75 | GDBINIT_FILE = __avr_gdbinit | ||
| 76 | |||
| 77 | # When using avarice settings for the JTAG | ||
| 78 | JTAG_DEV = /dev/com1 | ||
| 79 | |||
| 80 | # Debugging port used to communicate between GDB / avarice / simulavr. | ||
| 81 | DEBUG_PORT = 4242 | ||
| 82 | |||
| 83 | # Debugging host used to communicate between GDB / avarice / simulavr, normally | ||
| 84 | # just set to localhost unless doing some sort of crazy debugging when | ||
| 85 | # avarice is running on a different computer. | ||
| 86 | DEBUG_HOST = localhost | ||
| 87 | |||
| 88 | #============================================================================ | ||
| 89 | # Autodecct teensy loader | ||
| 90 | ifneq (, $(shell which teensy-loader-cli 2>/dev/null)) | ||
| 91 | TEENSY_LOADER_CLI = teensy-loader-cli | ||
| 92 | else | ||
| 93 | TEENSY_LOADER_CLI = teensy_loader_cli | ||
| 94 | endif | ||
| 95 | |||
| 96 | # Program the device. | ||
| 97 | program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep | ||
| 98 | $(PROGRAM_CMD) | ||
| 99 | |||
| 100 | teensy: $(BUILD_DIR)/$(TARGET).hex | ||
| 101 | $(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex | ||
| 102 | |||
| 103 | flip: $(BUILD_DIR)/$(TARGET).hex | ||
| 104 | batchisp -hardware usb -device $(MCU) -operation erase f | ||
| 105 | batchisp -hardware usb -device $(MCU) -operation loadbuffer $(BUILD_DIR)/$(TARGET).hex program | ||
| 106 | batchisp -hardware usb -device $(MCU) -operation start reset 0 | ||
| 107 | |||
| 108 | dfu: $(BUILD_DIR)/$(TARGET).hex sizeafter | ||
| 109 | ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1))) | ||
| 110 | dfu-programmer $(MCU) erase --force | ||
| 111 | else | ||
| 112 | dfu-programmer $(MCU) erase | ||
| 113 | endif | ||
| 114 | dfu-programmer $(MCU) flash $(BUILD_DIR)/$(TARGET).hex | ||
| 115 | dfu-programmer $(MCU) reset | ||
| 116 | |||
| 117 | dfu-start: | ||
| 118 | dfu-programmer $(MCU) reset | ||
| 119 | dfu-programmer $(MCU) start | ||
| 120 | |||
| 121 | flip-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep | ||
| 122 | $(COPY) $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET)eep.hex | ||
| 123 | batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase | ||
| 124 | batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(BUILD_DIR)/$(TARGET)eep.hex program | ||
| 125 | batchisp -hardware usb -device $(MCU) -operation start reset 0 | ||
| 126 | $(REMOVE) $(BUILD_DIR)/$(TARGET)eep.hex | ||
| 127 | |||
| 128 | dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep | ||
| 129 | ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1))) | ||
| 130 | dfu-programmer $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep | ||
| 131 | else | ||
| 132 | dfu-programmer $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep | ||
| 133 | endif | ||
| 134 | dfu-programmer $(MCU) reset | ||
| 135 | |||
| 136 | |||
| 137 | # Generate avr-gdb config/init file which does the following: | ||
| 138 | # define the reset signal, load the target file, connect to target, and set | ||
| 139 | # a breakpoint at main(). | ||
| 140 | gdb-config: | ||
| 141 | @$(REMOVE) $(GDBINIT_FILE) | ||
| 142 | @echo define reset >> $(GDBINIT_FILE) | ||
| 143 | @echo SIGNAL SIGHUP >> $(GDBINIT_FILE) | ||
| 144 | @echo end >> $(GDBINIT_FILE) | ||
| 145 | @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE) | ||
| 146 | @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE) | ||
| 147 | ifeq ($(DEBUG_BACKEND),simulavr) | ||
| 148 | @echo load >> $(GDBINIT_FILE) | ||
| 149 | endif | ||
| 150 | @echo break main >> $(GDBINIT_FILE) | ||
| 151 | |||
| 152 | debug: gdb-config $(BUILD_DIR)/$(TARGET).elf | ||
| 153 | ifeq ($(DEBUG_BACKEND), avarice) | ||
| 154 | @echo Starting AVaRICE - Press enter when "waiting to connect" message displays. | ||
| 155 | @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \ | ||
| 156 | $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT) | ||
| 157 | @$(WINSHELL) /c pause | ||
| 158 | |||
| 159 | else | ||
| 160 | @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \ | ||
| 161 | $(DEBUG_MFREQ) --port $(DEBUG_PORT) | ||
| 162 | endif | ||
| 163 | @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE) | ||
| 164 | |||
| 165 | |||
| 166 | |||
| 167 | |||
| 168 | # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. | ||
| 169 | COFFCONVERT = $(OBJCOPY) --debugging | ||
| 170 | COFFCONVERT += --change-section-address .data-0x800000 | ||
| 171 | COFFCONVERT += --change-section-address .bss-0x800000 | ||
| 172 | COFFCONVERT += --change-section-address .noinit-0x800000 | ||
| 173 | COFFCONVERT += --change-section-address .eeprom-0x810000 | ||
| 174 | |||
| 175 | |||
| 176 | |||
| 177 | coff: $(BUILD_DIR)/$(TARGET).elf | ||
| 178 | @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof | ||
| 179 | $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof | ||
| 180 | |||
| 181 | |||
| 182 | extcoff: $(BUILD_DIR)/$(TARGET).elf | ||
| 183 | @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof | ||
| 184 | $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof | ||
| 185 | |||
