AVR-Playground/makefile

58 lines
1 KiB
Makefile
Raw Normal View History

2024-02-09 02:14:45 +01:00
# AVR-GCC compiler
CC = avr-gcc
# Programmer (change it according to your programmer)
PROGRAMMER = usbasp
# MCU
MCU = atmega328p
2024-02-10 14:37:38 +01:00
QEMU_MACHINE_NAME = uno
2024-02-09 02:14:45 +01:00
# Compiler flags
2024-03-23 04:28:03 +01:00
CFLAGS = -std=c2x -Wall -Wno-array-bounds -mmcu=$(MCU) -DF_CPU=16000000UL -O3
2024-02-09 02:14:45 +01:00
# Source files
SRCS = main.c
# Object files
OBJS = $(SRCS:.c=.o)
# Target file
TARGET = main
# Default target
all: $(TARGET).hex
# Compile C files
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
# Link object files
$(TARGET).elf: $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(TARGET).elf
2024-03-23 04:28:03 +01:00
avr-strip $(TARGET).elf
2024-02-09 02:14:45 +01:00
# Convert ELF to HEX
$(TARGET).hex: $(TARGET).elf
avr-objcopy -O ihex -R .eeprom $(TARGET).elf $(TARGET).hex
# Flash the program
flash: $(TARGET).hex
avrdude -p $(MCU) -c $(PROGRAMMER) -U flash:w:$(TARGET).hex
2024-02-10 14:37:38 +01:00
# Run the program in QEMU
qemu: $(TARGET).elf
qemu-system-avr -machine $(QEMU_MACHINE_NAME) -bios $(TARGET).elf
# View the generated assembly
asm: $(TARGET).hex
avr-objdump -S $(TARGET).elf
2024-03-23 04:28:03 +01:00
serial:
picocom -b 9600 /dev/ttyUSB0
2024-02-09 02:14:45 +01:00
# Clean
clean:
rm -f $(OBJS) $(TARGET).elf $(TARGET).hex