Browse Source

update Makefile

pull/1/head
Olaf Rempel 4 years ago
parent
commit
5e4b562608
3 changed files with 70 additions and 50 deletions
  1. 1
    0
      .gitignore
  2. 53
    47
      Makefile
  3. 16
    3
      main.c

+ 1
- 0
.gitignore View File

@@ -3,4 +3,5 @@
3 3
 *.bin
4 4
 *.hex
5 5
 *.lst
6
+*.lss
6 7
 *.map

+ 53
- 47
Makefile View File

@@ -1,65 +1,71 @@
1
-PRG            = twiboot
2
-OBJ            = main.o
3
-MCU_TARGET     = atmega88
4
-OPTIMIZE       = -Os
1
+CC	:= avr-gcc
2
+LD	:= avr-ld
3
+OBJCOPY	:= avr-objcopy
4
+OBJDUMP	:= avr-objdump
5
+SIZE	:= avr-size
5 6
 
6
-ifeq ($(MCU_TARGET), atmega8)
7
-BOOTLOADER_START=0x1C00
7
+TARGET = twiboot
8
+SOURCE = $(wildcard *.c)
9
+
10
+# select MCU
11
+MCU = atmega88
12
+
13
+AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ttyUSB0
14
+#AVRDUDE_PROG := -c dragon_isp -P usb
15
+
16
+# ---------------------------------------------------------------------------
17
+
18
+ifeq ($(MCU), atmega8)
19
+# (8Mhz internal RC-Osz., 2.7V BOD)
8 20
 AVRDUDE_MCU=m8
9
-endif
10
-ifeq ($(MCU_TARGET), atmega88)
21
+AVRDUDE_FUSES=lfuse:w:0x84:m hfuse:w:0xda:m
22
+
11 23
 BOOTLOADER_START=0x1C00
24
+endif
25
+
26
+ifeq ($(MCU), atmega88)
27
+# (8Mhz internal RC-Osz., 2.7V BOD)
12 28
 AVRDUDE_MCU=m88
29
+AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xfa:m
30
+
31
+BOOTLOADER_START=0x1C00
13 32
 endif
14
-ifeq ($(MCU_TARGET), atmega168)
33
+
34
+ifeq ($(MCU), atmega168)
35
+# (8Mhz internal RC-Osz., 2.7V BOD)
36
+AVRDUDE_MCU=m168 -F
37
+AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xfa:m
38
+
15 39
 BOOTLOADER_START=0x3C00
16
-AVRDUDE_MCU=m168
17 40
 endif
18 41
 
19
-DEFS           = -DAPP_END=$(BOOTLOADER_START)
20
-LIBS           =
42
+# ---------------------------------------------------------------------------
21 43
 
22
-# Override is only needed by avr-lib build system.
23
-override CFLAGS        = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
24
-override LDFLAGS       = -Wl,-Map,$(PRG).map,--section-start=.text=$(BOOTLOADER_START)
44
+CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
45
+CFLAGS += -Wa,-adhlns=$(*F).lst -DBOOTLOADER_START=$(BOOTLOADER_START)
46
+LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections,--section-start=.text=$(BOOTLOADER_START)
25 47
 
26
-CC             = avr-gcc
27
-OBJCOPY        = avr-objcopy
28
-OBJDUMP        = avr-objdump
29
-SIZE           = avr-size
48
+# ---------------------------------------------------------------------------
30 49
 
31
-all: $(PRG).elf lst text
32
-	$(SIZE) -x -A $(PRG).elf
50
+$(TARGET): $(TARGET).elf
51
+	@$(SIZE) -B -x --mcu=$(MCU) $<
33 52
 
34
-$(PRG).elf: $(OBJ)
35
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
53
+$(TARGET).elf: $(SOURCE:.c=.o)
54
+	@echo " Linking file:  $@"
55
+	@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
56
+	@$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
57
+	@$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
58
+	@$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
36 59
 
37 60
 %.o: %.c $(MAKEFILE_LIST)
38
-	$(CC) $(CFLAGS) -c $< -o $@
61
+	@echo " Building file: $<"
62
+	@$(CC) $(CFLAGS) -o $@ -c $<
39 63
 
