Moved completely over to jam. bye bye make\!

This commit is contained in:
maniacbug 2011-06-27 21:22:39 -07:00
parent ce881ba0dc
commit e7c30f265f
18 changed files with 1036 additions and 1812 deletions

View File

@ -62,21 +62,8 @@ PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ;
OUT = $(OUT_DIR)/$(PROJECT_NAME) ; OUT = $(OUT_DIR)/$(PROJECT_NAME) ;
# AvrDude setup # AvrDude setup
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ;
#This is not working :(
#HDRSCAN on $(OUT).pde = "^#[ \\t]*include[ \\t]*[<\\"](.*)[\\">].*$" ;
#HDRRULE on $(OUT).pde = HDER ;
#rule HDER
#{
# Echo $(<) INCLUDES $(>:B) ;
#
# _LIB = [ GLOB $(ARDUINO_LIB)/$(>:B) $(SKETCH_LIB)/$(>:B) : *.cpp ] ;
# Includes $(<) : $(OUT_DIR)/$(_LIB:B).o ;
# Echo [ GLOB $(ARDUINO_LIB)/$(>:B) $(SKETCH_LIB)/$(>:B) : *.cpp ] ;
#}
rule GitVersion rule GitVersion
{ {
Always $(<) ; Always $(<) ;
@ -128,9 +115,6 @@ rule Pde
Depends $(<) : $(<:D) ; Depends $(<) : $(<:D) ;
Clean clean : $(<) ; Clean clean : $(<) ;
# Could not get headerscan to work :(
# HDRRULE on $(>) = HDER ;
# HDRSCAN on $(>) = $(HDRPATTERN) ;
} }
actions Pde actions Pde

View File

@ -1,305 +0,0 @@
# Arduino Makefile
# Arduino adaptation by mellis, eighthave, oli.keller
# Modified by Kerry Wong to support NetBeans
# Modified by Rob Gray (Graynomad) for use with Windows and no IDE
# This works in my environment and I use it to program two different
# 328-based boards and a Mega2560. It's not necessarily robust and
# I may have broken something in the original file that I don't use.
#
# This makefile allows you to build sketches from the command line
# without the Arduino environment.
#
# Instructions for using the makefile:
#
# 1. Copy this file into the folder with your sketch. The project code file
# should have a .c extension however the file gets copied to a .cpp before
# compilation so you still write in C++.
#
# 2. Modify the lines between the double ### rows to set the paths
# comm ports etc for your system. EG. c:/progra~1/arduino/arduino-00
# for the Arduino IDE, Note the use of short folder name, don't use
# "Program files" because spaces will break the build.
#
# Set the line containing "MCU" to match your board's processor.
# Typically ATmega328 or ATmega2560. If you're using a LilyPad Arduino,
# change F_CPU to 8000000.
#
# 3. At the command line, change to the directory containing your
# program's file and the makefile.
#
# 4. Type "make" and press enter to compile/verify your program.
# The default make target will also perform the uplode using avrdude.
#
# The first time this is done all required libraries will be built
# and a core.a file will be created in the output folder.
#
# NOTES:
# All output goes into a folder called "output" underneath the working folder.
# The default all: target creates symbol (.sym) and expanded assembly
# (.lss) files and uploads the program.
#
#
##########################################################
##########################################################
# Select processor here
MCU = atmega328p
#MCU = atmega2560
ifeq ($(MCU),atmega2560)
UPLOAD_RATE = 115200
AVRDUDE_PROTOCOL = stk500v2
COM = 39
endif
ifeq ($(MCU),atmega328p)
UPLOAD_RATE = 57600
AVRDUDE_PROTOCOL = stk500v1
COM = 33
endif
UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
ARDUINO_VERSION = 21
ARDUINO_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = $(ARDUINO_DIR)/hardware/tools/avr/bin
AVRDUDECONFIG_PATH = $(ARDUINO_DIR)/hardware/tools/avr/etc
PORT = /dev/tty.usbserial-A600eHIs
PORT2 = /dev/tty.usbserial-A9007LmI
PORT3 = /dev/tty.usbserial-A40081RP
else
ARDUINO_VERSION = 22
ARDUINO_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = /usr/bin
AVRDUDECONFIG_PATH = $(ARDUINO_DIR)/hardware/tools
PORT = /dev/ttyUSB0
PORT2 = /dev/ttyUSB1
endif
# Temporary testing of github Arduino environment
OLD_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin
AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc
ARDUINO_DIR = /opt/Arduino
PROJECT_NAME = $(notdir $(PWD))
PROJECT_DIR = .
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
ARDUINO_AVR = $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr
ARDUINO_LIB = $(ARDUINO_DIR)/libraries
F_CPU = 16000000
##########################################################
##########################################################
# Note that if your program has dependencies other than those
# already listed below, you will need to add them accordingly.
C_MODULES = \
$(ARDUINO_CORE)/wiring_pulse.c \
$(ARDUINO_CORE)/wiring_analog.c \
$(ARDUINO_CORE)/pins_arduino.c \
$(ARDUINO_CORE)/wiring.c \
$(ARDUINO_CORE)/wiring_digital.c \
$(ARDUINO_CORE)/WInterrupts.c \
$(ARDUINO_CORE)/wiring_shift.c \
CXX_MODULES = \
$(ARDUINO_CORE)/Tone.cpp \
$(ARDUINO_CORE)/main.cpp \
$(ARDUINO_CORE)/WMath.cpp \
$(ARDUINO_CORE)/Print.cpp \
$(ARDUINO_CORE)/HardwareSerial.cpp \
$(ARDUINO_LIB)/SPI/SPI.cpp \
$(ARDUINO_LIB)/EEPROM/EEPROM.cpp \
../../RF24.cpp
CXX_APP = output/$(PROJECT_NAME).cpp
MODULES = $(C_MODULES) $(CXX_MODULES)
SRC = $(C_MODULES)
CXXSRC = $(CXX_MODULES) $(CXX_APP)
FORMAT = ihex
# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile
# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
#DEBUG = stabs
DEBUG =
OPT = s
# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(ARDUINO_VERSION)
CXXDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(ARDUINO_VERSION)
# Place -I options here
CINCS = -I$(ARDUINO_LIB)/EEPROM -I$(ARDUINO_CORE) -I$(ARDUINO_LIB) -I$(PROJECT_DIR) -I$(ARDUINO_AVR) -I$(ARDUINO_LIB)/SPI -I$(MY_LIB)/Bounce -I$(MY_LIB)/ButtonSpace -I../..
CXXINCS = -I$(ARDUINO_CORE) -I$(ARDUINO_LIB)
# Compiler flag to set the C Standard level.
# c89 - "ANSI" C
# gnu89 - c89 plus GCC extensions
# c99 - ISO C99 standard (not yet fully implemented)
# gnu99 - c99 plus GCC extensions
#CSTANDARD = -std=gnu99
CDEBUG = -g$(DEBUG)
#CWARN = -Wall -Wstrict-prototypes
CWARN = -Wall # show all warnings
#CWARN = -w # suppress all warnings
CMAP = -Wl,-Map,output.map
####CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CTUNING = -ffunction-sections -fdata-sections
CXXTUNING = -fno-exceptions -ffunction-sections -fdata-sections
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
MMCU = -mmcu=$(MCU)
CFLAGS = $(CDEBUG) -O$(OPT) $(CMAP) $(CWARN) $(CTUNING) $(MMCU) $(CDEFS) $(CINCS) $(CSTANDARD) $(CEXTRA)
CXXFLAGS = $(CDEBUG) -O$(OPT) $(CWARN) $(CXXTUNING) $(CDEFS) $(CINCS)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
LDFLAGS = -O$(OPT) -lm -Wl,--gc-sections
#LDFLAGS = -O$(OPT) -lm -Wl,-Map,output/$(PROJECT_NAME).map
# Programming support using avrdude. Settings and variables.
AVRDUDE_PORT = $(PORT)
AVRDUDE_WRITE_FLASH = -U flash:w:output/$(PROJECT_NAME).hex:i
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf \
-p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE)
# Program settings
CC = $(AVR_TOOLS_PATH)/avr-gcc
CXX = $(AVR_TOOLS_PATH)/avr-g++
LD = $(AVR_TOOLS_PATH)/avr-gcc
OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
AR = $(AVR_TOOLS_PATH)/avr-ar
SIZE = $(AVR_TOOLS_PATH)/avr-size
NM = $(AVR_TOOLS_PATH)/avr-nm
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
REMOVE = rm -f
MV = mv -f
# Define all object files.
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
OBJ_MODULES = $(C_MODULES:.c=.o) $(CXX_MODULES:.cpp=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = $(CFLAGS) -mmcu=$(MCU)
ALL_CXXFLAGS = $(CXXFLAGS) -mmcu=$(MCU)
ALL_ASFLAGS = -x assembler-with-cpp $(ASFLAGS) -mmcu=$(MCU)
ALL_LDFLAGS = $(LDFLAGS) -mmcu=$(MCU)
# Default target.
# This is th etarget that gets executed with a make command
# that has no parameters, ie "make".
all: applet_files build sym lss size upload
build: elf hex
output/$(PROJECT_NAME).cpp: $(PROJECT_NAME).pde
test -d output || mkdir output
echo "#include <WProgram.h>" > $@
echo "#line 1 \"$<\"" >> $@
cat $< >> $@
elf: output/$(PROJECT_NAME).elf
hex: output/$(PROJECT_NAME).hex
eep: output/$(PROJECT_NAME).eep
lss: output/$(PROJECT_NAME).lss
#sym: output/$(PROJECT_NAME).sym
# Upload HEX file to Arduino
upload: upload1 upload2
upload1: output/$(PROJECT_NAME).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT) $(AVRDUDE_WRITE_FLASH)
upload2: output/$(PROJECT_NAME).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT2) $(AVRDUDE_WRITE_FLASH)
upload3: output/$(PROJECT_NAME).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT3) $(AVRDUDE_WRITE_FLASH)
sym:
$(NM) -n -C --format=posix output/$(PROJECT_NAME).elf > output/$(PROJECT_NAME).sym
# Display size of file.
size:
$(SIZE) output/$(PROJECT_NAME).elf
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: output/$(PROJECT_NAME).elf
$(COFFCONVERT) -O coff-avr output/$(PROJECT_NAME).elf $(PROJECT_NAME).cof
extcoff: $(PROJECT_NAME).elf
$(COFFCONVERT) -O coff-ext-avr output/$(PROJECT_NAME).elf $(PROJECT_NAME).cof
.SUFFIXES: .elf .hex .eep .lss .sym
.elf.hex:
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
.elf.eep:
$(OBJCOPY) -O $(FORMAT) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--no-change-warnings \
--change-section-lma .eeprom=0 $< $@
# Create extended listing file from ELF output file.
.elf.lss:
$(OBJDUMP) -h -S $< > $@
# Link: create ELF output file from library.
#output/$(PROJECT_NAME).elf: $(PROJECT_NAME).c output/core.a
output/$(PROJECT_NAME).elf: output/$(PROJECT_NAME).o output/core.a
$(LD) $(ALL_LDFLAGS) -o $@ output/$(PROJECT_NAME).o output/core.a
output/core.a: $(OBJ_MODULES)
@for i in $(OBJ_MODULES); do echo $(AR) rcs output/core.a $$i; $(AR) rcs output/core.a $$i; done
# Compile: create object files from C++ source files.
.cpp.o:
$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
# Compile: create object files from C source files.
.c.o:
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
.c.s:
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
.S.o:
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Automatic dependencies
%.d: %.c
$(CC) -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
%.d: %.cpp
$(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
# Target: clean project.
clean:
$(REMOVE) output/$(PROJECT_NAME).hex output/$(PROJECT_NAME).eep output/$(PROJECT_NAME).cof output/$(PROJECT_NAME).elf \
output/$(PROJECT_NAME).map output/$(PROJECT_NAME).sym output/$(PROJECT_NAME).lss output/core.a \
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
#.PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter
.PHONY: all build elf hex eep lss sym program coff extcoff applet_files sizebefore sizeafter
#include $(SRC:.c=.d)
#include $(CXXSRC:.cpp=.d)

206
examples/pingpair/Jamfile Normal file
View File

@ -0,0 +1,206 @@
PROJECT_NAME = $(PWD:B) ;
PROJECT_DIR = . ;
PROJECT_LIBS = SPI RF24 ;
OUT_DIR = ojam ;
F_CPU = 16000000 ;
MCU = atmega328p ;
PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ;
UPLOAD_RATE = 57600 ;
AVRDUDE_PROTOCOL = stk500v1 ;
COM = 33 ;
# Host-specific overrides for locations
if $(OS) = MACOSX
{
ARDUINO_VERSION = 22 ;
OLD_DIR = /opt/arduino-0021 ;
AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ;
AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ;
ARDUINO_DIR = /opt/Arduino ;
ARDUINO_AVR = /usr/lib/avr/include ;
}
# Where is everything?
ARDUINO_VERSION ?= 22 ;
AVR_TOOLS_PATH ?= /usr/bin ;
ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ;
ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ;
AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ;
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ;
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ;
AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ;
AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ;
AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ;
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ;
DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
CTUNING = -ffunction-sections -fdata-sections ;
CXXTUNING = -fno-exceptions -fno-strict-aliasing ;
CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ;
CXXFLAGS = $(CFLAGS) $(CXXTUNING) ;
LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ;
# Search everywhere for headers
HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ;
# Grab everything from the core directory
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
# can specify specific modules to pick up in PROJECT_MODULES
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ;
# In addition to explicitly-specified program modules, pick up anything from the current
# dir.
PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ;
# Shortcut for the out files
OUT = $(OUT_DIR)/$(PROJECT_NAME) ;
# AvrDude setup
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ;
rule GitVersion
{
Always $(<) ;
Depends all : $(<) ;
}
actions GitVersion
{
echo "const char program_version[] = \"\\" > $(<)
git log -1 --pretty=format:%h >> $(<)
echo "\";" >> $(<)
}
GitVersion version.h ;
rule AvrCc
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}
actions AvrCc
{
$(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>)
}
rule AvrC++
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}
actions AvrC++
{
$(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>)
}
rule Pde
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
}
actions Pde
{
echo "#include <WProgram.h>" > $(<)
echo "#line 1 \"$(>)\"" >> $(<)
cat $(>) >> $(<)
}
rule AvrPde
{
local _CPP = $(OUT_DIR)/$(_I:B).cpp ;
Pde $(_CPP) : $(>) ;
AvrC++ $(<) : $(_CPP) ;
}
rule AvrObject
{
switch $(>:S)
{
case .c : AvrCc $(<) : $(>) ;
case .cpp : AvrC++ $(<) : $(>) ;
case .pde : AvrPde $(<) : $(>) ;
}
}
rule AvrObjects
{
for _I in $(<)
{
AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ;
}
}
rule AvrMainFromObjects
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
MkDir $(<:D) ;
Depends all : $(<) ;
Clean clean : $(<) ;
}
actions AvrMainFromObjects
{
$(AVR_LD) $(LDFLAGS) -o $(<) $(>)
}
rule AvrMain
{
AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ;
AvrObjects $(>) ;
}
rule AvrHex
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Depends hex : $(<) ;
Clean clean : $(<) ;
}
actions AvrHex
{
$(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<)
}
rule AvrUpload
{
Depends $(1) : $(2) ;
Depends $(2) : $(3) ;
NotFile $(1) ;
Always $(1) ;
Always $(2) ;
AvrUploadAction $(2) : $(3) ;
}
actions AvrUploadAction
{
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
}
AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
AvrHex $(OUT).hex : $(OUT).elf ;
AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ;
AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ;
AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ;

