IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
Source at commit 2978afe92b395305a002c6615676e9cb992989eb created 13 years 17 days ago. By Werner Almesberger, atusb/fw/flash.c: simplified logic of flash_write and corrected several small bugs | |
---|---|
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 | |
13 | SHELL = /bin/bash |
14 | |
15 | NAME = atusb |
16 | |
17 | CFLAGS = -g -mmcu=$(CHIP) -DBOOT_ADDR=$(BOOT_ADDR) \ |
18 | -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \ |
19 | -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes |
20 | |
21 | CHIP=atmega32u2 |
22 | HOST=jlime |
23 | BOOT_ADDR=0x7000 |
24 | |
25 | AVR_PREFIX = $(BIN_PATH) avr- |
26 | CC = $(AVR_PREFIX)gcc |
27 | OBJCOPY = $(AVR_PREFIX)objcopy |
28 | #OBJDUMP = $(AVR_PREFIX)objdump |
29 | SIZE = $(AVR_PREFIX)size |
30 | |
31 | USB_OBJS = usb.o atu2.o |
32 | OBJS = atusb.o board.o spi.o descr.o ep0.o $(USB_OBJS) |
33 | BOOT_OBJS = boot.o board.o spi.o flash.o dfu.o $(USB_OBJS) |
34 | |
35 | vpath %.c usb/ |
36 | |
37 | CFLAGS += -Iinclude -Iusb |
38 | |
39 | # ----- Verbosity control ----------------------------------------------------- |
40 | |
41 | CC_normal := $(CC) |
42 | BUILD_normal := |
43 | DEPEND_normal := $(CPP) $(CFLAGS) -MM -MG |
44 | |
45 | CC_quiet = @echo " CC " $@ && $(CC_normal) |
46 | BUILD_quiet = @echo " BUILD " $@ && $(BUILD_normal) |
47 | DEPEND_quiet = @$(DEPEND_normal) |
48 | |
49 | ifeq ($(V),1) |
50 | CC = $(CC_normal) |
51 | BUILD = $(BUILD_normal) |
52 | DEPEND = $(DEPEND_normal) |
53 | else |
54 | CC = $(CC_quiet) |
55 | BUILD = $(BUILD_quiet) |
56 | DEPEND = $(DEPEND_quiet) |
57 | endif |
58 | |
59 | # ----- Rules ----------------------------------------------------------------- |
60 | |
61 | .PHONY: all clean upload prog version.c |
62 | |
63 | all: $(NAME).bin boot.hex |
64 | |
65 | $(NAME).elf: $(OBJS) |
66 | $(MAKE) version.o |
67 | $(CC) $(CFLAGS) -o $@ $(OBJS) version.o |
68 | |
69 | boot.elf: $(BOOT_OBJS) |
70 | $(CC) $(CFLAGS) -o $@ $(BOOT_OBJS) \ |
71 | -Wl,--section-start=.text=$(BOOT_ADDR) |
72 | |
73 | %.bin: %.elf |
74 | $(BUILD) $(OBJCOPY) -j .text -j .data -O binary $< $@ |
75 | @echo "build #`cat .version`, `ls -l $@`" |
76 | |
77 | %.hex: %.elf |
78 | $(BUILD) $(OBJCOPY) -j .text -j .data -O ihex $< $@ |
79 | $(SIZE) $@ |
80 | |
81 | # ----- Cleanup --------------------------------------------------------------- |
82 | |
83 | clean: |
84 | rm -f $(NAME).bin $(NAME).elf |
85 | rm -f $(OBJS) $(OBJS:.o=.d) |
86 | rm -f boot.hex boot.elf |
87 | rm -f $(BOOT_OBJS) $(BOOT_OBJS:.o=.d) |
88 | rm -f version.c version.d version.o |
89 | |
90 | # ----- Build version --------------------------------------------------------- |
91 | |
92 | version.c: |
93 | @if [ -f .version ]; then \ |
94 | v=`cat .version`; \ |
95 | expr $$v + 1 >.version; \ |
96 | else \ |
97 | echo 0 >.version; \ |
98 | fi |
99 | @[ -s .version ] || echo 0 >.version |
100 | @echo '/* MACHINE-GENERATED. DO NOT EDIT ! */' >version.c |
101 | @echo '#include "version.h"' >>version.c |
102 | @echo "const char *build_date = \"`date`\";" >>version.c |
103 | @echo "const uint16_t build_number = `cat .version`;" \ |
104 | >>version.c |
105 | |
106 | # ----- Dependencies ---------------------------------------------------------- |
107 | |
108 | %.o: %.c |
109 | $(CC) $(CFLAGS) -Os -c $< |
110 | $(DEPEND) $< | \ |
111 | sed -e \ |
112 | '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \ |
113 | -e '$${g;p;}' -e d >$*.d; \ |
114 | [ "$${PIPESTATUS[*]}" = "0 0" ] || { rm -f $*.d; exit 1; } |
115 | |
116 | -include $(OBJS:.o=.d) |
117 | |
118 | # ----- Programming and device control ---------------------------------------- |
119 | |
120 | upload: $(NAME).bin boot.hex |
121 | scp $(NAME).bin boot.hex $(HOST): |
122 | |
123 | # lfuse: external clock, slow start-up |
124 | # hfuse: 4 kB boot loader, reset into boot loader |
125 | # lock: allow everything but SPM to the boot loader |
126 | # Note: when trying to program 0xef, we get back 0x2f, failing |
127 | # verification. So we just program 0x2f. |
128 | |
129 | prog-app: |
130 | ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \ |
131 | -U flash:w:atusb.bin:r \ |
132 | -U lfuse:w:0x60:m |
133 | |
134 | prog: |
135 | ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \ |
136 | -U flash:w:boot.hex:i \ |
137 | -U lfuse:w:0x60:m \ |
138 | -U hfuse:w:0xd8:m \ |
139 | -U lock:w:0x2f:m |
140 | |
141 | prog-read: |
142 | ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb \ |
143 | -U flash:r:mcu.bin:r |
144 | |
145 | on: |
146 | ssh $(HOST) poke 0x10010318 4 |
147 | |
148 | off: |
149 | ssh $(HOST) poke 0x10010314 4 |
150 | |
151 | reset: |
152 | ssh $(HOST) poke 0x10010318 2048 |
153 | ssh $(HOST) poke 0x10010314 2048 |
154 |