| 1 | # MCU name\r |
| 2 | MCU = attiny85\r |
| 3 | F_CPU = 8000000\r |
| 4 | \r |
| 5 | # Output format. (can be srec, ihex, binary)\r |
| 6 | FORMAT = ihex \r |
| 7 | \r |
| 8 | # Target file name (without extension).\r |
| 9 | TARGET = tvbgone\r |
| 10 | \r |
| 11 | # Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.\r |
| 12 | # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)\r |
| 13 | OPT = s\r |
| 14 | \r |
| 15 | # List C source files here. (C dependencies are automatically generated.)\r |
| 16 | SRC = main.c NAcodes.c #util.c\r |
| 17 | \r |
| 18 | # List Assembler source files here.\r |
| 19 | # Make them always end in a capital .S. Files ending in a lowercase .s\r |
| 20 | # will not be considered source files but generated files (assembler\r |
| 21 | # output from the compiler), and will be deleted upon "make clean"!\r |
| 22 | # Even though the DOS/Win filesystem matches both .s and .S the same,\r |
| 23 | # it will preserve the spelling of the filenames, and gcc itself does\r |
| 24 | # care about how the name is spelled on its command-line.\r |
| 25 | # Optional compiler flags.\r |
| 26 | # -g: generate debugging information (for GDB, or for COFF conversion)\r |
| 27 | # -O*: optimization level\r |
| 28 | # -f...: tuning, see gcc manual and avr-libc documentation\r |
| 29 | # -Wall...: warning level\r |
| 30 | # -Wa,...: tell GCC to pass this to the assembler.\r |
| 31 | # -ahlms: create assembler listing\r |
| 32 | CFLAGS = -g -O$(OPT) \\r |
| 33 | -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \\r |
| 34 | -Wall -Wstrict-prototypes \\r |
| 35 | -DF_CPU=$(F_CPU) \\r |
| 36 | -Wa,-adhlns=$(<:.c=.lst) \\r |
| 37 | $(patsubst %,-I%,$(EXTRAINCDIRS))\r |
| 38 | \r |
| 39 | \r |
| 40 | # Set a "language standard" compiler flag.\r |
| 41 | # Unremark just one line below to set the language standard to use.\r |
| 42 | # gnu99 = C99 + GNU extensions. See GCC manual for more information.\r |
| 43 | #CFLAGS += -std=c89\r |
| 44 | #CFLAGS += -std=gnu89\r |
| 45 | #CFLAGS += -std=c99\r |
| 46 | CFLAGS += -std=gnu99\r |
| 47 | \r |
| 48 | \r |
| 49 | \r |
| 50 | # Optional assembler flags.\r |
| 51 | # -Wa,...: tell GCC to pass this to the assembler.\r |
| 52 | # -ahlms: create listing\r |
| 53 | # -gstabs: have the assembler create line number information; note that\r |
| 54 | # for use in COFF files, additional information about filenames\r |
| 55 | # and function names needs to be present in the assembler source\r |
| 56 | # files -- see avr-libc docs [FIXME: not yet described there]\r |
| 57 | ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs \r |
| 58 | \r |
| 59 | \r |
| 60 | \r |
| 61 | # Optional linker flags.\r |
| 62 | # -Wl,...: tell GCC to pass this to linker.\r |
| 63 | # -Map: create map file\r |
| 64 | # --cref: add cross reference to map file\r |
| 65 | LDFLAGS = -Wl,-Map=$(TARGET).map,--cref\r |
| 66 | \r |
| 67 | \r |
| 68 | \r |
| 69 | # Additional libraries\r |
| 70 | \r |
| 71 | # Minimalistic printf version\r |
| 72 | #LDFLAGS += -Wl,-u,vfprintf -lprintf_min\r |
| 73 | \r |
| 74 | # Floating point printf version (requires -lm below)\r |
| 75 | #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt\r |
| 76 | \r |
| 77 | # -lm = math library\r |
| 78 | LDFLAGS += -lm\r |
| 79 | \r |
| 80 | \r |
| 81 | \r |
| 82 | # Programming support using avrdude. Settings and variables.\r |
| 83 | \r |
| 84 | # Programming hardware: alf avr910 avrisp bascom bsd \r |
| 85 | # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500\r |
| 86 | #\r |
| 87 | # Type: avrdude -c ?\r |
| 88 | # to get a full listing.\r |
| 89 | #\r |
| 90 | #\r |
| 91 | \r |
| 92 | AVRDUDE_PROGRAMMER = usbtiny\r |
| 93 | AVRDUDE_PROGRAMMER = dt006\r |
| 94 | \r |
| 95 | #AVRDUDE_PORT = usb # programmer connected to serial device\r |
| 96 | AVRDUDE_PORT = lpt1\r |
| 97 | \r |
| 98 | AVRDUDE_WRITE_FLASH = -B 1 -U flash:w:$(TARGET).hex\r |
| 99 | #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep\r |
| 100 | \r |
| 101 | AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)\r |
| 102 | \r |
| 103 | # Uncomment the following if you want avrdude's erase cycle counter.\r |
| 104 | # Note that this counter needs to be initialized first using -Yn,\r |
| 105 | # see avrdude manual.\r |
| 106 | #AVRDUDE_ERASE += -y\r |
| 107 | \r |
| 108 | # Uncomment the following if you do /not/ wish a verification to be\r |
| 109 | # performed after programming the device.\r |
| 110 | #AVRDUDE_FLAGS += -V\r |
| 111 | \r |
| 112 | # Increase verbosity level. Please use this when submitting bug\r |
| 113 | # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> \r |
| 114 | # to submit bug reports.\r |
| 115 | #AVRDUDE_FLAGS += -v -v\r |
| 116 | \r |
| 117 | \r |
| 118 | \r |
| 119 | \r |
| 120 | # ---------------------------------------------------------------------------\r |
| 121 | \r |
| 122 | # Define directories, if needed.\r |
| 123 | DIRAVR = c:/winavr\r |
| 124 | DIRAVRBIN = $(DIRAVR)/bin\r |
| 125 | DIRAVRUTILS = $(DIRAVR)/utils/bin\r |
| 126 | DIRINC = .\r |
| 127 | DIRLIB = $(DIRAVR)/avr/lib\r |
| 128 | \r |
| 129 | \r |
| 130 | # Define programs and commands.\r |
| 131 | SHELL = sh\r |
| 132 | \r |
| 133 | CC = avr-gcc\r |
| 134 | \r |
| 135 | OBJCOPY = avr-objcopy\r |
| 136 | OBJDUMP = avr-objdump\r |
| 137 | SIZE = avr-size\r |
| 138 | \r |
| 139 | \r |
| 140 | # Programming support using avrdude.\r |
| 141 | AVRDUDE = avrdude\r |
| 142 | \r |
| 143 | \r |
| 144 | REMOVE = rm -f\r |
| 145 | COPY = cp\r |
| 146 | \r |
| 147 | HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex\r |
| 148 | ELFSIZE = $(SIZE) -A $(TARGET).elf\r |
| 149 | \r |
| 150 | \r |
| 151 | \r |
| 152 | # Define Messages\r |
| 153 | # English\r |
| 154 | MSG_ERRORS_NONE = Errors: none\r |
| 155 | MSG_BEGIN = -------- begin --------\r |
| 156 | MSG_END = -------- end --------\r |
| 157 | MSG_SIZE_BEFORE = Size before: \r |
| 158 | MSG_SIZE_AFTER = Size after:\r |
| 159 | MSG_COFF = Converting to AVR COFF:\r |
| 160 | MSG_EXTENDED_COFF = Converting to AVR Extended COFF:\r |
| 161 | MSG_FLASH = Creating load file for Flash:\r |
| 162 | MSG_EEPROM = Creating load file for EEPROM:\r |
| 163 | MSG_EXTENDED_LISTING = Creating Extended Listing:\r |
| 164 | MSG_SYMBOL_TABLE = Creating Symbol Table:\r |
| 165 | MSG_LINKING = Linking:\r |
| 166 | MSG_COMPILING = Compiling:\r |
| 167 | MSG_ASSEMBLING = Assembling:\r |
| 168 | MSG_CLEANING = Cleaning project:\r |
| 169 | \r |
| 170 | \r |
| 171 | \r |
| 172 | \r |
| 173 | # Define all object files.\r |
| 174 | OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) \r |
| 175 | \r |
| 176 | # Define all listing files.\r |
| 177 | LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)\r |
| 178 | \r |
| 179 | # Combine all necessary flags and optional flags.\r |
| 180 | # Add target processor to flags.\r |
| 181 | ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)\r |
| 182 | ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)\r |
| 183 | \r |
| 184 | \r |
| 185 | \r |
| 186 | # Default target.\r |
| 187 | all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \\r |
| 188 | $(TARGET).lss $(TARGET).sym sizeafter finished end\r |
| 189 | \r |
| 190 | \r |
| 191 | # Eye candy.\r |
| 192 | # AVR Studio 3.x does not check make's exit code but relies on\r |
| 193 | # the following magic strings to be generated by the compile job.\r |
| 194 | begin:\r |
| 195 | @echo\r |
| 196 | @echo $(MSG_BEGIN)\r |
| 197 | \r |
| 198 | finished:\r |
| 199 | @echo $(MSG_ERRORS_NONE)\r |
| 200 | \r |
| 201 | end:\r |
| 202 | @echo $(MSG_END)\r |
| 203 | @echo\r |
| 204 | \r |
| 205 | \r |
| 206 | # Display size of file.\r |
| 207 | sizebefore:\r |
| 208 | @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi\r |
| 209 | \r |
| 210 | sizeafter:\r |
| 211 | @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi\r |
| 212 | \r |
| 213 | \r |
| 214 | \r |
| 215 | # Display compiler version information.\r |
| 216 | gccversion : \r |
| 217 | @$(CC) --version\r |
| 218 | \r |
| 219 | \r |
| 220 | \r |
| 221 | \r |
| 222 | # Convert ELF to COFF for use in debugging / simulating in\r |
| 223 | # AVR Studio or VMLAB.\r |
| 224 | COFFCONVERT=$(OBJCOPY) --debugging \\r |
| 225 | --change-section-address .data-0x800000 \\r |
| 226 | --change-section-address .bss-0x800000 \\r |
| 227 | --change-section-address .noinit-0x800000 \\r |
| 228 | --change-section-address .eeprom-0x810000 \r |
| 229 | \r |
| 230 | \r |
| 231 | coff: $(TARGET).elf\r |
| 232 | @echo\r |
| 233 | @echo $(MSG_COFF) $(TARGET).cof\r |
| 234 | $(COFFCONVERT) -O coff-avr $< $(TARGET).cof\r |
| 235 | \r |
| 236 | \r |
| 237 | extcoff: $(TARGET).elf\r |
| 238 | @echo\r |
| 239 | @echo $(MSG_EXTENDED_COFF) $(TARGET).cof\r |
| 240 | $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof\r |
| 241 | \r |
| 242 | \r |
| 243 | \r |
| 244 | reset:\r |
| 245 | $(AVRDUDE) $(AVRDUDE_FLAGS)\r |
| 246 | \r |
| 247 | # Program the device. \r |
| 248 | program: $(TARGET).hex $(TARGET).eep\r |
| 249 | $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)\r |
| 250 | \r |
| 251 | full: $(TARGET).hex\r |
| 252 | make burn-fuse\r |
| 253 | make program\r |
| 254 | \r |
| 255 | burn-fuse:\r |
| 256 | $(AVRDUDE) $(AVRDUDE_FLAGS) -B 250 -u -U lfuse:w:0xfd:m -U hfuse:w:0xde:m\r |
| 257 | \r |
| 258 | read-fuse:\r |
| 259 | $(AVRDUDE) $(AVRDUDE_FLAGS) -u -U lfuse:r:l.txt:r\r |
| 260 | $(AVRDUDE) $(AVRDUDE_FLAGS) -u -U hfuse:r:h.txt:r\r |
| 261 | $(AVRDUDE) $(AVRDUDE_FLAGS) -u -U efuse:r:e.txt:r\r |
| 262 | # Create final output files (.hex, .eep) from ELF output file.\r |
| 263 | %.hex: %.elf\r |
| 264 | @echo\r |
| 265 | @echo $(MSG_FLASH) $@\r |
| 266 | $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@\r |
| 267 | \r |
| 268 | %.eep: %.elf\r |
| 269 | @echo\r |
| 270 | @echo $(MSG_EEPROM) $@\r |
| 271 | -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \\r |
| 272 | --change-section-lma .eeprom=0 -O $(FORMAT) $< $@\r |
| 273 | \r |
| 274 | # Create extended listing file from ELF output file.\r |
| 275 | %.lss: %.elf\r |
| 276 | @echo\r |
| 277 | @echo $(MSG_EXTENDED_LISTING) $@\r |
| 278 | $(OBJDUMP) -h -S $< > $@\r |
| 279 | \r |
| 280 | # Create a symbol table from ELF output file.\r |
| 281 | %.sym: %.elf\r |
| 282 | @echo\r |
| 283 | @echo $(MSG_SYMBOL_TABLE) $@\r |
| 284 | avr-nm -n $< > $@\r |
| 285 | \r |
| 286 | \r |
| 287 | \r |
| 288 | # Link: create ELF output file from object files.\r |
| 289 | .SECONDARY : $(TARGET).elf\r |
| 290 | .PRECIOUS : $(OBJ)\r |
| 291 | %.elf: $(OBJ)\r |
| 292 | @echo\r |
| 293 | @echo $(MSG_LINKING) $@\r |
| 294 | $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)\r |
| 295 | \r |
| 296 | \r |
| 297 | # Compile: create object files from C source files.\r |
| 298 | %.o : %.c\r |
| 299 | @echo\r |
| 300 | @echo $(MSG_COMPILING) $<\r |
| 301 | $(CC) -c $(ALL_CFLAGS) $< -o $@\r |
| 302 | \r |
| 303 | \r |
| 304 | # Compile: create assembler files from C source files.\r |
| 305 | %.s : %.c\r |
| 306 | $(CC) -S $(ALL_CFLAGS) $< -o $@\r |
| 307 | \r |
| 308 | \r |
| 309 | # Assemble: create object files from assembler source files.\r |
| 310 | %.o : %.S\r |
| 311 | @echo\r |
| 312 | @echo $(MSG_ASSEMBLING) $<\r |
| 313 | $(CC) -c $(ALL_ASFLAGS) $< -o $@\r |
| 314 | \r |
| 315 | \r |
| 316 | \r |
| 317 | \r |
| 318 | \r |
| 319 | \r |
| 320 | # Target: clean project.\r |
| 321 | clean: begin clean_list finished end\r |
| 322 | \r |
| 323 | clean_list :\r |
| 324 | @echo\r |
| 325 | @echo $(MSG_CLEANING)\r |
| 326 | $(REMOVE) $(TARGET).hex\r |
| 327 | $(REMOVE) $(TARGET).eep\r |
| 328 | $(REMOVE) $(TARGET).obj\r |
| 329 | $(REMOVE) $(TARGET).cof\r |
| 330 | $(REMOVE) $(TARGET).elf\r |
| 331 | $(REMOVE) $(TARGET).map\r |
| 332 | $(REMOVE) $(TARGET).obj\r |
| 333 | $(REMOVE) $(TARGET).a90\r |
| 334 | $(REMOVE) $(TARGET).sym\r |
| 335 | $(REMOVE) $(TARGET).lnk\r |
| 336 | $(REMOVE) $(TARGET).lss\r |
| 337 | $(REMOVE) $(OBJ)\r |
| 338 | $(REMOVE) $(LST)\r |
| 339 | $(REMOVE) $(SRC:.c=.s)\r |
| 340 | $(REMOVE) $(SRC:.c=.d)\r |
| 341 | \r |
| 342 | \r |
| 343 | # Automatically generate C source code dependencies. \r |
| 344 | # (Code originally taken from the GNU make user manual and modified \r |
| 345 | # (See README.txt Credits).)\r |
| 346 | #\r |
| 347 | # Note that this will work with sh (bash) and sed that is shipped with WinAVR\r |
| 348 | # (see the SHELL variable defined above).\r |
| 349 | # This may not work with other shells or other seds.\r |
| 350 | #\r |
| 351 | %.d: %.c\r |
| 352 | set -e; $(CC) -MM $(ALL_CFLAGS) $< \\r |
| 353 | | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \\r |
| 354 | [ -s $@ ] || rm -f $@\r |
| 355 | \r |
| 356 | \r |
| 357 | # Remove the '-' if you want to see the dependency files generated.\r |
| 358 | -include $(SRC:.c=.d)\r |
| 359 | \r |
| 360 | \r |
| 361 | \r |
| 362 | # Listing of phony targets.\r |
| 363 | .PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \\r |
| 364 | clean clean_list program\r |