View File

@ -1,305 +0,0 @@
# Arduino Makefile
# Arduino adaptation by mellis, eighthave, oli.keller
# Modified by Kerry Wong to support NetBeans
# Modified by Rob Gray (Graynomad) for use with Windows and no IDE
# This works in my environment and I use it to program two different
# 328-based boards and a Mega2560. It's not necessarily robust and
# I may have broken something in the original file that I don't use.
#
# This makefile allows you to build sketches from the command line
# without the Arduino environment.
#
# Instructions for using the makefile:
#
# 1. Copy this file into the folder with your sketch. The project code file
# should have a .c extension however the file gets copied to a .cpp before
# compilation so you still write in C++.
#
# 2. Modify the lines between the double ### rows to set the paths
# comm ports etc for your system. EG. c:/progra~1/arduino/arduino-00
# for the Arduino IDE, Note the use of short folder name, don't use
# "Program files" because spaces will break the build.
#
# Set the line containing "MCU" to match your board's processor.
# Typically ATmega328 or ATmega2560. If you're using a LilyPad Arduino,
# change F_CPU to 8000000.
#
# 3. At the command line, change to the directory containing your
# program's file and the makefile.
#
# 4. Type "make" and press enter to compile/verify your program.
# The default make target will also perform the uplode using avrdude.
#
# The first time this is done all required libraries will be built
# and a core.a file will be created in the output folder.
#
# NOTES:
# All output goes into a folder called "output" underneath the working folder.
# The default all: target creates symbol (.sym) and expanded assembly
# (.lss) files and uploads the program.
#
#
##########################################################
##########################################################
# Select processor here
MCU = atmega328p
#MCU = atmega2560
ifeq ($(MCU),atmega2560)
UPLOAD_RATE = 115200
AVRDUDE_PROTOCOL = stk500v2
COM = 39
endif
ifeq ($(MCU),atmega328p)
UPLOAD_RATE = 57600
AVRDUDE_PROTOCOL = stk500v1
COM = 33
endif
UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
ARDUINO_VERSION = 21
ARDUINO_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = $(ARDUINO_DIR)/hardware/tools/avr/bin
AVRDUDECONFIG_PATH = $(ARDUINO_DIR)/hardware/tools/avr/etc
PORT = /dev/tty.usbserial-A600eHIs
PORT2 = /dev/tty.usbserial-A9007LmI
PORT3 = /dev/tty.usbserial-A40081RP
else
ARDUINO_VERSION = 22
ARDUINO_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = /usr/bin
AVRDUDECONFIG_PATH = $(ARDUINO_DIR)/hardware/tools
PORT = /dev/ttyUSB0
PORT2 = /dev/ttyUSB1
endif
# Temporary testing of github Arduino environment
OLD_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin
AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc
ARDUINO_DIR = /opt/Arduino
PROJECT_NAME = $(notdir $(PWD))
PROJECT_DIR = .
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
ARDUINO_AVR = $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr
ARDUINO_LIB = $(ARDUINO_DIR)/libraries
F_CPU = 16000000
##########################################################
##########################################################
# Note that if your program has dependencies other than those
# already listed below, you will need to add them accordingly.
C_MODULES = \
$(ARDUINO_CORE)/wiring_pulse.c \
$(ARDUINO_CORE)/wiring_analog.c \
$(ARDUINO_CORE)/pins_arduino.c \
$(ARDUINO_CORE)/wiring.c \
$(ARDUINO_CORE)/wiring_digital.c \
$(ARDUINO_CORE)/WInterrupts.c \
$(ARDUINO_CORE)/wiring_shift.c \
CXX_MODULES = \
$(ARDUINO_CORE)/Tone.cpp \
$(ARDUINO_CORE)/main.cpp \
$(ARDUINO_CORE)/WMath.cpp \
$(ARDUINO_CORE)/Print.cpp \
$(ARDUINO_CORE)/HardwareSerial.cpp \
$(ARDUINO_LIB)/SPI/SPI.cpp \
$(ARDUINO_LIB)/EEPROM/EEPROM.cpp \
../../RF24.cpp
CXX_APP = output/$(PROJECT_NAME).cpp
MODULES = $(C_MODULES) $(CXX_MODULES)
SRC = $(C_MODULES)
CXXSRC = $(CXX_MODULES) $(CXX_APP)
FORMAT = ihex
# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile
# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
#DEBUG = stabs
DEBUG =
OPT = s
# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(ARDUINO_VERSION)
CXXDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(ARDUINO_VERSION)
# Place -I options here
CINCS = -I$(ARDUINO_LIB)/EEPROM -I$(ARDUINO_CORE) -I$(ARDUINO_LIB) -I$(PROJECT_DIR) -I$(ARDUINO_AVR) -I$(ARDUINO_LIB)/SPI -I../..
CXXINCS = -I$(ARDUINO_CORE) -I$(ARDUINO_LIB)
# Compiler flag to set the C Standard level.
# c89 - "ANSI" C
# gnu89 - c89 plus GCC extensions
# c99 - ISO C99 standard (not yet fully implemented)
# gnu99 - c99 plus GCC extensions
#CSTANDARD = -std=gnu99
CDEBUG = -g$(DEBUG)
#CWARN = -Wall -Wstrict-prototypes
CWARN = -Wall # show all warnings
#CWARN = -w # suppress all warnings
CMAP = -Wl,-Map,output.map
####CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CTUNING = -ffunction-sections -fdata-sections
CXXTUNING = -fno-exceptions -ffunction-sections -fdata-sections
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
MMCU = -mmcu=$(MCU)
CFLAGS = $(CDEBUG) -O$(OPT) $(CMAP) $(CWARN) $(CTUNING) $(MMCU) $(CDEFS) $(CINCS) $(CSTANDARD) $(CEXTRA)
CXXFLAGS = $(CDEBUG) -O$(OPT) $(CWARN) $(CXXTUNING) $(CDEFS) $(CINCS)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
LDFLAGS = -O$(OPT) -lm -Wl,--gc-sections
#LDFLAGS = -O$(OPT) -lm -Wl,-Map,output/$(PROJECT_NAME).map
# Programming support using avrdude. Settings and variables.
AVRDUDE_PORT = $(PORT)
AVRDUDE_WRITE_FLASH = -U flash:w:output/$(PROJECT_NAME).hex:i
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf \
-p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE)
# Program settings
CC = $(AVR_TOOLS_PATH)/avr-gcc
CXX = $(AVR_TOOLS_PATH)/avr-g++
LD = $(AVR_TOOLS_PATH)/avr-gcc
OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
AR = $(AVR_TOOLS_PATH)/avr-ar
SIZE = $(AVR_TOOLS_PATH)/avr-size
NM = $(AVR_TOOLS_PATH)/avr-nm
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
REMOVE = rm -f
MV = mv -f
# Define all object files.
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
OBJ_MODULES = $(C_MODULES:.c=.o) $(CXX_MODULES:.cpp=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = $(CFLAGS) -mmcu=$(MCU)
ALL_CXXFLAGS = $(CXXFLAGS) -mmcu=$(MCU)
ALL_ASFLAGS = -x assembler-with-cpp $(ASFLAGS) -mmcu=$(MCU)
ALL_LDFLAGS = $(LDFLAGS) -mmcu=$(MCU)
# Default target.
# This is th etarget that gets executed with a make command
# that has no parameters, ie "make".
all: applet_files build sym lss size upload
build: elf hex
output/$(PROJECT_NAME).cpp: $(PROJECT_NAME).pde
test -d output || mkdir output
echo "#include <WProgram.h>" > $@
echo "#line 1 \"$<\"" >> $@
cat $< >> $@
elf: output/$(PROJECT_NAME).elf
hex: output/$(PROJECT_NAME).hex
eep: output/$(PROJECT_NAME).eep
lss: output/$(PROJECT_NAME).lss
#sym: output/$(PROJECT_NAME).sym
# Upload HEX file to Arduino
upload: upload1 upload2
upload1: output/$(PROJECT_NAME).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT) $(AVRDUDE_WRITE_FLASH)
upload2: output/$(PROJECT_NAME).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT2) $(AVRDUDE_WRITE_FLASH)
upload3: output/$(PROJECT_NAME).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT3) $(AVRDUDE_WRITE_FLASH)
sym:
$(NM) -n -C --format=posix output/$(PROJECT_NAME).elf > output/$(PROJECT_NAME).sym
# Display size of file.
size:
$(SIZE) output/$(PROJECT_NAME).elf
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: output/$(PROJECT_NAME).elf
$(COFFCONVERT) -O coff-avr output/$(PROJECT_NAME).elf $(PROJECT_NAME).cof
extcoff: $(PROJECT_NAME).elf
$(COFFCONVERT) -O coff-ext-avr output/$(PROJECT_NAME).elf $(PROJECT_NAME).cof
.SUFFIXES: .elf .hex .eep .lss .sym
.elf.hex:
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
.elf.eep:
$(OBJCOPY) -O $(FORMAT) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--no-change-warnings \
--change-section-lma .eeprom=0 $< $@
# Create extended listing file from ELF output file.
.elf.lss:
$(OBJDUMP) -h -S $< > $@
# Link: create ELF output file from library.
#output/$(PROJECT_NAME).elf: $(PROJECT_NAME).c output/core.a
output/$(PROJECT_NAME).elf: output/$(PROJECT_NAME).o output/core.a
$(LD) $(ALL_LDFLAGS) -o $@ output/$(PROJECT_NAME).o output/core.a
output/core.a: $(OBJ_MODULES)
@for i in $(OBJ_MODULES); do echo $(AR) rcs output/core.a $$i; $(AR) rcs output/core.a $$i; done
# Compile: create object files from C++ source files.
.cpp.o:
$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
# Compile: create object files from C source files.
.c.o:
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
.c.s:
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
.S.o:
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Automatic dependencies
%.d: %.c
$(CC) -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
%.d: %.cpp
$(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
# Target: clean project.
clean:
$(REMOVE) output/$(PROJECT_NAME).hex output/$(PROJECT_NAME).eep output/$(PROJECT_NAME).cof output/$(PROJECT_NAME).elf \
output/$(PROJECT_NAME).map output/$(PROJECT_NAME).sym output/$(PROJECT_NAME).lss output/core.a \
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
#.PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter
.PHONY: all build elf hex eep lss sym program coff extcoff applet_files sizebefore sizeafter
#include $(SRC:.c=.d)
#include $(CXXSRC:.cpp=.d)

View File

@ -18,7 +18,7 @@
#include "WProgram.h" #include "WProgram.h"
int serial_putc( char c, FILE *t ) int serial_putc( char c, FILE * )
{ {
Serial.write( c ); Serial.write( c );

View File

@ -0,0 +1,206 @@
PROJECT_NAME = $(PWD:B) ;
PROJECT_DIR = . ;
PROJECT_LIBS = SPI RF24 ;
OUT_DIR = ojam ;
F_CPU = 16000000 ;
MCU = atmega328p ;
PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ;
UPLOAD_RATE = 57600 ;
AVRDUDE_PROTOCOL = stk500v1 ;
COM = 33 ;
# Host-specific overrides for locations
if $(OS) = MACOSX
{
ARDUINO_VERSION = 22 ;
OLD_DIR = /opt/arduino-0021 ;
AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ;
AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ;
ARDUINO_DIR = /opt/Arduino ;
ARDUINO_AVR = /usr/lib/avr/include ;
}
# Where is everything?
ARDUINO_VERSION ?= 22 ;
AVR_TOOLS_PATH ?= /usr/bin ;
ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ;
ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ;
AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ;
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ;
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ;
AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ;
AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ;
AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ;
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ;
DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
CTUNING = -ffunction-sections -fdata-sections ;
CXXTUNING = -fno-exceptions -fno-strict-aliasing ;
CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ;
CXXFLAGS = $(CFLAGS) $(CXXTUNING) ;
LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ;
# Search everywhere for headers
HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ;
# Grab everything from the core directory
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
# can specify specific modules to pick up in PROJECT_MODULES
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ;
# In addition to explicitly-specified program modules, pick up anything from the current
# dir.
PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ;
# Shortcut for the out files
OUT = $(OUT_DIR)/$(PROJECT_NAME) ;
# AvrDude setup
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ;
rule GitVersion
{
Always $(<) ;
Depends all : $(<) ;
}
actions GitVersion
{
echo "const char program_version[] = \"\\" > $(<)
git log -1 --pretty=format:%h >> $(<)
echo "\";" >> $(<)
}
GitVersion version.h ;
rule AvrCc
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}
actions AvrCc
{
$(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>)
}
rule AvrC++
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}
actions AvrC++
{
$(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>)
}
rule Pde
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
}
actions Pde
{
echo "#include <WProgram.h>" > $(<)
echo "#line 1 \"$(>)\"" >> $(<)
cat $(>) >> $(<)
}
rule AvrPde
{
local _CPP = $(OUT_DIR)/$(_I:B).cpp ;
Pde $(_CPP) : $(>) ;
AvrC++ $(<) : $(_CPP) ;
}
rule AvrObject
{
switch $(>:S)
{
case .c : AvrCc $(<) : $(>) ;
case .cpp : AvrC++ $(<) : $(>) ;
case .pde : AvrPde $(<) : $(>) ;
}
}
rule AvrObjects
{
for _I in $(<)
{
AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ;
}
}
rule AvrMainFromObjects
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
MkDir $(<:D) ;
Depends all : $(<) ;
Clean clean : $(<) ;
}
actions AvrMainFromObjects
{
$(AVR_LD) $(LDFLAGS) -o $(<) $(>)
}
rule AvrMain
{
AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ;
AvrObjects $(>) ;
}
rule AvrHex
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Depends hex : $(<) ;
Clean clean : $(<) ;
}
actions AvrHex
{
$(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<)
}
rule AvrUpload
{
Depends $(1) : $(2) ;
Depends $(2) : $(3) ;
NotFile $(1) ;
Always $(1) ;
Always $(2) ;
AvrUploadAction $(2) : $(3) ;
}
actions AvrUploadAction
{
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
}
AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
AvrHex $(OUT).hex : $(OUT).elf ;
AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ;
AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ;
AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ;

