Show Posts
Pages: [1]
1  Using Arduino / Interfacing w/ Software on the Computer / Re: command line development in linux on: January 24, 2013, 10:27:38 pm
Here's my Makefile. Well, not quite. I took a Makefile here (http://playground.arduino.cc/uploads/Learning/Makefile) but I didn't work for me. So I made the necessary adjustments. Your code will have to have the following "extras":

1)
include "Arduino.h"
include "Servo.c" // or any other library

2) function prototypes for all functions in your program.

Example:

Code:
#include "Arduino.h"
void setup();
void loop();

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
}

Code:
PREFIX = PATH_TO_YOUR_ARDUINO_IDE_DIR
PORT = /dev/ttyACM0
# your program name minus the .cpp extension.
TARGET = YOUR_PROGRAM_NAME
ARDUINO = $(PREFIX)/hardware/arduino/cores/arduino
ARDUINO_LIBS = $(PREFIX)/libraries
ARDUINO_INCL = $(PREFIX)/hardware/arduino/variants/standard $(wildcard $(ARDUINO_LIBS)/*)
ARDUINO_BIN = $PREFIX/hardware/tools/avr/bin
ARDUINO_TOOLS = $PREFIX/hardware/tools

VPATH=$(ARDUINO)

SRC = $(wildcard $(ARDUINO)/*.c)

# I had to include the Servo.cpp explicitly. If you use another library in addition, mention it here as well.
CXXSRC = $(TARGET).cpp $(wildcard $(ARDUINO)/*.cpp) $(ARDUINO_LIBS)/Servo/Servo.cpp

MCU = atmega328p
F_CPU = 16000000
FORMAT = ihex
UPLOAD_RATE = 19200

# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)
CXXDEFS = -DF_CPU=$(F_CPU)

# Place -I options here
CINCS = -I$(ARDUINO) $(foreach d, $(ARDUINO_INCL), -I$d)
CXXINCS = -I$(ARDUINO) $(foreach d, $(ARDUINO_INCL), -I$d)

CSTANDARD =
CDEBUG = -g$(DEBUG)
CWARN = -Wall
CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CEXTRA = -Os -ffunction-sections -fdata-sections
CXXEXTRA = -Os -fno-exceptions -ffunction-sections -fdata-sections

CFLAGS = $(CDEFS) $(CINCS) -Os $(CWARN) $(CSTANDARD) $(CEXTRA)
CXXFLAGS = $(CDEFS) $(CINCS) $(CXXEXTRA)

# Programming support using avrdude. Settings and variables.
AVRDUDE_PROGRAMMER = arduino
AVRDUDE_PORT = $(PORT)
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex:i
AVRDUDE_FLAGS = -p$(MCU) -P$(AVRDUDE_PORT) -c$(AVRDUDE_PROGRAMMER) -b $(UPLOAD_RATE) -D $(AVRDUDE_WRITE_FLASH)

# Program settings
CC = $(ARDUINO_BIN)/avr-gcc
CXX = $(ARDUINO_BIN)/avr-g++
OBJCOPY = $(ARDUINO_BIN)/avr-objcopy
OBJDUMP = $(ARDUINO_BIN)/avr-objdump
SIZE = $(ARDUINO_BIN)/avr-size
NM = $(ARDUINO_BIN)/avr-nm
AVRDUDE = $(ARDUINO_TOOLS)/avrdude
REMOVE = rm -f
MV = mv -f

# Define all object files.
OBJ = $(SRC:.c=.c.o) $(CXXSRC:.cpp=.cpp.o) $(ASRC:.S=.o)

# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)

# Default target. Remove core.a before doing anything.
all: remove_core build

build: elf hex eep

elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep

#$(AVRDUDE) -C$(ARDUINO_TOOLS)/avrdude.conf $(AVRDUDE_FLAGS)
# Program the device. 
upload: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) -C$(ARDUINO_TOOLS)/avrdude.conf -patmega328p -carduino -P/dev/ttyACM0 -b115200 -D -Uflash:w:$(TARGET).hex:i

.SUFFIXES: .elf .hex .eep .lss .sym

.elf.hex:
$(OBJCOPY) -O $(FORMAT) -R .eeprom $(TARGET).elf $(TARGET).hex

.elf.eep:
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 -O $(FORMAT) $< $@

core: $(OBJ)
$(ARDUINO_BIN)/avr-ar rcs core.a $?

# Link: create ELF output file from object files.
$(TARGET).elf: core
$(CC) -Os -Wl,--gc-sections -mmcu=$(MCU) -o $(TARGET).elf core.a -lm

# Compile: create object files from C++ source files.
%.cpp.o: %.cpp
$(CXX) -c $(ALL_CFLAGS) $< -o $@

# Compile: create object files from C source files.
%.c.o: %.c
$(CC) -c $(ALL_CXXFLAGS) $< -o $@

# Target: clean project.
clean:
$(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) \
core.a

remove_core:
$(REMOVE) core.a

.PHONY: all build elf hex eep lss sym program clean remove_core
2  Using Arduino / Interfacing w/ Software on the Computer / Re: command line development in linux on: January 23, 2013, 09:43:56 am
Will post tonight -- it's at home.

Quote
Does it support the sam architecture (as used with the Due boards) ?

If the IDE can do it, you can probably modify the Makefile to do it as well. I know nothing about the Due board though.

Back later...
3  Using Arduino / Interfacing w/ Software on the Computer / Re: command line development in linux on: January 22, 2013, 03:12:35 pm
Very nice. Thanks for the post. I meanwhile created a Makefile for this myself. Which was a nice learning experience in itself. But I'm glad it's standard now. Thanks!!!

If anybody is interested in the Makefile, let me know.
4  Using Arduino / Interfacing w/ Software on the Computer / Re: command line development in linux on: January 09, 2013, 11:52:54 am
That's so cool, thanks!

So, I could replace the parts that are variable in those commands and create a script? Hasn't somebody done it already? I just specify the port and voila?
5  Using Arduino / Interfacing w/ Software on the Computer / command line development in linux on: January 09, 2013, 11:42:16 am
Hi,

I was just wondering if there's a list of commands somewhere that the IDE runs when uploading a program to the board. It would be great to automate all that from the command line. It would be cool if the IDE printed what it was executing in some window.

Thanks for any ideas.
Pages: [1]