-
Notifications
You must be signed in to change notification settings - Fork 14
/
avr.mk
69 lines (54 loc) · 1.99 KB
/
avr.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#### AVR support. Currently you'll have to copy some of these flags
#### into the normal C values to get it to work.
# What micro is it?
AVR_MCU ?= atxmega128a1
AVR_MCU_SHORT ?= x128a1
# Some useful flags for microcontroller development
AVR_BOTHFLAGS ?= -fshort-enums -funsigned-char -funsigned-bitfields -DF_CPU=32000000UL -mmcu=$(AVR_MCU) -O0
AVR_CFLAGS ?= -std=gnu99
AVR_CXXFLAGS ?= -fno-exceptions -std=gnu++11
# New targets.
AVRPROJ ?= $(PROJ:%=%.elf)
AVR_EXT_LISTING ?= $(AVRPROJ:%.elf=%.lss)
AVR_HEX ?= $(AVRPROJ:%.elf=%.hex)
AVR_EEPROM ?= $(AVRPROJ:%.elf=%.eep)
# Compiler setup
AVR_PREFIX = avr
AVR_CC = $(AVR_PREFIX)-gcc
AVR_CXX = $(AVR_PREFIX)-g++
AVR_AR = $(AVR_PREFIX)-ar
.PHONY: avr-lss avr-hex avr-ihex avr-eeprom avr-eep avr-sizedummy avr-subs avr-all flash
$(AVR_EXT_LISTING): $(AVRPROJ)
@echo OBJDUMP $(notdir $<)
$(Q)avr-objdump -h -S $(AVRPROJ) > $(AVR_EXT_LISTING)
$(AVR_HEX): $(AVRPROJ)
@echo OBJCOPY $(notdir $<)
$(Q)avr-objcopy -R .eeprom -O ihex $(AVRPROJ) $(AVR_HEX)
$(AVR_EEPROM): $(AVRPROJ)
@echo OBJCOPY $(notdir $<)
$(Q)avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O ihex $(AVRPROJ) $(AVR_EEPROM)
avr-sizedummy: $(AVRPROJ)
@echo AVR-SIZE $(notdir $<)
$(Q)avr-size --format=avr --mcu=$(AVR_MCU) $(AVRPROJ)
avr-all: $(AVRPROJ) avr-subs
avr-subs: avr-lss avr-hex avr-eep avr-sizedummy
avr-lss: $(AVR_EXT_LISTING)
avr-hex: $(AVR_HEX)
avr-ihex: $(AVR_HEX)
avr-eeprom: $(AVR_EEPROM)
avr-eep: $(AVR_EEPROM)
# The default here is to use the AVRISP mkII. Be sure to change the
# settings for other programmers.
flash: $(AVR_HEX)
@echo FLASH $(notdir $<) \(AVRISP mkII\)
$(Q)avrdude -p$(AVR_MCU_SHORT) -cavrisp2 -Pusb -Uflash:w:$<:a
flash-eeprom: $(AVR_EEPROM)
@echo FLASH-EEPROM $(notdir $<) \(AVRISP mkII\)
$(Q)avrdude -p$(AVR_MCU_SHORT) -cavrisp2 -Pusb -Ueeprom:w:$<:a
LDOPTFLAGS ?= -Wl,--gc-sections -O0 -Wl,-Map=$(PROJ).map,--cref
USERFLAGS += $(AVR_BOTHFLAGS)
USERCFLAGS += $(AVR_CFLAGS)
USERCXXFLAGS += $(AVR_CXXFLAGS)
CC = $(AVR_CC)
CXX = $(AVR_CXX)
AR = $(AVR_AR)