View File

@ -1,290 +0,0 @@
# Arduino Makefile
# Arduino adaptation by mellis, eighthave, oli.keller
# Modified by Kerry Wong to support NetBeans
# Modified by Rob Gray (Graynomad) for use with Windows and no IDE
# This works in my environment and I use it to program two different
# 328-based boards and a Mega2560. It's not necessarily robust and
# I may have broken something in the original file that I don't use.
#
# This makefile allows you to build sketches from the command line
# without the Arduino environment.
#
# Instructions for using the makefile:
#
# 1. Copy this file into the folder with your sketch. The project code file
# should have a .c extension however the file gets copied to a .cpp before
# compilation so you still write in C++.
#
# 2. Modify the lines between the double ### rows to set the paths
# comm ports etc for your system. EG. c:/progra~1/arduino/arduino-00
# for the Arduino IDE, Note the use of short folder name, don't use
# "Program files" because spaces will break the build.
#
# Set the line containing "MCU" to match your board's processor.
# Typically ATmega328 or ATmega2560. If you're using a LilyPad Arduino,
# change F_CPU to 8000000.
#
# 3. At the command line, change to the directory containing your
# program's file and the makefile.
#
# 4. Type "make" and press enter to compile/verify your program.
# The default make target will also perform the uplode using avrdude.
#
# The first time this is done all required libraries will be built
# and a core.a file will be created in the output folder.
#
# NOTES:
# All output goes into a folder called "output" underneath the working folder.
# The default all: target creates symbol (.sym) and expanded assembly
# (.lss) files and uploads the program.
#
#
##########################################################
##########################################################
# Select processor here
MCU = atmega328p
#MCU = atmega2560
ifeq ($(MCU),atmega2560)
UPLOAD_RATE = 115200
AVRDUDE_PROTOCOL = stk500v2
COM = 39
endif
ifeq ($(MCU),atmega328p)
UPLOAD_RATE = 57600
AVRDUDE_PROTOCOL = stk500v1
COM = 33
endif
UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
ARDUINO_VERSION = 21
ARDUINO_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = $(ARDUINO_DIR)/hardware/tools/avr/bin
AVRDUDECONFIG_PATH = $(ARDUINO_DIR)/hardware/tools/avr/etc
PORT = /dev/tty.usbserial-A600eHIs
PORT2 = /dev/tty.usbserial-A9007LmI
else
ARDUINO_VERSION = 22
ARDUINO_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = /usr/bin
AVRDUDECONFIG_PATH = $(ARDUINO_DIR)/hardware/tools
PORT = /dev/ttyUSB0
PORT2 = /dev/ttyUSB1
endif
PROJECT_NAME = $(notdir $(PWD))
PROJECT_DIR = .
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
ARDUINO_AVR = $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr
ARDUINO_LIB = $(ARDUINO_DIR)/libraries
F_CPU = 16000000
##########################################################
##########################################################
# Note that if your program has dependencies other than those
# already listed below, you will need to add them accordingly.
C_MODULES = \
$(ARDUINO_CORE)/wiring_pulse.c \
$(ARDUINO_CORE)/wiring_analog.c \
$(ARDUINO_CORE)/pins_arduino.c \
$(ARDUINO_CORE)/wiring.c \
$(ARDUINO_CORE)/wiring_digital.c \
$(ARDUINO_CORE)/WInterrupts.c \
$(ARDUINO_CORE)/wiring_shift.c \
CXX_MODULES = \
$(ARDUINO_CORE)/Tone.cpp \
$(ARDUINO_CORE)/main.cpp \
$(ARDUINO_CORE)/WMath.cpp \
$(ARDUINO_CORE)/Print.cpp \
$(ARDUINO_CORE)/HardwareSerial.cpp \
$(ARDUINO_LIB)/SPI/SPI.cpp \
../../RF24.cpp
CXX_APP = output/$(PROJECT_NAME).cpp
MODULES = $(C_MODULES) $(CXX_MODULES)
SRC = $(C_MODULES)
CXXSRC = $(CXX_MODULES) $(CXX_APP)
FORMAT = ihex
# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile
# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
#DEBUG = stabs
DEBUG =
OPT = s
# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(ARDUINO_VERSION)
CXXDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(ARDUINO_VERSION)
# Place -I options here
CINCS = -I$(ARDUINO_CORE) -I$(ARDUINO_LIB) -I$(PROJECT_DIR) -I$(ARDUINO_AVR) -I$(ARDUINO_LIB)/SPI -I../..
CXXINCS = -I$(ARDUINO_CORE) -I$(ARDUINO_LIB)
# Compiler flag to set the C Standard level.
# c89 - "ANSI" C
# gnu89 - c89 plus GCC extensions
# c99 - ISO C99 standard (not yet fully implemented)
# gnu99 - c99 plus GCC extensions
#CSTANDARD = -std=gnu99
CDEBUG = -g$(DEBUG)
#CWARN = -Wall -Wstrict-prototypes
CWARN = -Wall # show all warnings
#CWARN = -w # suppress all warnings
CMAP = -Wl,-Map,output.map
####CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CTUNING = -ffunction-sections -fdata-sections
CXXTUNING = -fno-exceptions -ffunction-sections -fdata-sections
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
MMCU = -mmcu=$(MCU)
CFLAGS = $(CDEBUG) -O$(OPT) $(CMAP) $(CWARN) $(CTUNING) $(MMCU) $(CDEFS) $(CINCS) $(CSTANDARD) $(CEXTRA)
CXXFLAGS = $(CDEBUG) -O$(OPT) $(CWARN) $(CXXTUNING) $(CDEFS) $(CINCS)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
LDFLAGS = -O$(OPT) -lm -Wl,--gc-sections
#LDFLAGS = -O$(OPT) -lm -Wl,-Map,output/$(PROJECT_NAME).map
# Programming support using avrdude. Settings and variables.
AVRDUDE_PORT = $(PORT)
AVRDUDE_WRITE_FLASH = -U flash:w:output/$(PROJECT_NAME).hex:i
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf \
-p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE)
# Program settings
CC = $(AVR_TOOLS_PATH)/avr-gcc
CXX = $(AVR_TOOLS_PATH)/avr-g++
LD = $(AVR_TOOLS_PATH)/avr-gcc
OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
AR = $(AVR_TOOLS_PATH)/avr-ar
SIZE = $(AVR_TOOLS_PATH)/avr-size
NM = $(AVR_TOOLS_PATH)/avr-nm
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
REMOVE = rm -f
MV = mv -f
# Define all object files.
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
OBJ_MODULES = $(C_MODULES:.c=.o) $(CXX_MODULES:.cpp=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = $(CFLAGS) -mmcu=$(MCU)
ALL_CXXFLAGS = $(CXXFLAGS) -mmcu=$(MCU)
ALL_ASFLAGS = -x assembler-with-cpp $(ASFLAGS) -mmcu=$(MCU)
ALL_LDFLAGS = $(LDFLAGS) -mmcu=$(MCU)
# Default target.
# This is th etarget that gets executed with a make command
# that has no parameters, ie "make".
all: applet_files build sym lss size upload
build: elf hex
output/$(PROJECT_NAME).cpp: $(PROJECT_NAME).pde
test -d output || mkdir output
echo "#include <WProgram.h>" > $@
echo "#line 1 \"$<\"" >> $@
cat $< >> $@
elf: output/$(PROJECT_NAME).elf
hex: output/$(PROJECT_NAME).hex
eep: output/$(PROJECT_NAME).eep
lss: output/$(PROJECT_NAME).lss
#sym: output/$(PROJECT_NAME).sym
# Upload HEX file to Arduino
upload: output/$(PROJECT_NAME).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT) $(AVRDUDE_WRITE_FLASH)
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT2) $(AVRDUDE_WRITE_FLASH)
sym:
$(NM) -n -C --format=posix output/$(PROJECT_NAME).elf > output/$(PROJECT_NAME).sym
# Display size of file.
size:
$(SIZE) output/$(PROJECT_NAME).elf
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: output/$(PROJECT_NAME).elf
$(COFFCONVERT) -O coff-avr output/$(PROJECT_NAME).elf $(PROJECT_NAME).cof
extcoff: $(PROJECT_NAME).elf
$(COFFCONVERT) -O coff-ext-avr output/$(PROJECT_NAME).elf $(PROJECT_NAME).cof
.SUFFIXES: .elf .hex .eep .lss .sym
.elf.hex:
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
.elf.eep:
$(OBJCOPY) -O $(FORMAT) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--no-change-warnings \
--change-section-lma .eeprom=0 $< $@
# Create extended listing file from ELF output file.
.elf.lss:
$(OBJDUMP) -h -S $< > $@
# Link: create ELF output file from library.
#output/$(PROJECT_NAME).elf: $(PROJECT_NAME).c output/core.a
output/$(PROJECT_NAME).elf: output/$(PROJECT_NAME).o output/core.a
$(LD) $(ALL_LDFLAGS) -o $@ output/$(PROJECT_NAME).o output/core.a
output/core.a: $(OBJ_MODULES)
@for i in $(OBJ_MODULES); do echo $(AR) rcs output/core.a $$i; $(AR) rcs output/core.a $$i; done
# Compile: create object files from C++ source files.
.cpp.o:
$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
# Compile: create object files from C source files.
.c.o:
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
.c.s:
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
.S.o:
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Automatic dependencies
%.d: %.c
$(CC) -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
%.d: %.cpp
$(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
# Target: clean project.
clean:
$(REMOVE) output/$(PROJECT_NAME).hex output/$(PROJECT_NAME).eep output/$(PROJECT_NAME).cof output/$(PROJECT_NAME).elf \
output/$(PROJECT_NAME).map output/$(PROJECT_NAME).sym output/$(PROJECT_NAME).lss output/core.a \
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
#.PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter
.PHONY: all build elf hex eep lss sym program coff extcoff applet_files sizebefore sizeafter
#include $(SRC:.c=.d)
#include $(CXXSRC:.cpp=.d)

View File

@ -18,7 +18,7 @@
#include "WProgram.h" #include "WProgram.h"
int serial_putc( char c, FILE *t ) int serial_putc( char c, FILE * )
{ {
Serial.write( c ); Serial.write( c );

View File

@ -0,0 +1,206 @@
PROJECT_NAME = $(PWD:B) ;
PROJECT_DIR = . ;
PROJECT_LIBS = SPI RF24 ;
OUT_DIR = ojam ;
F_CPU = 16000000 ;
MCU = atmega328p ;
PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ;
UPLOAD_RATE = 57600 ;
AVRDUDE_PROTOCOL = stk500v1 ;
COM = 33 ;
# Host-specific overrides for locations
if $(OS) = MACOSX
{
ARDUINO_VERSION = 22 ;
OLD_DIR = /opt/arduino-0021 ;
AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ;
AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ;
ARDUINO_DIR = /opt/Arduino ;
ARDUINO_AVR = /usr/lib/avr/include ;
}
# Where is everything?
ARDUINO_VERSION ?= 22 ;
AVR_TOOLS_PATH ?= /usr/bin ;
ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ;
ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ;
AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ;
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ;
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ;
AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ;
AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ;
AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ;
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ;
DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
CTUNING = -ffunction-sections -fdata-sections ;
CXXTUNING = -fno-exceptions -fno-strict-aliasing ;
CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ;
CXXFLAGS = $(CFLAGS) $(CXXTUNING) ;
LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ;
# Search everywhere for headers
HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ;
# Grab everything from the core directory
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
# can specify specific modules to pick up in PROJECT_MODULES
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ;
# In addition to explicitly-specified program modules, pick up anything from the current
# dir.
PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ;
# Shortcut for the out files
OUT = $(OUT_DIR)/$(PROJECT_NAME) ;
# AvrDude setup
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ;
rule GitVersion
{
Always $(<) ;
Depends all : $(<) ;
}
actions GitVersion
{
echo "const char program_version[] = \"\\" > $(<)
git log -1 --pretty=format:%h >> $(<)
echo "\";" >> $(<)
}
GitVersion version.h ;
rule AvrCc
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}
actions AvrCc
{
$(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>)
}
rule AvrC++
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}
actions AvrC++
{
$(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>)
}
rule Pde
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
}
actions Pde
{
echo "#include <WProgram.h>" > $(<)
echo "#line 1 \"$(>)\"" >> $(<)
cat $(>) >> $(<)
}
rule AvrPde
{
local _CPP = $(OUT_DIR)/$(_I:B).cpp ;
Pde $(_CPP) : $(>) ;
AvrC++ $(<) : $(_CPP) ;
}
rule AvrObject
{
switch $(>:S)
{
case .c : AvrCc $(<) : $(>) ;
case .cpp : AvrC++ $(<) : $(>) ;
case .pde : AvrPde $(<) : $(>) ;
}
}
rule AvrObjects
{
for _I in $(<)
{
AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ;
}
}
rule AvrMainFromObjects
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
MkDir $(<:D) ;
Depends all : $(<) ;
Clean clean : $(<) ;
}
actions AvrMainFromObjects
{
$(AVR_LD) $(LDFLAGS) -o $(<) $(>)
}
rule AvrMain
{
AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ;
AvrObjects $(>) ;
}
rule AvrHex
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Depends hex : $(<) ;
Clean clean : $(<) ;
}
actions AvrHex
{
$(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<)
}
rule AvrUpload
{
Depends $(1) : $(2) ;
Depends $(2) : $(3) ;
NotFile $(1) ;
Always $(1) ;
Always $(2) ;
AvrUploadAction $(2) : $(3) ;
}
actions AvrUploadAction
{
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
}
AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
AvrHex $(OUT).hex : $(OUT).elf ;
AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ;
AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ;
AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ;