40 64
 clean:
41
-	rm -rf *.o $(PRG).lst $(PRG).map $(PRG).elf $(PRG).hex $(PRG).bin
42
-
43
-lst:  $(PRG).lst
44
-
45
-%.lst: %.elf
46
-	$(OBJDUMP) -h -S $< > $@
47
-
48
-text: hex bin
49
-
50
-hex:  $(PRG).hex
51
-bin:  $(PRG).bin
52
-
53
-%.hex: %.elf
54
-	$(OBJCOPY) -j .text -j .data -O ihex $< $@
55
-
56
-%.bin: %.elf
57
-	$(OBJCOPY) -j .text -j .data -O binary $< $@
65
+	rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin)
58 66
 
59
-install: text
60
-	avrdude -c dragon_isp -P usb -p $(AVRDUDE_MCU) -U flash:w:$(PRG).hex
67
+install: $(TARGET).elf
68
+	avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
61 69
 
62
-#fuses:
63
-#	avrdude -c dragon_isp -P usb -p $(AVRDUDE_MCU) -U lfuse:w:0xc2:m
64
-#	avrdude -c dragon_isp -P usb -p $(AVRDUDE_MCU) -U hfuse:w:0xdd:m
65
-#	avrdude -c dragon_isp -P usb -p $(AVRDUDE_MCU) -U efuse:w:0xfa:m
70
+fuses:
71
+	avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))

+ 16
- 3
main.c View File

@@ -54,6 +54,7 @@
54 54
 #endif
55 55
 
56 56
 #define EEPROM_SUPPORT		1
57
+#define LED_SUPPORT		1
57 58
 
58 59
 /* 25ms @8MHz */
59 60
 #define TIMER_RELOAD		(0xFF - 195)
@@ -61,6 +62,7 @@
61 62
 /* 40 * 25ms */
62 63
 #define TIMEOUT			40
63 64
 
65
+#if LED_SUPPORT
64 66
 #define LED_INIT()		DDRB = ((1<<PORTB4) | (1<<PORTB5))
65 67
 #define LED_RT_ON()		PORTB |= (1<<PORTB4)
66 68
 #define LED_RT_OFF()		PORTB &= ~(1<<PORTB4)
@@ -68,8 +70,19 @@
68 70
 #define LED_GN_OFF()		PORTB &= ~(1<<PORTB5)
69 71
 #define LED_GN_TOGGLE()		PORTB ^= (1<<PORTB5)
70 72
 #define LED_OFF()		PORTB = 0x00
73
+#else
74
+#define LED_INIT()
75
+#define LED_RT_ON()
76
+#define LED_RT_OFF()
77
+#define LED_GN_ON()
78
+#define LED_GN_OFF()
79
+#define LED_GN_TOGGLE()
80
+#define LED_OFF()
81
+#endif
71 82
 
83
+#ifndef TWI_ADDRESS
72 84
 #define TWI_ADDRESS		0x29
85
+#endif
73 86
 
74 87
 /* SLA+R */
75 88
 #define CMD_WAIT		0x00
@@ -138,8 +151,8 @@ const static uint8_t chipinfo[8] = {
138 151
 
139 152
 	SPM_PAGESIZE,
140 153
 
141
-	(APP_END >> 8) & 0xFF,
142
-	APP_END & 0xFF,
154
+	(BOOTLOADER_START >> 8) & 0xFF,
155
+	BOOTLOADER_START & 0xFF,
143 156
 #if (EEPROM_SUPPORT)
144 157
 	((E2END +1) >> 8 & 0xFF),
145 158
 	(E2END +1) & 0xFF
@@ -162,7 +175,7 @@ static void write_flash_page(void)
162 175
 	uint8_t size = SPM_PAGESIZE;
163 176
 	uint8_t *p = buf;
164 177
 
165
-	if (pagestart >= APP_END)
178
+	if (pagestart >= BOOTLOADER_START)
166 179
 		return;
167 180
 
168 181
 	boot_page_erase(pagestart);

Loading…
Cancel
Save