Arduino bez Arduino IDEa

Nije bas bez IDEa, ali korišćenjem regularnog editora (u mom slučaju vima) i make-a, a IDE morate da instalirate zbog svih ostalih fajlova i dependinga.

Makefile:

AVR_GPP = avr-g++
AVR_GCC = avr-gcc
AVR_OBJCOPY = avr-objcopy
ARDUINODIR = /usr/share/arduino
LIBRARY = $(ARDUINODIR)/libraries
COREDIR = $(ARDUINODIR)/hardware/arduino/cores/arduino

SERIALPORT=/dev/ttyUSB0

ARDUINODIR = /usr/share/arduino

CFLAGS = -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100

LIBS =
#LIBS += $(LIBRARY)/EEPROM/EEPROM.cpp
#LIBS += $(LIBRARY)/Ethernet/Dhcp.cpp
#LIBS += $(LIBRARY)/Ethernet/Dns.cpp
#LIBS += $(LIBRARY)/Ethernet/EthernetClient.cpp
#LIBS += $(LIBRARY)/Ethernet/Ethernet.cpp
#LIBS += $(LIBRARY)/Ethernet/EthernetServer.cpp
#LIBS += $(LIBRARY)/Ethernet/EthernetUdp.cpp
#LIBS += $(LIBRARY)/Firmata/Firmata.cpp
LIBS += $(LIBRARY)/LiquidCrystal/LiquidCrystal.cpp
#LIBS += $(LIBRARY)/SD/File.cpp
#LIBS += $(LIBRARY)/SD/SD.cpp
#LIBS += $(LIBRARY)/Servo/Servo.cpp
#LIBS += $(LIBRARY)/SoftwareSerial/SoftwareSerial.cpp
#LIBS += $(LIBRARY)/SPI/SPI.cpp
#LIBS += $(LIBRARY)/Stepper/Stepper.cpp
LIBS += $(LIBRARY)/Wire/Wire.cpp
LIBS += $(LIBRARY)/Wire/utility/twi.c
LIBS += Timer/Timer.cpp
LIBS += Timer/Event.cpp
LIBS += OneWire/OneWire.cpp

#LIBS += LiquidCrystal/LiquidCrystal.cpp

OUTFILE = lcd1
SRCFILES = lcd1.cpp

CFLAGS += -I$(COREDIR)
CFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/standard
CFLAGS += $(foreach l,$(LIBS), -I$(shell dirname $(l)))

LDFLAGS = -lm

COREFILES = wiring_pulse.c wiring.c wiring_shift.c WInterrupts.c wiring_digital.c wiring_analog.c USBCore.cpp IPAddress.cpp Stream.cpp main.cpp HardwareSerial.cpp Print.cpp WMath.cpp Tone.cpp CDC.cpp new.cpp HID.cpp WString.cpp

OBJS = 

define BUILD
$(1): $(2)
ifeq ($(suffix $(2)),.c)
	$$(AVR_GCC) -c $$(CFLAGS) -o $$@ $$^
else
	$$(AVR_GPP) -c $$(CFLAGS) -o $$@ $$^
endif

OBJS += $(1)
endef

$(foreach l,$(LIBS),$(eval $(call BUILD,core/$(shell basename $(l)).o,$(l))))

$(foreach l,$(COREFILES),$(eval $(call BUILD,core/$(shell basename $(l)).o,$(COREDIR)/$(l))))

$(foreach l,$(SRCFILES),$(eval $(call BUILD,$(l).o,$(l))))

.PHONY: all
.DEFAULT:

all: $(OUTFILE).elf $(OUTFILE).eep $(OUTFILE).hex

$(OUTFILE).elf: $(OBJS)
	$(AVR_GCC) -Os -Wl,--gc-sections -mmcu=atmega328p -o $@ $^ $(LDFLAGS)

$(OUTFILE).eep: $(OUTFILE).elf
	$(AVR_OBJCOPY) -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $^ $@

$(OUTFILE).hex: $(OUTFILE).elf
	$(AVR_OBJCOPY) -O ihex -R .eeprom $^ $@

.PHONY: clean

clean:
	rm -f *.o  *.epp *.elf *.hex

distclean:
	rm -f core/*.o

flash: $(OUTFILE).hex
	$(ARDUINODIR)/hardware/tools/avrdude -C$(ARDUINODIR)/hardware/tools/avrdude.conf -v -patmega328p -carduino -P$(SERIALPORT) -b57600 -D -Uflash:w:$(OUTFILE).hex:i

Treba promeniti OUTFILE i SRCFILES (naši sourcevi), kao i u linijama sa LIBS enablovati sistemske i lokalne biblioteke.

I u source (osim što nije .pde ekstenzija) treba dodati

#include <Arduino.h>

Kompajliranje:

make all

flashovanje

make flash

Napomena: parametri u fajlu su za atmega328p 16Mhz baziranim arduinom.

dl: Makefile

This entry was posted in elektronika, linux and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *