make ddcp target to compile all usb helper utils
[digitaldcpower] / Makefile
1 # makefile for digitial dc power supply, written by guido socher
2 MCU=atmega8
3 DUDECPUTYPE=m8
4 # === Edit this and enter the correct device/com-port:
5 # linux (plug in the avrusb500 and type dmesg to see which device it is):
6 LOADCMD=avrdude -P /dev/ttyUSB0
7
8 # mac (plug in the programer and use ls /dev/tty.usbserial* to get the name):
9 #LOADCMD=avrdude -P /dev/tty.usbserial-A9006MOb
10
11 # windows (check which com-port you get when you plugin the avrusb500):
12 #LOADCMD=avrdude -P COM4
13
14 # All operating systems: if you have set the default_serial paramter 
15 # in your avrdude.conf file correctly then you can just use this
16 # and you don't need the above -P option:
17 #LOADCMD=avrdude
18 # === end edit this
19 #
20 #LOADARG=-p $(DUDECPUTYPE) -c stk500v2 -e -U flash:w:
21 PROGRAMMER=-p $(DUDECPUTYPE) -c stk500v2
22
23 # board ->      bus pirate
24 #
25 # /RST  ->      CS      9. WT
26 # MOSI  ->      MOSI    8. GR
27 # MISO  ->      MISO    0. Blk
28 # SCK   ->      CLK     7. PU
29 # GND   ->      GND     1. BR
30 #
31 PROGRAMMER=-p $(DUDECPUTYPE) -c buspirate
32
33 LOADARG=$(PROGRAMMER) -e -U flash:w:
34
35
36 CC=avr-gcc
37 OBJCOPY=avr-objcopy
38 # optimize for size:
39 CFLAGS=-g -mmcu=$(MCU) -Wall -W -Os -mcall-prologues
40 # #-------------------
41 .PHONY: test_lcd test_dac all main ddcp-script
42 #
43 all: main.hex test_lcd.hex test_dac.hex
44 #
45 ddcp-script: ddcp-script-setval ddcp-script-getval ddcp-script-ttyinit
46 #
47 main: main.hex 
48 #
49 test_lcd: test_lcd.hex
50         echo "OK"
51 #
52 test_dac: test_dac.hex
53         echo "OK"
54 #
55 ddcp-script-setval: ddcp-script-setval.c
56         gcc -Wall -o ddcp-script-setval ddcp-script-setval.c
57 ddcp-script-getval: ddcp-script-getval.c
58         gcc -Wall -o ddcp-script-getval ddcp-script-getval.c
59 ddcp-script-ttyinit: ddcp-script-ttyinit.c
60         gcc -Wall -o ddcp-script-ttyinit ddcp-script-ttyinit.c
61 ddcp: ddcp-script-setval ddcp-script-getval ddcp-script-ttyinit
62 #-------------------
63 size:
64         avr-size *.elf
65 help: 
66         @echo "Usage: make help"
67         @echo "       Print this help"
68         @echo " "
69         @echo "Usage: make all|load|rdfuses|fuses"
70         @echo "       program using the avrdude programmer"
71         @echo " "
72         @echo "Usage: make clean"
73         @echo "       delete all generated files"
74         @echo "Test programs:"
75         @echo "Usage: make test_lcd|load_test_lcd|test_dac|load_test_dac"
76         @echo "       compile and load test programs"
77         @echo "Usage: make ddcp"
78         @echo "       compile unix program to set serial line speed such that one can use scripts to change settings"
79 #-------------------
80 main.hex: main.elf 
81         $(OBJCOPY) -R .eeprom -O ihex main.elf main.hex 
82         avr-size main.elf
83         @echo " "
84         @echo "Expl.: data=initialized data, bss=uninitialized data, text=code"
85         @echo " "
86 main.elf: main.o dac.o lcd.o analog.o kbd.o uart.o
87         $(CC) $(CFLAGS) -o main.elf -Wl,-Map,main.map main.o dac.o lcd.o analog.o kbd.o uart.o
88 main.o: main.c dac.h kbd.h lcd.h lcd_hw.h analog.h hardware_settings.h uart.h
89         $(CC) $(CFLAGS) -Os -c main.c 
90 #-------------------
91 test_lcd.hex: test_lcd.elf 
92         $(OBJCOPY) -R .eeprom -O ihex test_lcd.elf test_lcd.hex 
93 test_lcd.elf: test_lcd.o lcd.o kbd.o
94         $(CC) $(CFLAGS) -o test_lcd.elf -Wl,-Map,test_lcd.map test_lcd.o lcd.o kbd.o
95 test_lcd.o: test_lcd.c lcd.h lcd_hw.h kbd.h
96         $(CC) $(CFLAGS) -Os -c test_lcd.c
97 #-------------------
98 test_dac.hex: test_dac.elf 
99         $(OBJCOPY) -R .eeprom -O ihex test_dac.elf test_dac.hex 
100 test_dac.elf: test_dac.o lcd.o kbd.o dac.o
101         $(CC) $(CFLAGS) -o test_dac.elf -Wl,-Map,test_dac.map test_dac.o lcd.o kbd.o dac.o
102 test_dac.o: test_dac.c lcd.h lcd_hw.h kbd.h dac.h
103         $(CC) $(CFLAGS) -Os -c test_dac.c
104 #-------------------
105 lcd.o : lcd.c lcd.h lcd_hw.h
106         $(CC) $(CFLAGS) -Os -c lcd.c
107 #-------------------
108 analog.o : analog.c analog.h hardware_settings.h
109         $(CC) $(CFLAGS) -Os -c analog.c
110 #-------------------
111 dac.o : dac.c dac.h 
112         $(CC) $(CFLAGS) -Os -c dac.c
113 #-------------------
114 kbd.o : kbd.c kbd.h 
115         $(CC) $(CFLAGS) -Os -c kbd.c
116 #-------------------
117 uart.o : uart.c uart.h 
118         $(CC) $(CFLAGS) -Os -c uart.c
119 #-------------------
120 load: main.hex
121         $(LOADCMD) $(LOADARG)main.hex
122 #
123 load_test_lcd: test_lcd.hex
124         $(LOADCMD) $(LOADARG)test_lcd.hex
125 #
126 load_test_dac: test_dac.hex
127         $(LOADCMD) $(LOADARG)test_dac.hex
128 #
129 #-------------------
130 # fuse byte settings:
131 #  Atmel AVR ATmega8 
132 #  Fuse Low Byte      = 0xe1 (1MHz internal), 0xe4 (8MHz internal)
133 #  Fuse Low Byte with BOD  = 0xa1 (1MHz internal), 0xa4 (8MHz internal)
134 #  Fuse High Byte     = 0xd9 
135 #  Factory default is 0xe1 for low byte and 0xd9 for high byte
136 # Check this with make rdfuses
137 rdfuses:
138         $(LOADCMD) $(PROGRAMMER) -v -q
139 # use internal RC oscillator 8 Mhz (lf=0xe4 hf=0xd9)
140 fuses:
141         $(LOADCMD) $(PROGRAMMER) -u -v -U lfuse:w:0xa4:m
142         $(LOADCMD) $(PROGRAMMER) -u -v -U hfuse:w:0xd9:m
143 fuse:
144         $(LOADCMD) $(PROGRAMMER) -u -v -U lfuse:w:0xa4:m
145         $(LOADCMD) $(PROGRAMMER) -u -v -U hfuse:w:0xd9:m
146 #-------------------
147 clean:
148         rm -f *.o *.map *.elf test*.hex main.hex ddcp-script-ttyinit ddcp-script-getval ddcp-script-setval
149 #-------------------