template to compile/flash code without ide

master
ugrnm 5 years ago
parent b31459f962
commit 138fef792e

@ -0,0 +1,3 @@
*.o
*.elf
*.hex

@ -0,0 +1,27 @@
baud=57600
avrType=atmega328p
avrFreq=16000000 # 16 Mhz
programmerDev=/dev/ttyUSB0
programmerType=arduino
cflags=-DF_CPU=$(avrFreq) -mmcu=$(avrType) -Wall -Werror -Wextra -Os
objects=$(patsubst %.c,%.o,$(wildcard *.c))
.PHONY: flash clean
all: main.hex
%.o: %.c
avr-gcc $(cflags) -c $< -o $@
main.elf: $(objects)
avr-gcc $(cflags) -o $@ $^
main.hex: main.elf
avr-objcopy -j .text -j .data -O ihex $^ $@
flash: main.hex
avrdude -p$(avrType) -c$(programmerType) -P$(programmerDev) -b$(baud) -v -U flash:w:$<
clean:
rm -f main.hex main.elf $(objects)

@ -0,0 +1,6 @@
You don't need the Arduino IDE, you can simply use a Makefile and write your
C code as long as you have avr-gcc, avr-libc and avrdude installed!
make # compile and generate main.hex
make flash # flash it to the Arduino nano

@ -0,0 +1,14 @@
#include <util/delay.h>
#include <avr/io.h>
#define LED PORTB5
int main(void) {
DDRB |= (1 << LED);
for/*ever*/(;;) {
PORTB |= (1 << LED);
_delay_ms(100);
PORTB &= (0 << LED);
_delay_ms(100);
}
}
Loading…
Cancel
Save