View File

@ -1,290 +0,0 @@
# Arduino Makefile
# Arduino adaptation by mellis, eighthave, oli.keller
# Modified by Kerry Wong to support NetBeans
# Modified by Rob Gray (Graynomad) for use with Windows and no IDE
# This works in my environment and I use it to program two different
# 328-based boards and a Mega2560. It's not necessarily robust and
# I may have broken something in the original file that I don't use.
#
# This makefile allows you to build sketches from the command line
# without the Arduino environment.
#
# Instructions for using the makefile:
#
# 1. Copy this file into the folder with your sketch. The project code file
# should have a .c extension however the file gets copied to a .cpp before
# compilation so you still write in C++.
#
# 2. Modify the lines between the double ### rows to set the paths
# comm ports etc for your system. EG. c:/progra~1/arduino/arduino-00
# for the Arduino IDE, Note the use of short folder name, don't use
# "Program files" because spaces will break the build.
#
# Set the line containing "MCU" to match your board's processor.
# Typically ATmega328 or ATmega2560. If you're using a LilyPad Arduino,
# change F_CPU to 8000000.
#
# 3. At the command line, change to the directory containing your
# program's file and the makefile.
#
# 4. Type "make" and press enter to compile/verify your program.
# The default make target will also perform the uplode using avrdude.
#
# The first time this is done all required libraries will be built
# and a core.a file will be created in the output folder.
#
# NOTES:
# All output goes into a folder called "output" underneath the working folder.
# The default all: target creates symbol (.sym) and expanded assembly
# (.lss) files and uploads the program.
#
#
##########################################################
##########################################################
# Select processor here
MCU = atmega328p
#MCU = atmega2560
ifeq ($(MCU),atmega2560)
UPLOAD_RATE = 115200
AVRDUDE_PROTOCOL = stk500v2
COM = 39
endif
ifeq ($(MCU),atmega328p)
UPLOAD_RATE = 57600
AVRDUDE_PROTOCOL = stk500v1
COM = 33
endif
UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
ARDUINO_VERSION = 21
ARDUINO_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = $(ARDUINO_DIR)/hardware/tools/avr/bin
AVRDUDECONFIG_PATH = $(ARDUINO_DIR)/hardware/tools/avr/etc
PORT = /dev/tty.usbserial-A600eHIs
PORT2 = /dev/tty.usbserial-A9007LmI
else
ARDUINO_VERSION = 22
ARDUINO_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = /usr/bin
AVRDUDECONFIG_PATH = $(ARDUINO_DIR)/hardware/tools
PORT = /dev/ttyUSB0
PORT2 = /dev/ttyUSB1
endif
PROJECT_NAME = $(notdir $(PWD))
PROJECT_DIR = .
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
ARDUINO_AVR = $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr
ARDUINO_LIB = $(ARDUINO_DIR)/libraries
F_CPU = 16000000
##########################################################
##########################################################
# Note that if your program has dependencies other than those
# already listed below, you will need to add them accordingly.
C_MODULES = \
$(ARDUINO_CORE)/wiring_pulse.c \
$(ARDUINO_CORE)/wiring_analog.c \
$(ARDUINO_CORE)/pins_arduino.c \
$(ARDUINO_CORE)/wiring.c \
$(ARDUINO_CORE)/wiring_digital.c \
$(ARDUINO_CORE)/WInterrupts.c \
$(ARDUINO_CORE)/wiring_shift.c \
CXX_MODULES = \
$(ARDUINO_CORE)/Tone.cpp \
$(ARDUINO_CORE)/main.cpp \
$(ARDUINO_CORE)/WMath.cpp \
$(ARDUINO_CORE)/Print.cpp \
$(ARDUINO_CORE)/HardwareSerial.cpp \
$(ARDUINO_LIB)/SPI/SPI.cpp \
../../RF24.cpp
CXX_APP = output/$(PROJECT_NAME).cpp
MODULES = $(C_MODULES) $(CXX_MODULES)
SRC = $(C_MODULES)
CXXSRC = $(CXX_MODULES) $(CXX_APP)
FORMAT = ihex
# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile
# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
#DEBUG = stabs
DEBUG =
OPT = s
# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(ARDUINO_VERSION)
CXXDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(ARDUINO_VERSION)
# Place -I options here
CINCS = -I$(ARDUINO_CORE) -I$(ARDUINO_LIB) -I$(PROJECT_DIR) -I$(ARDUINO_AVR) -I$(ARDUINO_LIB)/SPI -I../..
CXXINCS = -I$(ARDUINO_CORE) -I$(ARDUINO_LIB)
# Compiler flag to set the C Standard level.
# c89 - "ANSI" C
# gnu89 - c89 plus GCC extensions
# c99 - ISO C99 standard (not yet fully implemented)
# gnu99 - c99 plus GCC extensions
#CSTANDARD = -std=gnu99
CDEBUG = -g$(DEBUG)
#CWARN = -Wall -Wstrict-prototypes
CWARN = -Wall # show all warnings
#CWARN = -w # suppress all warnings
CMAP = -Wl,-Map,output.map
####CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CTUNING = -ffunction-sections -fdata-sections
CXXTUNING = -fno-exceptions -ffunction-sections -fdata-sections
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
MMCU = -mmcu=$(MCU)
CFLAGS = $(CDEBUG) -O$(OPT) $(CMAP) $(CWARN) $(CTUNING) $(MMCU) $(CDEFS) $(CINCS) $(CSTANDARD) $(CEXTRA)
CXXFLAGS = $(CDEBUG) -O$(OPT) $(CWARN) $(CXXTUNING) $(CDEFS) $(CINCS)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
LDFLAGS = -O$(OPT) -lm -Wl,--gc-sections
#LDFLAGS = -O$(OPT) -lm -Wl,-Map,output/$(PROJECT_NAME).map
# Programming support using avrdude. Settings and variables.
AVRDUDE_PORT = $(PORT)
AVRDUDE_WRITE_FLASH = -U flash:w:output/$(PROJECT_NAME).hex:i
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf \
-p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE)
# Program settings
CC = $(AVR_TOOLS_PATH)/avr-gcc
CXX = $(AVR_TOOLS_PATH)/avr-g++
LD = $(AVR_TOOLS_PATH)/avr-gcc
OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
AR = $(AVR_TOOLS_PATH)/avr-ar
SIZE = $(AVR_TOOLS_PATH)/avr-size
NM = $(AVR_TOOLS_PATH)/avr-nm
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
REMOVE = rm -f
MV = mv -f
# Define all object files.
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
OBJ_MODULES = $(C_MODULES:.c=.o) $(CXX_MODULES:.cpp=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = $(CFLAGS) -mmcu=$(MCU)
ALL_CXXFLAGS = $(CXXFLAGS) -mmcu=$(MCU)
ALL_ASFLAGS = -x assembler-with-cpp $(ASFLAGS) -mmcu=$(MCU)
ALL_LDFLAGS = $(LDFLAGS) -mmcu=$(MCU)
# Default target.
# This is th etarget that gets executed with a make command
# that has no parameters, ie "make".
all: applet_files build sym lss size upload
build: elf hex
output/$(PROJECT_NAME).cpp: $(PROJECT_NAME).pde
test -d output || mkdir output
echo "#include <WProgram.h>" > $@
echo "#line 1 \"$<\"" >> $@
cat $< >> $@
elf: output/$(PROJECT_NAME).elf
hex: output/$(PROJECT_NAME).hex
eep: output/$(PROJECT_NAME).eep
lss: output/$(PROJECT_NAME).lss
#sym: output/$(PROJECT_NAME).sym
# Upload HEX file to Arduino
upload: output/$(PROJECT_NAME).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT) $(AVRDUDE_WRITE_FLASH)
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT2) $(AVRDUDE_WRITE_FLASH)
sym:
$(NM) -n -C --format=posix output/$(PROJECT_NAME).elf > output/$(PROJECT_NAME).sym
# Display size of file.
size:
$(SIZE) output/$(PROJECT_NAME).elf
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: output/$(PROJECT_NAME).elf
$(COFFCONVERT) -O coff-avr output/$(PROJECT_NAME).elf $(PROJECT_NAME).cof
extcoff: $(PROJECT_NAME).elf
$(COFFCONVERT) -O coff-ext-avr output/$(PROJECT_NAME).elf $(PROJECT_NAME).cof
.SUFFIXES: .elf .hex .eep .lss .sym
.elf.hex:
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
.elf.eep:
$(OBJCOPY) -O $(FORMAT) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--no-change-warnings \
--change-section-lma .eeprom=0 $< $@
# Create extended listing file from ELF output file.
.elf.lss:
$(OBJDUMP) -h -S $< > $@
# Link: create ELF output file from library.
#output/$(PROJECT_NAME).elf: $(PROJECT_NAME).c output/core.a
output/$(PROJECT_NAME).elf: output/$(PROJECT_NAME).o output/core.a
$(LD) $(ALL_LDFLAGS) -o $@ output/$(PROJECT_NAME).o output/core.a
output/core.a: $(OBJ_MODULES)
@for i in $(OBJ_MODULES); do echo $(AR) rcs output/core.a $$i; $(AR) rcs output/core.a $$i; done
# Compile: create object files from C++ source files.
.cpp.o:
$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
# Compile: create object files from C source files.
.c.o:
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
.c.s:
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
.S.o:
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Automatic dependencies
%.d: %.c
$(CC) -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
%.d: %.cpp
$(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
# Target: clean project.
clean:
$(REMOVE) output/$(PROJECT_NAME).hex output/$(PROJECT_NAME).eep output/$(PROJECT_NAME).cof output/$(PROJECT_NAME).elf \
output/$(PROJECT_NAME).map output/$(PROJECT_NAME).sym output/$(PROJECT_NAME).lss output/core.a \
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
#.PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter
.PHONY: all build elf hex eep lss sym program coff extcoff applet_files sizebefore sizeafter
#include $(SRC:.c=.d)
#include $(CXXSRC:.cpp=.d)

View File

@ -18,7 +18,7 @@
#include "WProgram.h" #include "WProgram.h"
int serial_putc( char c, FILE *t ) int serial_putc( char c, FILE * )
{ {
Serial.write( c ); Serial.write( c );

206
examples/scanner/Jamfile Normal file
View File

@ -0,0 +1,206 @@
PROJECT_NAME = $(PWD:B) ;
PROJECT_DIR = . ;
PROJECT_LIBS = SPI RF24 ;
OUT_DIR = ojam ;
F_CPU = 16000000 ;
MCU = atmega328p ;
PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ;
UPLOAD_RATE = 57600 ;
AVRDUDE_PROTOCOL = stk500v1 ;
COM = 33 ;
# Host-specific overrides for locations
if $(OS) = MACOSX
{
ARDUINO_VERSION = 22 ;
OLD_DIR = /opt/arduino-0021 ;
AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ;
AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ;
ARDUINO_DIR = /opt/Arduino ;
ARDUINO_AVR = /usr/lib/avr/include ;
}
# Where is everything?
ARDUINO_VERSION ?= 22 ;
AVR_TOOLS_PATH ?= /usr/bin ;
ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ;
ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ;
AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ;
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ;
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ;
AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ;
AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ;
AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ;
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ;
DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
CTUNING = -ffunction-sections -fdata-sections ;
CXXTUNING = -fno-exceptions -fno-strict-aliasing ;
CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ;
CXXFLAGS = $(CFLAGS) $(CXXTUNING) ;
LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ;
# Search everywhere for headers
HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ;
# Grab everything from the core directory
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
# can specify specific modules to pick up in PROJECT_MODULES
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ;
# In addition to explicitly-specified program modules, pick up anything from the current
# dir.
PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ;
# Shortcut for the out files
OUT = $(OUT_DIR)/$(PROJECT_NAME) ;
# AvrDude setup
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ;
rule GitVersion
{
Always $(<) ;
Depends all : $(<) ;
}
actions GitVersion
{
echo "const char program_version[] = \"\\" > $(<)
git log -1 --pretty=format:%h >> $(<)
echo "\";" >> $(<)
}
GitVersion version.h ;
rule AvrCc
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}
actions AvrCc
{
$(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>)
}
rule AvrC++
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}
actions AvrC++
{
$(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>)
}
rule Pde
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
}
actions Pde
{
echo "#include <WProgram.h>" > $(<)
echo "#line 1 \"$(>)\"" >> $(<)
cat $(>) >> $(<)
}
rule AvrPde
{
local _CPP = $(OUT_DIR)/$(_I:B).cpp ;
Pde $(_CPP) : $(>) ;
AvrC++ $(<) : $(_CPP) ;
}
rule AvrObject
{
switch $(>:S)
{
case .c : AvrCc $(<) : $(>) ;
case .cpp : AvrC++ $(<) : $(>) ;
case .pde : AvrPde $(<) : $(>) ;
}
}
rule AvrObjects
{
for _I in $(<)
{
AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ;
}
}
rule AvrMainFromObjects
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
MkDir $(<:D) ;
Depends all : $(<) ;
Clean clean : $(<) ;
}
actions AvrMainFromObjects
{
$(AVR_LD) $(LDFLAGS) -o $(<) $(>)
}
rule AvrMain
{
AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ;
AvrObjects $(>) ;
}
rule AvrHex
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Depends hex : $(<) ;
Clean clean : $(<) ;
}
actions AvrHex
{
$(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<)
}
rule AvrUpload
{
Depends $(1) : $(2) ;
Depends $(2) : $(3) ;
NotFile $(1) ;
Always $(1) ;
Always $(2) ;
AvrUploadAction $(2) : $(3) ;
}
actions AvrUploadAction
{
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
}
AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
AvrHex $(OUT).hex : $(OUT).elf ;
AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ;
AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ;
AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ;

