summaryrefslogtreecommitdiffstats
path: root/_blog/arduino-uno/3v3.Makefile
diff options
context:
space:
mode:
Diffstat (limited to '_blog/arduino-uno/3v3.Makefile')
-rw-r--r--_blog/arduino-uno/3v3.Makefile46
1 files changed, 46 insertions, 0 deletions
diff --git a/_blog/arduino-uno/3v3.Makefile b/_blog/arduino-uno/3v3.Makefile
new file mode 100644
index 0000000..4ca89d4
--- /dev/null
+++ b/_blog/arduino-uno/3v3.Makefile
@@ -0,0 +1,46 @@
+CC = avr-gcc
+MCU = atmega328p
+PORT = /dev/cuaU0
+TARGET = app
+
+SRC = main.c
+OBJ = $(SRC:.c=.o)
+
+CFLAGS = -std=gnu99
+CFLAGS += -Os
+CFLAGS += -Wall
+CFLAGS += -mmcu=$(MCU)
+CFLAGS += -DBAUD=57600
+CFLAGS += -DF_CPU=8000000UL
+CFLAGS += -ffunction-sections -fdata-sections
+
+LDFLAGS = -mmcu=$(MCU)
+LDFLAGS += -Wl,--gc-sections
+
+HEX_FLAGS = -O ihex
+HEX_FLAGS += -j .text -j .data
+
+AVRDUDE_FLAGS = -p $(MCU)
+AVRDUDE_FLAGS += -c arduino
+AVRDUDE_FLAGS += -b 57600
+AVRDUDE_FLAGS += -P $(PORT)
+AVRDUDE_FLAGS += -D -U
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+elf: $(OBJ)
+ $(CC) $(LDFLAGS) $(OBJ) -o $(TARGET).elf
+
+hex: elf
+ avr-objcopy $(HEX_FLAGS) $(TARGET).elf $(TARGET).hex
+
+upload: hex
+ avrdude $(AVRDUDE_FLAGS) flash:w:$(TARGET).hex:i
+
+.PHONY: clean
+
+clean:
+ rm -f *.o *.elf *.hex
+
+