From cf36849b988ec87d86d01c59e77761f33506f8eb Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Mon, 11 May 2015 14:13:50 +0200
Subject: [PATCH] Make fuses programmable with avrdude.

---
 lib/avr/Makefile.common           | 11 ++++++++++-
 linear_pendulum_2009/avr/Makefile |  6 ++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/lib/avr/Makefile.common b/lib/avr/Makefile.common
index aa15db4..cc9828b 100644
--- a/lib/avr/Makefile.common
+++ b/lib/avr/Makefile.common
@@ -68,6 +68,15 @@ OBJECTS=$($(1).C:%=compiled/$(1)/%.o)
 	        -U flash:w:compiled/$(TARGET)/$*.sr:s
 
 %.FUSE:
+	[ -n "$($(TARGET).FUSE_L)" ] && avrdude -P usb -c avrisp2 -p $(CHIP) \
+	        -U lfuse:w:$($(TARGET).FUSE_L):m || true
+	[ -n "$($(TARGET).FUSE_H)" ] && avrdude -P usb -c avrisp2 -p $(CHIP) \
+	        -U hfuse:w:$($(TARGET).FUSE_H):m || true
+	[ -n "$($(TARGET).FUSE_E)" ] && avrdude -P usb -c avrisp2 -p $(CHIP) \
+	        -U efuse:w:$($(TARGET).FUSE_E):m || true
+
+%.FUSE_uisp:
+	exit 1
 	uisp \
 		-dprog=stk200 \
 		$($(TARGET).FUSE)
@@ -85,4 +94,4 @@ compiled/$(TARGET)/%.sr: compiled/$(TARGET)/%.exe
 	   compiled/$(TARGET)/%.exe \
 	   compiled/$(TARGET)/%.sr
 
-endif
\ No newline at end of file
+endif
diff --git a/linear_pendulum_2009/avr/Makefile b/linear_pendulum_2009/avr/Makefile
index dc03524..8367fac 100644
--- a/linear_pendulum_2009/avr/Makefile
+++ b/linear_pendulum_2009/avr/Makefile
@@ -3,13 +3,15 @@ TARGETS=current_control vel_control
 current_control.ARCH=avr
 current_control.CHIP=atmega16
 # 14.7456 MHz crystal, brown out
-current_control.FUSE=--wr_fuse_l=0x1f --wr_fuse_h=0xd9 --wr_fuse_e=0xff
+vel_control.FUSE_L=0x1f
+vel_control.FUSE_H=0xd9
 current_control.C=current_control
 
 vel_control.ARCH=avr
 vel_control.CHIP=atmega16
 # 14.7456 MHz crystal, brown out
-vel_control.FUSE=--wr_fuse_l=0x1f --wr_fuse_h=0xd9 --wr_fuse_e=0xff
+vel_control.FUSE_L=0x1f
+vel_control.FUSE_H=0xd9
 vel_control.C=vel_control 
 vel_control.H=serialio_core
 
-- 
GitLab