View File

@ -1,305 +0,0 @@
# Arduino Makefile
# Arduino adaptation by mellis, eighthave, oli.keller
# Modified by Kerry Wong to support NetBeans
# Modified by Rob Gray (Graynomad) for use with Windows and no IDE
# This works in my environment and I use it to program two different
# 328-based boards and a Mega2560. It's not necessarily robust and
# I may have broken something in the original file that I don't use.
#
# This makefile allows you to build sketches from the command line
# without the Arduino environment.
#
# Instructions for using the makefile:
#
# 1. Copy this file into the folder with your sketch. The project code file
# should have a .c extension however the file gets copied to a .cpp before
# compilation so you still write in C++.
#
# 2. Modify the lines between the double ### rows to set the paths
# comm ports etc for your system. EG. c:/progra~1/arduino/arduino-00
# for the Arduino IDE, Note the use of short folder name, don't use
# "Program files" because spaces will break the build.
#
# Set the line containing "MCU" to match your board's processor.
# Typically ATmega328 or ATmega2560. If you're using a LilyPad Arduino,
# change F_CPU to 8000000.
#
# 3. At the command line, change to the directory containing your
# program's file and the makefile.
#
# 4. Type "make" and press enter to compile/verify your program.
# The default make target will also perform the uplode using avrdude.
#
# The first time this is done all required libraries will be built
# and a core.a file will be created in the output folder.
#
# NOTES:
# All output goes into a folder called "output" underneath the working folder.
# The default all: target creates symbol (.sym) and expanded assembly
# (.lss) files and uploads the program.
#
#
##########################################################
##########################################################
# Select processor here
MCU = atmega328p
#MCU = atmega2560
ifeq ($(MCU),atmega2560)
UPLOAD_RATE = 115200
AVRDUDE_PROTOCOL = stk500v2
COM = 39
endif
ifeq ($(MCU),atmega328p)
UPLOAD_RATE = 57600
AVRDUDE_PROTOCOL = stk500v1
COM = 33
endif
UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
ARDUINO_VERSION = 21
ARDUINO_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = $(ARDUINO_DIR)/hardware/tools/avr/bin
AVRDUDECONFIG_PATH = $(ARDUINO_DIR)/hardware/tools/avr/etc
PORT = /dev/tty.usbserial-A600eHIs
PORT2 = /dev/tty.usbserial-A9007LmI
PORT3 = /dev/tty.usbserial-A40081RP
else
ARDUINO_VERSION = 22
ARDUINO_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = /usr/bin
AVRDUDECONFIG_PATH = $(ARDUINO_DIR)/hardware/tools
PORT = /dev/ttyUSB0
PORT2 = /dev/ttyUSB1
endif
# Temporary testing of github Arduino environment
OLD_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin
AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc
ARDUINO_DIR = /opt/Arduino
PROJECT_NAME = $(notdir $(PWD))
PROJECT_DIR = .
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
ARDUINO_AVR = $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr
ARDUINO_LIB = $(ARDUINO_DIR)/libraries
F_CPU = 16000000
##########################################################
##########################################################
# Note that if your program has dependencies other than those
# already listed below, you will need to add them accordingly.
C_MODULES = \
$(ARDUINO_CORE)/wiring_pulse.c \
$(ARDUINO_CORE)/wiring_analog.c \
$(ARDUINO_CORE)/pins_arduino.c \
$(ARDUINO_CORE)/wiring.c \
$(ARDUINO_CORE)/wiring_digital.c \
$(ARDUINO_CORE)/WInterrupts.c \
$(ARDUINO_CORE)/wiring_shift.c \
CXX_MODULES = \
$(ARDUINO_CORE)/Tone.cpp \
$(ARDUINO_CORE)/main.cpp \
$(ARDUINO_CORE)/WMath.cpp \
$(ARDUINO_CORE)/Print.cpp \
$(ARDUINO_CORE)/HardwareSerial.cpp \
$(ARDUINO_LIB)/SPI/SPI.cpp \
$(ARDUINO_LIB)/EEPROM/EEPROM.cpp \
../../RF24.cpp
CXX_APP = output/$(PROJECT_NAME).cpp
MODULES = $(C_MODULES) $(CXX_MODULES)
SRC = $(C_MODULES)
CXXSRC = $(CXX_MODULES) $(CXX_APP)
FORMAT = ihex
# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile
# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
#DEBUG = stabs
DEBUG =
OPT = s
# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(ARDUINO_VERSION)
CXXDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(ARDUINO_VERSION)
# Place -I options here
CINCS = -I$(ARDUINO_LIB)/EEPROM -I$(ARDUINO_CORE) -I$(ARDUINO_LIB) -I$(PROJECT_DIR) -I$(ARDUINO_AVR) -I$(ARDUINO_LIB)/SPI -I../..
CXXINCS = -I$(ARDUINO_CORE) -I$(ARDUINO_LIB)
# Compiler flag to set the C Standard level.
# c89 - "ANSI" C
# gnu89 - c89 plus GCC extensions
# c99 - ISO C99 standard (not yet fully implemented)
# gnu99 - c99 plus GCC extensions
#CSTANDARD = -std=gnu99
CDEBUG = -g$(DEBUG)
#CWARN = -Wall -Wstrict-prototypes
CWARN = -Wall # show all warnings
#CWARN = -w # suppress all warnings
CMAP = -Wl,-Map,output.map
####CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CTUNING = -ffunction-sections -fdata-sections
CXXTUNING = -fno-exceptions -ffunction-sections -fdata-sections
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
MMCU = -mmcu=$(MCU)
CFLAGS = $(CDEBUG) -O$(OPT) $(CMAP) $(CWARN) $(CTUNING) $(MMCU) $(CDEFS) $(CINCS) $(CSTANDARD) $(CEXTRA)
CXXFLAGS = $(CDEBUG) -O$(OPT) $(CWARN) $(CXXTUNING) $(CDEFS) $(CINCS)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
LDFLAGS = -O$(OPT) -lm -Wl,--gc-sections
#LDFLAGS = -O$(OPT) -lm -Wl,-Map,output/$(PROJECT_NAME).map
# Programming support using avrdude. Settings and variables.
AVRDUDE_PORT = $(PORT)
AVRDUDE_WRITE_FLASH = -U flash:w:output/$(PROJECT_NAME).hex:i
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf \
-p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE)
# Program settings
CC = $(AVR_TOOLS_PATH)/avr-gcc
CXX = $(AVR_TOOLS_PATH)/avr-g++
LD = $(AVR_TOOLS_PATH)/avr-gcc
OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
AR = $(AVR_TOOLS_PATH)/avr-ar
SIZE = $(AVR_TOOLS_PATH)/avr-size
NM = $(AVR_TOOLS_PATH)/avr-nm
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
REMOVE = rm -f
MV = mv -f
# Define all object files.
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
OBJ_MODULES = $(C_MODULES:.c=.o) $(CXX_MODULES:.cpp=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = $(CFLAGS) -mmcu=$(MCU)
ALL_CXXFLAGS = $(CXXFLAGS) -mmcu=$(MCU)
ALL_ASFLAGS = -x assembler-with-cpp $(ASFLAGS) -mmcu=$(MCU)
ALL_LDFLAGS = $(LDFLAGS) -mmcu=$(MCU)
# Default target.
# This is th etarget that gets executed with a make command
# that has no parameters, ie "make".
all: applet_files build sym lss size upload
build: elf hex
output/$(PROJECT_NAME).cpp: $(PROJECT_NAME).pde
test -d output || mkdir output
echo "#include <WProgram.h>" > $@
echo "#line 1 \"$<\"" >> $@
cat $< >> $@
elf: output/$(PROJECT_NAME).elf
hex: output/$(PROJECT_NAME).hex
eep: output/$(PROJECT_NAME).eep
lss: output/$(PROJECT_NAME).lss
#sym: output/$(PROJECT_NAME).sym
# Upload HEX file to Arduino
upload: upload1 upload2
upload1: output/$(PROJECT_NAME).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT) $(AVRDUDE_WRITE_FLASH)
upload2: output/$(PROJECT_NAME).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT2) $(AVRDUDE_WRITE_FLASH)
upload3: output/$(PROJECT_NAME).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT3) $(AVRDUDE_WRITE_FLASH)
sym:
$(NM) -n -C --format=posix output/$(PROJECT_NAME).elf > output/$(PROJECT_NAME).sym
# Display size of file.
size:
$(SIZE) output/$(PROJECT_NAME).elf
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: output/$(PROJECT_NAME).elf
$(COFFCONVERT) -O coff-avr output/$(PROJECT_NAME).elf $(PROJECT_NAME).cof
extcoff: $(PROJECT_NAME).elf
$(COFFCONVERT) -O coff-ext-avr output/$(PROJECT_NAME).elf $(PROJECT_NAME).cof
.SUFFIXES: .elf .hex .eep .lss .sym
.elf.hex:
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
.elf.eep:
$(OBJCOPY) -O $(FORMAT) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--no-change-warnings \
--change-section-lma .eeprom=0 $< $@
# Create extended listing file from ELF output file.
.elf.lss:
$(OBJDUMP) -h -S $< > $@
# Link: create ELF output file from library.
#output/$(PROJECT_NAME).elf: $(PROJECT_NAME).c output/core.a
output/$(PROJECT_NAME).elf: output/$(PROJECT_NAME).o output/core.a
$(LD) $(ALL_LDFLAGS) -o $@ output/$(PROJECT_NAME).o output/core.a
output/core.a: $(OBJ_MODULES)
@for i in $(OBJ_MODULES); do echo $(AR) rcs output/core.a $$i; $(AR) rcs output/core.a $$i; done
# Compile: create object files from C++ source files.
.cpp.o:
$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
# Compile: create object files from C source files.
.c.o:
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
.c.s:
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
.S.o:
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Automatic dependencies
%.d: %.c
$(CC) -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
%.d: %.cpp
$(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
# Target: clean project.
clean:
$(REMOVE) output/$(PROJECT_NAME).hex output/$(PROJECT_NAME).eep output/$(PROJECT_NAME).cof output/$(PROJECT_NAME).elf \
output/$(PROJECT_NAME).map output/$(PROJECT_NAME).sym output/$(PROJECT_NAME).lss output/core.a \
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
#.PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter
.PHONY: all build elf hex eep lss sym program coff extcoff applet_files sizebefore sizeafter
#include $(SRC:.c=.d)
#include $(CXXSRC:.cpp=.d)

View File

@ -18,7 +18,7 @@
#include "WProgram.h" #include "WProgram.h"
int serial_putc( char c, FILE *t ) int serial_putc( char c, FILE * )
{ {
Serial.write( c ); Serial.write( c );

206
examples/starping/Jamfile Normal file
View File

@ -0,0 +1,206 @@
PROJECT_NAME = $(PWD:B) ;
PROJECT_DIR = . ;
PROJECT_LIBS = EEPROM SPI RF24 ;
OUT_DIR = ojam ;
F_CPU = 16000000 ;
MCU = atmega328p ;
PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ;
UPLOAD_RATE = 57600 ;
AVRDUDE_PROTOCOL = stk500v1 ;
COM = 33 ;
# Host-specific overrides for locations
if $(OS) = MACOSX
{
ARDUINO_VERSION = 22 ;
OLD_DIR = /opt/arduino-0021 ;
AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ;
AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ;
ARDUINO_DIR = /opt/Arduino ;
ARDUINO_AVR = /usr/lib/avr/include ;
}
# Where is everything?
ARDUINO_VERSION ?= 22 ;
AVR_TOOLS_PATH ?= /usr/bin ;
ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ;
ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ;
AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ;
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ;
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ;
AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ;
AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ;
AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ;
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ;
DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
CTUNING = -ffunction-sections -fdata-sections ;
CXXTUNING = -fno-exceptions -fno-strict-aliasing ;
CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ;
CXXFLAGS = $(CFLAGS) $(CXXTUNING) ;
LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ;
# Search everywhere for headers
HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ;
# Grab everything from the core directory
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
# can specify specific modules to pick up in PROJECT_MODULES
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ;
# In addition to explicitly-specified program modules, pick up anything from the current
# dir.
PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ;
# Shortcut for the out files
OUT = $(OUT_DIR)/$(PROJECT_NAME) ;
# AvrDude setup
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ;
rule GitVersion
{
Always $(<) ;
Depends all : $(<) ;
}
actions GitVersion
{
echo "const char program_version[] = \"\\" > $(<)
git log -1 --pretty=format:%h >> $(<)
echo "\";" >> $(<)
}
GitVersion version.h ;
rule AvrCc
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}
actions AvrCc
{
$(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>)
}
rule AvrC++
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}
actions AvrC++
{
$(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>)
}
rule Pde
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Clean clean : $(<) ;
}
actions Pde
{
echo "#include <WProgram.h>" > $(<)
echo "#line 1 \"$(>)\"" >> $(<)
cat $(>) >> $(<)
}
rule AvrPde
{
local _CPP = $(OUT_DIR)/$(_I:B).cpp ;
Pde $(_CPP) : $(>) ;
AvrC++ $(<) : $(_CPP) ;
}
rule AvrObject
{
switch $(>:S)
{
case .c : AvrCc $(<) : $(>) ;
case .cpp : AvrC++ $(<) : $(>) ;
case .pde : AvrPde $(<) : $(>) ;
}
}
rule AvrObjects
{
for _I in $(<)
{
AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ;
}
}
rule AvrMainFromObjects
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
MkDir $(<:D) ;
Depends all : $(<) ;
Clean clean : $(<) ;
}
actions AvrMainFromObjects
{
$(AVR_LD) $(LDFLAGS) -o $(<) $(>)
}
rule AvrMain
{
AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ;
AvrObjects $(>) ;
}
rule AvrHex
{
Depends $(<) : $(>) ;
Depends $(<) : $(<:D) ;
Depends hex : $(<) ;
Clean clean : $(<) ;
}
actions AvrHex
{
$(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<)
}
rule AvrUpload
{
Depends $(1) : $(2) ;
Depends $(2) : $(3) ;
NotFile $(1) ;
Always $(1) ;
Always $(2) ;
AvrUploadAction $(2) : $(3) ;
}
actions AvrUploadAction
{
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
}
AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
AvrHex $(OUT).hex : $(OUT).elf ;
AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ;
AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ;
AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ;

