summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-09-08 13:49:41 +0200
committerKarel Kočí <cynerd@email.cz>2018-09-08 13:49:41 +0200
commit1107e66c889cc62e9e7381853134448feac6e18c (patch)
tree9d51975b4596e335221a4a67abd0a98854a2dd94
parentb5c736aa4dd34b195fe730f76274728c058c0b9f (diff)
downloadhwelekit-1107e66c889cc62e9e7381853134448feac6e18c.tar.gz
hwelekit-1107e66c889cc62e9e7381853134448feac6e18c.tar.bz2
hwelekit-1107e66c889cc62e9e7381853134448feac6e18c.zip
dice: add template for firmware
-rw-r--r--dice/firmware/Makefile49
-rw-r--r--dice/firmware/main.c13
2 files changed, 62 insertions, 0 deletions
diff --git a/dice/firmware/Makefile b/dice/firmware/Makefile
new file mode 100644
index 0000000..80cffce
--- /dev/null
+++ b/dice/firmware/Makefile
@@ -0,0 +1,49 @@
+MAKEFLAGS += --no-builtin-rules --no-builtin-variables
+
+# This variable can be overwritten to show executed commands
+Q ?= @
+
+# TODO use CC instead of GCC but at the moment --no-builtin-variables seems to
+# break somehow detection of not defined variable.
+TARGET ?= avr-
+GCC ?= $(TARGET)gcc
+OBJCOPY ?= $(TARGET)objcopy
+AVRDUDE ?= avrdude
+
+MCU ?= attiny85
+F_CPU ?= 16000000L
+CFLAGS ?= -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU)
+LDFLAGS ?= -Os -mmcu=$(MCU)
+
+#####################
+SRC := main.c
+#####################
+OBJ := $(patsubst %.c,%.o,$(SRC))
+
+.PHONY: all
+all: firmware.hex
+
+$(OBJ): %.o: %.c
+ @echo "CC $@"
+ $(Q)$(GCC) -c $(CFLAGS) $< -o $@
+
+firmware.elf: $(OBJ)
+ @echo "LD $@"
+ $(Q)$(GCC) $(LDFLAGS) $< -o $@
+
+firmware.hex: firmware.elf
+ @echo "OBJCOPY $@"
+ $(Q)$(OBJCOPY) -O ihex -R .eeprom $< $@
+
+
+.PHONY: install
+install: firmware.hex
+ @echo "AVRDUDE $@"
+ $(Q)$(AVRDUDE) -p$(MCU) -cusbasp -D -Uflash:w:$<:a
+
+# TODO probably configure fuses
+
+.PHONY: clean
+clean:
+ rm -f $(OBJ)
+ rm -f firmware.elf firmware.hex
diff --git a/dice/firmware/main.c b/dice/firmware/main.c
new file mode 100644
index 0000000..6b6f6f8
--- /dev/null
+++ b/dice/firmware/main.c
@@ -0,0 +1,13 @@
+#include <avr/io.h>
+#include <util/delay.h>
+
+int main() {
+ DDRB |= _BV(DDB3);
+
+ while (1) {
+ PORTB |= _BV(PORTB3);
+ _delay_ms(500);
+ PORTB &= ~_BV(PORTB3);
+ _delay_ms(500);
+ }
+}