aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/appl/arduino/Makefile
blob: acec7c8d421b4dea976ac5740c57d440610eae3e (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# Simple makefile for building the 
# Arduino amforth vor various targets

# Examples of usage for Arduino leonardo:
#
# 1) Assemble the whole flash and eemprom files
#     make leonardo.hex
#
# 2) Backup the current flash & eeprom values 
#     make leonardo.bak
#
# 3) Erase the whole MCU Flash
#    make leonardo.era
#
# 4) Upload the new firmware using the hex file generated
#    make leonardo
#
# 5) Set the appropiate MCU fuses
#    make leonardo.fuse
#
# 6) Clear files (except backup)
#    make leonardo.clr


SHELL=/bin/bash

##############################
# TARGET DEPENDANT VARIABLES #
##############################

# 1) MCU should be identical to the device
#    Look at the .../avr8/devices/ folder
# 2) PART is the device model passed to avrdude.
# 3) LFUSE, HFUSE, EFUSE are the device-specific fuses
#    there is a useful fuse calc tool at:
#    http://www.engbedded.com/fusecalc/
# --------------------------------------
# Example fuse settings for 'leonardo'
# Low Fuse LFUSE=0xFF
#  - No Div8 prescaler, 
#  - No ouptput Clock, 
#  - Low Crystal mode: >=8 MHz + start-up time: 16K CK cycles + 65 ms
# High Fuse HFUSE=0xD9
# - Enable Serial Programming & Downloading
# - Bootsize 2048 words (4096 bytes)
# Extended Fuse EFUSE=0xF9
# - Brown-out detection @ 3.5V
# - no Hardware Boot Vector (=boot at $0000)
# --------------------------------------

leonardo:         PART=m32u4
leonardo.hex:     MCU=atmega32u4
leonardo.era:     PART=m32u4
leonardo.bak:     PART=m32u4
leonardo.fuse:    PART=m32u4
leonardo.fuse:    LFUSE=0xFF
leonardo.fuse:    HFUSE=0xD9
leonardo.fuse:    EFUSE=0xE9

uno:              PART=m328p
uno.hex:          MCU=atmega328p
uno.era:          PART=m328p
uno.bak:          PART=m328p
uno.fuse:         PART=m328p
uno.fuse:         LFUSE=0xFF
uno.fuse:         HFUSE=0xD9
uno.fuse:         EFUSE=0x05

mega128:        PART=m1280
mega128.hex:    MCU=atmega1280
mega128.era:    PART=m1280
mega128.bak:    PART=m1280
mega128.fuse:   PART=m1280
mega128.fuse:   LFUSE=0xFF
mega128.fuse:   HFUSE=0xD9
mega128.fuse:   EFUSE=0xF7

sanguino:         PART=m644p
sanguino.hex:     MCU=atmega644p
sanguino.era:     PART=m644p
sanguino.bak:     PART=m644p
sanguino.fuse:    PART=m644p
sanguino.fuse:    LFUSE=0xFF
sanguino.fuse:    HFUSE=0xF9
sanguino.fuse:    EFUSE=0xFD 

duemilanove:      PART=m328p
duemilanove.hex:  MCU=atmega328p
duemilanove.era:  PART=m328p
duemilanove.bak:  PART=m328p
duemilanove.fuse: PART=m328p
duemilanove.fuse: LFUSE=0xFF
duemilanove.fuse: HFUSE=0xD9
duemilanove.fuse: EFUSE=0x05

diecimila:        PART=m168
diecimila.hex:    MCU=atmega168
diecimila.era:    PART=m168
diecimila.bak:    PART=m168
diecimila.fuse:   PART=m168
diecimila.fuse:   LFUSE=0xFF
diecimila.fuse:   HFUSE=0xDD
diecimila.fuse:   EFUSE=0xF9

# AMFORTH VERSION TO USE
# 'code' for trunk and x.y for the releases (i.e 5.0)
#VERSION=5.0
VERSION=code
CORE=$(AMFORTH)/avr8

# directories
ATMEL=$(AMFORTH)/avr8/Atmel

# ------------------------
# PROGRAMMER CONFIGURATION
# ------------------------

PROGRAMMER=avrisp2
PORT=/dev/ttyUSB0

AVRDUDE=avrdude
AVRDUDE_FLAGS=-q -P $(PORT) -c $(PROGRAMMER)

# ----------------
# ASSEMBLER TO USE
# ----------------

AS_INCLUDE=-I $(ATMEL)/Appnotes2 -I$(CORE)  -I$(CORE)/devices/ -I$(AMFORTH)/common

ASM=wine $(ATMEL)/avrasm2.exe
# flags Specific to avrasm2.exe
AS_FLAGS=$(AS_INCLUDE) -fI -v0

#ASM=avra $(AS_FLAGS)

#--------------------------
# Generic assemble patterns
#--------------------------

# Assemble the target
%.hex : %.asm
	@echo "Producing Hexfiles for Arduino $*" 
	@$(ASM) $(AS_FLAGS) -I $(CORE)/devices/$(MCU) -e $*.eep.hex -m $*.map -l $*.lst $<

# Flash the target
% : %.hex
	@echo "Uploading Hexfiles to Arduino $*" 
	$(AVRDUDE) $(AVRDUDE_FLAGS) -p $(PART) -e -U flash:w:$*.hex:i -U eeprom:w:$*.eep.hex:i

# Set the fuse bits
%.fuse :
	@echo "Setting fuses to Arduino $*" 
	$(AVRDUDE) $(AVRDUDE_FLAGS) -p $(PART) -U efuse:w:$(EFUSE):m -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m

# Erase the whole MCU
%.era :
	@echo "Erasing entire Arduino $*" 
	$(AVRDUDE) $(AVRDUDE_FLAGS) -p $(PART) -e

# Clear assembled & auxilars files
%.clr:
	@echo "Cleaning all aux files" 
	@rm -f $*.hex ; rm -f $*.eep.hex ; rm -f $*.lst ; rm -f $*.map ; rm -f $*.cof ; rm -f $*.obj

# Backup arduino Flash & EEPROM files
%.bak:
	@echo "Backup Flash & EEPRON from Arduino $*" 
	$(AVRDUDE) $(AVRDUDE_FLAGS) -p $(PART) -U flash:r:$*.hex.bak:i -U eeprom:r:$*.eep.hex.bak:i

# ----------------------------------------------------------

GENERIC_DEPENDECIES=*.inc words/*.asm $(CORE)/*.asm $(CORE)/words/*.asm $(CORE)/drivers/*.asm

# Assemble all targets is the default action

TARGET = leonardo.hex uno.hex duemilanove.hex mega128.hex sanguino.hex diecimila.hex

%.asm: MCU=atmega328p

default: $(TARGET)

$(TARGET) :  $(GENERIC_DEPENDENCIES)  $(CORE)/devices/*/*.asm $(CORE)/devices/*/*.inc


# Cleans everything
clean:
	rm -f *.hex ; rm -f *.eep.hex ; rm -f *.lst ; rm -f *.map ; rm -f *.cof ; rm -f *.obj

# All other rules are target specific and must be typed one by one
# as shown in the top.