View File

@ -1,295 +0,0 @@
# Arduino Makefile
# Arduino adaptation by mellis, eighthave, oli.keller
# Modified by Kerry Wong to support NetBeans
# Modified by Rob Gray (Graynomad) for use with Windows and no IDE
# This works in my environment and I use it to program two different
# 328-based boards and a Mega2560. It's not necessarily robust and
# I may have broken something in the original file that I don't use.
#
# This makefile allows you to build sketches from the command line
# without the Arduino environment.
#
# Instructions for using the makefile:
#
# 1. Copy this file into the folder with your sketch. The project code file
# should have a .c extension however the file gets copied to a .cpp before
# compilation so you still write in C++.
#
# 2. Modify the lines between the double ### rows to set the paths
# comm ports etc for your system. EG. c:/progra~1/arduino/arduino-00
# for the Arduino IDE, Note the use of short folder name, don't use
# "Program files" because spaces will break the build.
#
# Set the line containing "MCU" to match your board's processor.
# Typically ATmega328 or ATmega2560. If you're using a LilyPad Arduino,
# change F_CPU to 8000000.
#
# 3. At the command line, change to the directory containing your
# program's file and the makefile.
#
# 4. Type "make" and press enter to compile/verify your program.
# The default make target will also perform the uplode using avrdude.
#
# The first time this is done all required libraries will be built
# and a core.a file will be created in the output folder.
#
# NOTES:
# All output goes into a folder called "output" underneath the working folder.
# The default all: target creates symbol (.sym) and expanded assembly
# (.lss) files and uploads the program.
#
#
##########################################################
##########################################################
# Select processor here
MCU = atmega328p
#MCU = atmega2560
ifeq ($(MCU),atmega2560)
UPLOAD_RATE = 115200
AVRDUDE_PROTOCOL = stk500v2
COM = 39
endif
ifeq ($(MCU),atmega328p)
UPLOAD_RATE = 57600
AVRDUDE_PROTOCOL = stk500v1
COM = 33
endif
UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
ARDUINO_VERSION = 21
ARDUINO_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = $(ARDUINO_DIR)/hardware/tools/avr/bin
AVRDUDECONFIG_PATH = $(ARDUINO_DIR)/hardware/tools/avr/etc
PORT = /dev/tty.usbserial-A600eHIs
PORT2 = /dev/tty.usbserial-A9007LmI
else
ARDUINO_VERSION = 22
ARDUINO_DIR = /opt/arduino-00$(ARDUINO_VERSION)
AVR_TOOLS_PATH = /usr/bin
AVRDUDECONFIG_PATH = $(ARDUINO_DIR)/hardware/tools
PORT = /dev/ttyUSB0
PORT2 = /dev/ttyUSB1
endif
PROJECT_NAME = $(notdir $(PWD))
PROJECT_DIR = .
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
ARDUINO_AVR = $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr
ARDUINO_LIB = $(ARDUINO_DIR)/libraries
F_CPU = 16000000
##########################################################
##########################################################
# Note that if your program has dependencies other than those
# already listed below, you will need to add them accordingly.
C_MODULES = \
$(ARDUINO_CORE)/wiring_pulse.c \
$(ARDUINO_CORE)/wiring_analog.c \
$(ARDUINO_CORE)/pins_arduino.c \
$(ARDUINO_CORE)/wiring.c \
$(ARDUINO_CORE)/wiring_digital.c \
$(ARDUINO_CORE)/WInterrupts.c \
$(ARDUINO_CORE)/wiring_shift.c \
CXX_MODULES = \
$(ARDUINO_CORE)/Tone.cpp \
$(ARDUINO_CORE)/main.cpp \
$(ARDUINO_CORE)/WMath.cpp \
$(ARDUINO_CORE)/Print.cpp \
$(ARDUINO_CORE)/HardwareSerial.cpp \
$(ARDUINO_LIB)/SPI/SPI.cpp \
$(ARDUINO_LIB)/EEPROM/EEPROM.cpp \
../../RF24.cpp
CXX_APP = output/$(PROJECT_NAME).cpp
MODULES = $(C_MODULES) $(CXX_MODULES)
SRC = $(C_MODULES)
CXXSRC = $(CXX_MODULES) $(CXX_APP)
FORMAT = ihex
# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile
# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
#DEBUG = stabs
DEBUG =
OPT = s
# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(ARDUINO_VERSION)
CXXDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(ARDUINO_VERSION)
# Place -I options here
CINCS = -I$(ARDUINO_LIB)/EEPROM -I$(ARDUINO_CORE) -I$(ARDUINO_LIB) -I$(PROJECT_DIR) -I$(ARDUINO_AVR) -I$(ARDUINO_LIB)/SPI -I../..
CXXINCS = -I$(ARDUINO_CORE) -I$(ARDUINO_LIB)
# Compiler flag to set the C Standard level.
# c89 - "ANSI" C
# gnu89 - c89 plus GCC extensions
# c99 - ISO C99 standard (not yet fully implemented)
# gnu99 - c99 plus GCC extensions
#CSTANDARD = -std=gnu99
CDEBUG = -g$(DEBUG)
#CWARN = -Wall -Wstrict-prototypes
CWARN = -Wall # show all warnings
#CWARN = -w # suppress all warnings
CMAP = -Wl,-Map,output.map
####CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CTUNING = -ffunction-sections -fdata-sections
CXXTUNING = -fno-exceptions -ffunction-sections -fdata-sections
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
MMCU = -mmcu=$(MCU)
CFLAGS = $(CDEBUG) -O$(OPT) $(CMAP) $(CWARN) $(CTUNING) $(MMCU) $(CDEFS) $(CINCS) $(CSTANDARD) $(CEXTRA)
CXXFLAGS = $(CDEBUG) -O$(OPT) $(CWARN) $(CXXTUNING) $(CDEFS) $(CINCS)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
LDFLAGS = -O$(OPT) -lm -Wl,--gc-sections
#LDFLAGS = -O$(OPT) -lm -Wl,-Map,output/$(PROJECT_NAME).map
# Programming support using avrdude. Settings and variables.
AVRDUDE_PORT = $(PORT)
AVRDUDE_WRITE_FLASH = -U flash:w:output/$(PROJECT_NAME).hex:i
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf \
-p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE)
# Program settings
CC = $(AVR_TOOLS_PATH)/avr-gcc
CXX = $(AVR_TOOLS_PATH)/avr-g++
LD = $(AVR_TOOLS_PATH)/avr-gcc
OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
AR = $(AVR_TOOLS_PATH)/avr-ar
SIZE = $(AVR_TOOLS_PATH)/avr-size
NM = $(AVR_TOOLS_PATH)/avr-nm
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
REMOVE = rm -f
MV = mv -f
# Define all object files.
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
OBJ_MODULES = $(C_MODULES:.c=.o) $(CXX_MODULES:.cpp=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = $(CFLAGS) -mmcu=$(MCU)
ALL_CXXFLAGS = $(CXXFLAGS) -mmcu=$(MCU)
ALL_ASFLAGS = -x assembler-with-cpp $(ASFLAGS) -mmcu=$(MCU)
ALL_LDFLAGS = $(LDFLAGS) -mmcu=$(MCU)
# Default target.
# This is th etarget that gets executed with a make command
# that has no parameters, ie "make".
all: applet_files build sym lss size upload
build: elf hex
output/$(PROJECT_NAME).cpp: $(PROJECT_NAME).pde
test -d output || mkdir output
echo "#include <WProgram.h>" > $@
echo "#line 1 \"$<\"" >> $@
cat $< >> $@
elf: output/$(PROJECT_NAME).elf
hex: output/$(PROJECT_NAME).hex
eep: output/$(PROJECT_NAME).eep
lss: output/$(PROJECT_NAME).lss
#sym: output/$(PROJECT_NAME).sym
# Upload HEX file to Arduino
upload: upload1 upload2
upload1: output/$(PROJECT_NAME).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT) $(AVRDUDE_WRITE_FLASH)
upload2: output/$(PROJECT_NAME).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(PORT2) $(AVRDUDE_WRITE_FLASH)
sym:
$(NM) -n -C --format=posix output/$(PROJECT_NAME).elf > output/$(PROJECT_NAME).sym
# Display size of file.
size:
$(SIZE) output/$(PROJECT_NAME).elf
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: output/$(PROJECT_NAME).elf
$(COFFCONVERT) -O coff-avr output/$(PROJECT_NAME).elf $(PROJECT_NAME).cof
extcoff: $(PROJECT_NAME).elf
$(COFFCONVERT) -O coff-ext-avr output/$(PROJECT_NAME).elf $(PROJECT_NAME).cof
.SUFFIXES: .elf .hex .eep .lss .sym
.elf.hex:
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
.elf.eep:
$(OBJCOPY) -O $(FORMAT) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--no-change-warnings \
--change-section-lma .eeprom=0 $< $@
# Create extended listing file from ELF output file.
.elf.lss:
$(OBJDUMP) -h -S $< > $@
# Link: create ELF output file from library.
#output/$(PROJECT_NAME).elf: $(PROJECT_NAME).c output/core.a
output/$(PROJECT_NAME).elf: output/$(PROJECT_NAME).o output/core.a
$(LD) $(ALL_LDFLAGS) -o $@ output/$(PROJECT_NAME).o output/core.a
output/core.a: $(OBJ_MODULES)
@for i in $(OBJ_MODULES); do echo $(AR) rcs output/core.a $$i; $(AR) rcs output/core.a $$i; done
# Compile: create object files from C++ source files.
.cpp.o:
$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
# Compile: create object files from C source files.
.c.o:
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
.c.s:
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
.S.o:
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Automatic dependencies
%.d: %.c
$(CC) -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
%.d: %.cpp
$(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
# Target: clean project.
clean:
$(REMOVE) output/$(PROJECT_NAME).hex output/$(PROJECT_NAME).eep output/$(PROJECT_NAME).cof output/$(PROJECT_NAME).elf \
output/$(PROJECT_NAME).map output/$(PROJECT_NAME).sym output/$(PROJECT_NAME).lss output/core.a \
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
#.PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter
.PHONY: all build elf hex eep lss sym program coff extcoff applet_files sizebefore sizeafter
#include $(SRC:.c=.d)
#include $(CXXSRC:.cpp=.d)

View File

@ -18,7 +18,7 @@
#include "WProgram.h" #include "WProgram.h"
int serial_putc( char c, FILE *t ) int serial_putc( char c, FILE * )
{ {
Serial.write( c ); Serial.write( c );