Go Down

Topic: Arduino on Xcode Project — Official Thread (Read 153 times) previous topic - next topic


Good news, using the Makefile supplied by avenue33 I've successfully uploaded the Blink script to my Uno!

Xcode4 still won't acknowledge the existence of the template, but I guess that's just an afternoon of manual-digging. I'll post here when I have anything more to report.

Cheers, Robert.


Hi Robert,

On Xcode 3.2.5, I select File > New Project and then a window pops-up with the following options:

Choose Other > ArduinoOnXcode.

I don't know how it runs on Xcode 4 but I guess it's similar.

I still don't manage to get my own libraries compiled, as Example-4 attached in a previous post. There's no problem with standard Arduino libraries.

Nice to hear from your progress  ;)


Nov 04, 2011, 06:48 pm Last Edit: Nov 04, 2011, 10:21 pm by avenue33 Reason: 1

Please find on this GitHub repository a Xcode project for Arduino UNO.

  • Xcode 4 on Mac OS X.7

  • MPIDE 0022 based on Arduino IDE 0022

I tested it successfully with the Arduino UNO and the chipKIT UNO32 platforms.

The Xcode 3 template is no longer valid because Xcode 4 has changed everything about the templates.

More details on my website.

I'd greatly appreciate some help on Xcode 4 about templates and libraries linking.


Nov 12, 2011, 02:11 am Last Edit: Nov 12, 2011, 01:07 pm by timKnapen Reason: 1

I have been struggling to get Arduino to work with XCode for the longest time.
Finally, it is working. even with libraries ( but for some reason not the SD library... I'm not really sure why. )

I have been recycling makefiles that other people posted on the web, but none that I found could make libraries link correctly or even include extra .cpp files in my project's src folder.
So I have been adjusting and changing makefiles so many times I have no clue where my original source came from :-s

Here is the makefile that I'm using now for working with a Makerbot Sanguino based board:

Code: [Select]

ARDUINO = /Applications/Arduino.app/Contents/Resources/Java/hardware/Sanguino/cores/arduino
LIBRARIES = /Applications/Arduino.app/Contents/Resources/Java/libraries
AVRDUDE_DIR = /usr/local/CrossPack-AVR/bin
SIZE = $(AVRDUDE_DIR)/avr-size
SOURCES = $(wildcard src/*.cpp)

#loading libraries
CPP_LIBRARIES = $(wildcard $(STEPPER)/*.cpp) $(wildcard $(SERVO)/*.cpp) \
$(wildcard $(EEPROM)/*.cpp)

PORT = /dev/tty.usbserial*
TARGET = main
SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
$(ARDUINO)/wiring_pulse.c \
$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp $(ARDUINO)/Print.cpp \
MCU = atmega644p
F_CPU = 16000000
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

OPT = s

# Place -D or -U options here

# Place -I options here : include libraries

# 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
CWARN = -Wall -Wstrict-prototypes
CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -Wl,-gc-sections

LDFLAGS = -lm -Wl,-gc-sections -mmcu=$(MCU)

# Programming support using avrdude. Settings and variables.
AVRDUDE_WRITE_FLASH = -U flash:w:bin/$(TARGET).hex

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

# Define all object files.
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.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 = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)

# Default target.
all: sizebefore clean build  sizeafter

build: info folder elf hex

elf: bin/$(TARGET).elf
hex: bin/$(TARGET).hex
eep: bin/$(TARGET).eep
lss: bin/$(TARGET).lss
sym: bin/$(TARGET).sym

# print info
@echo "compiling sources: " $(SOURCES);
@echo "compiling libraries sources: " $(CPP_LIBRARIES);
@echo "----------";

# create the bin folder if it doesn't exist
mkdir -p bin

# Program the device.  
upload: bin/$(TARGET).hex

# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) bin/$(TARGET).hex
ELFSIZE = $(SIZE)  bin/$(TARGET).elf
@echo "size before: ";
@if [ -f bin/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi

@echo "size after:";
@if [ -f bin/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi

# 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: bin/$(TARGET).elf
$(COFFCONVERT) -O coff-avr bin/$(TARGET).elf $(TARGET).cof

extcoff: $(TARGET).elf
$(COFFCONVERT) -O coff-ext-avr bin/$(TARGET).elf $(TARGET).cof

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

$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@

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

# Create extended listing file from ELF output file.
$(OBJDUMP) -h -S $< > $@

# Create a symbol table from ELF output file.
$(NM) -n $< > $@

bin/core.a: $(OBJ)
@for i in $(OBJ); do echo $(AR) rcs bin/core.a $$i; $(AR) rcs bin/core.a $$i; done

# Link: create ELF output file from library.
bin/$(TARGET).elf: bin/core.a
$(CC) $(ALL_CFLAGS) -o $@ src/$(TARGET).cpp -L. bin/core.a $(LDFLAGS)

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

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

# Compile: create assembler files from C source files.
$(CC) -S $(ALL_CFLAGS) $< -o $@

# Assemble: create object files from assembler source files.
$(CC) -c $(ALL_ASFLAGS) $< -o $@

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

if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
then \
sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
$(MAKEFILE).$$$$ && \
$(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
>> $(MAKEFILE); \
$(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)

.PHONY: all build elf hex eep lss sym program coff extcoff clean depend

I'm using this with XCode 3.2, I have attached a zip file of a working sample project.

hope this helps someone, I for one got a little bit balder trying to get this to work :-)



I have create a project on Github where I've put the XCode project templates:

With a little help from people who know about makefiles and compilers, I'm sure we can get decent XCode support for Arduino.


Go Up