add micro-controller source code with simple Makefile

This commit is contained in:
King Kévin 2013-10-12 17:02:42 +02:00
parent 6fcb31eabc
commit b6ae0df544
1 changed files with 79 additions and 0 deletions

79
src/Makefile Normal file
View File

@ -0,0 +1,79 @@
# required packages
# sudo aptitude install avrdude gcc-avr avr-libc
# the program
PROG=led-controller
# to compile
CC=avr-gcc
OBJDUMP=avr-objdump
OBJCOPY=avr-objcopy
CFLAGS=-g -Wall -O3 -std=c99
# the target
DEVICE=atmega328p
F_CPU=18432000UL
# the port to flash
#PORT=/dev/ttyUSB0
# the flasher
#PROGRAMMER=buspirate
PROGRAMMER=usbtiny
# to flash
#AVRDUDE=avrdude -p $(DEVICE) -P $(PORT) -c $(PROGRAMMER)
FLASHER=avrdude -p $(DEVICE) -c $(PROGRAMMER)
all: prog
prog: verify $(PROG).c
$(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -o $(PROG) $(PROG).c
$(OBJDUMP) -h -S $(PROG) > $(PROG).lst
$(OBJCOPY) -j .text -j .data -O ihex $(PROG) $(PROG).hex
# Fuse low byte:
# 0xff = 1 1 1 1 1 1 1 1
# ^ ^ \+/ \--+--/
# | | | +------- CKSEL 3..0 (clock selection -> full swing crytal oscillator)
# | | +--------------- SUT 1..0 (select start-up time -> slowly rising power)
# | +------------------ CKOUT (clock output on CKOUT pin -> unprogrammed)
# +-------------------- CKDIV8 (divide clock by 8 -> unprogrammed)
#
# Fuse high byte:
# 0xdf = 1 1 0 1 1 1 1 1
# ^ ^ ^ ^ ^ \+/ ^
# | | | | | | +---- BOOTRST (Select Reset Vector -> jump to application at start)
# | | | | | +------- BOOTSZ 1..0 (Select Boot Size -> 256 words starting at 0x3F00)
# | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> unprogrammed)
# | | | +-------------- WDTON (watchdog timer always on -> unprogrammed)
# | | +---------------- SPIEN (enable serial programming -> programmed)
# | +------------------ DWEN (debug wire enable -> unprogrammed)
# +-------------------- RSTDISBL (disable external reset -> unprogrammed)
#
# Fuse extended byte:
# 0x04 = - - - - - 1 0 0
# \-+-/
# +------ BODLEVEL 2..0 (Brown-out Detector trigger level -> 4.3V)
burn-fuse:
$(FLASHER) -U lfuse:w:0xff:m -U hfuse:w:0xdf:m -U efuse:w:0x04:m
read-fuse:
$(FLASHER) -U lfuse:r:lfuse.raw:r -U hfuse:r:hfuse.raw:r -U efuse:r:efuse.raw:r
flash:
$(FLASHER) -U flash:w:$(PROG).hex:i
read-flash:
$(FLASHER) -U flash:r:flash_dump.hex:i
flash: prog load
install : prog load
load:
$(FLASHER) -U flash:w:$(PROG).hex:i
clean:
rm -f $(PROG) *.hex *.lst
verify:
$(FLASHER)
if [ $$? -eq 0 ]; then \
echo "flasher configured correctly"; \
else \
echo "flasher not configured correctly in Makefile"; \
exit 1; \
fi