Root/atusb/fw/Makefile

Source at commit 313fb7c190db6521786843b66982c5d69bb6b585 created 9 years 1 month ago.
By Werner Almesberger, atusb/fw/Makefile (CFLAGS): simplify -I../fw/include to -Iinclude
1#
2# Makefile - Makefile of the ATUSB firmware
3#
4# Written 2010-2011 by Werner Almesberger
5# Copyright 2010-2011 by Werner Almesberger
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12
13SHELL = /bin/bash
14
15NAME = atusb
16
17CFLAGS = -g -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \
18     -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes
19
20CHIP=atmega32u2
21
22AVR_PREFIX = $(BIN_PATH) avr-
23CC = $(AVR_PREFIX)gcc
24OBJCOPY = $(AVR_PREFIX)objcopy
25#OBJDUMP = $(AVR_PREFIX)objdump
26
27USB_OBJS = usb.o atu2.o
28OBJS = atusb.o board.o spi.o descr.o ep0.o $(USB_OBJS)
29
30vpath %.c usb/
31
32CFLAGS += -Iinclude -Iusb
33
34# ----- Verbosity control -----------------------------------------------------
35
36CC_normal := $(CC)
37BUILD_normal :=
38DEPEND_normal := $(CPP) $(CFLAGS) -MM -MG
39
40CC_quiet = @echo " CC " $@ && $(CC_normal)
41BUILD_quiet = @echo " BUILD " $@ && $(BUILD_normal)
42DEPEND_quiet = @$(DEPEND_normal)
43
44ifeq ($(V),1)
45    CC = $(CC_normal)
46    BUILD = $(BUILD_normal)
47    DEPEND = $(DEPEND_normal)
48else
49    CC = $(CC_quiet)
50    BUILD = $(BUILD_quiet)
51    DEPEND = $(DEPEND_quiet)
52endif
53
54# ----- Rules -----------------------------------------------------------------
55
56.PHONY: all clean upload prog version.c
57
58all: $(NAME).bin
59
60$(NAME).elf: $(OBJS)
61        $(MAKE) version.o
62        $(CC) $(CFLAGS) -mmcu=$(CHIP) -o $@ $(OBJS) version.o
63
64%.bin: %.elf
65        $(BUILD) $(OBJCOPY) -j .text -j .data -O binary $< $@
66        @echo "build #`cat .version`, `ls -l $@`"
67
68# ----- Cleanup ---------------------------------------------------------------
69
70clean:
71        rm -f $(NAME).bin $(NAME).elf $(OBJS) $(OBJS:.o=.d)
72        rm -f version.c version.d version.o
73
74# ----- Build version ---------------------------------------------------------
75
76version.c:
77        @if [ -f .version ]; then \
78            v=`cat .version`; \
79            expr $$v + 1 >.version; \
80        else \
81            echo 0 >.version; \
82        fi
83        @[ -s .version ] || echo 0 >.version
84        @echo '/* MACHINE-GENERATED. DO NOT EDIT ! */' >version.c
85        @echo '#include "version.h"' >>version.c
86        @echo "const char *build_date = \"`date`\";" >>version.c
87        @echo "const uint16_t build_number = `cat .version`;" \
88          >>version.c
89
90# ----- Dependencies ----------------------------------------------------------
91
92%.o: %.c
93        $(CC) $(CFLAGS) -mmcu=$(CHIP) -Os -c $<
94        $(DEPEND) $< | \
95          sed -e \
96            '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \
97            -e '$${g;p;}' -e d >$*.d; \
98          [ "$${PIPESTATUS[*]}" = "0 0" ] || { rm -f $*.d; exit 1; }
99
100-include $(OBJS:.o=.d)
101
102# ----- Programming and device control ----------------------------------------
103
104upload: $(NAME).bin
105        scp $(NAME).bin jlime:
106
107prog:
108        ssh jlime avrdude -F -p $(CHIP) -c nanonote_atusb -e \
109          -U flash:w:$(NAME).bin:r \
110          -U lfuse:w:0x60:m # external clock, slow start-up
111
112on:
113        ssh jlime poke 0x10010318 4
114
115off:
116        ssh jlime poke 0x10010314 4
117
118reset:
119        ssh jlime poke 0x10010318 2048
120        ssh jlime poke 0x10010314 2048
121

Archive Download this file



interactive