§ Шаблона makefile
Компиляция под стандартный микроконтроллера AtMega328.
1# https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html
2DEVICE = atmega328
3OPTIONS = -Os -DF_CPU=25000000 -mmcu=$(DEVICE) -std=c++11
4INCLUDE = -I.. -Iinclude
5WARNING = -Wall -Wno-unused-but-set-variable
6LINKER = -fdata-sections -Wl,--gc-sections,--defsym=__stack=0x80efff,--defsym=__heap_end=0x80efff
7COMPILE = avr-gcc $(INCLUDE) $(WARNING) $(OPTIONS) $(LINKER)
8AVR = avr_machine
9
10all:
11 $(COMPILE) main.cc -o main.elf
12 avr-objcopy -j .text -j .data -O binary main.elf main.bin
13 avr-objdump -S main.elf > main.lst
14 avr-size -C --mcu=$(DEVICE) main.elf > mem.map
15 rm main.elf
16 $(AVR) main.bin
17
18clean:
19 rm -f *.o rm *.elf *.lst *.bin *.map
§ main.cc
1#include <avrio.h>
2
3ISR(INT0_vect) { }
4
5int main() {
6 for (;;);
7}
§ Файл avrio.h
1
6
7#ifndef __AVRIO_GENERIC_FILE
8#define __AVRIO_GENERIC_FILE
9
10#include <avr/pgmspace.h>
11#include <avr/interrupt.h>
12
13
14#define LPM(t) pgm_read_byte(&t)
15#define LPW(t) pgm_read_word(&t)
16
17
18typedef unsigned char byte;
19typedef unsigned int word;
20typedef unsigned long dword;
21
22
23inline byte inp(byte port) { return ((volatile byte*) 0x20)[port]; }
24inline void out(byte port, byte val) { ((volatile byte*) 0x20)[port] = val; }
25
26
27#define heap(x, a) byte* x = (byte*) a
28
29#endif
§ Устройства
DEVICE ROM RAM EEPROM
atmega328 32k 2048 1024
attiny85 8k 512 512
Если выбран attiny85
LINKER = -fdata-sections -Wl,--gc-sections,--defsym=__stack=0x80025f,--defsym=__heap_end=0x80025f