The Make Utility is a build tool that automatically determines which source files of a program need to be recompiled and/or linked. We can compile, link and flashing of AVR microcontroller using only one command in the terminal: make. Make remains widely used, especially in Unix-like operating systems.
How to use
1. Create a file inside of project's folder without extension and called Makefile.
2. Place commands in it.
3. Open a terminal and move into the project's folder with Makefile.
4. Type make command in terminal.
5. Use labels like:
make all
make flash
make clean
Check here the example for ATTiny13
=====
MCU=attiny13
F_CPU=1200000
CC=avr-gcc
CS=avr-size
OBJCOPY=avr-objcopy
CFLAGS=-std=c99 -Wall -g -Os -mmcu=${MCU} -DF_CPU=${F_CPU} -I.
TARGET=main
SRCS=main.c
all:
@printf "\n"
@printf " ===> Compiling: \n"
${CC} ${CFLAGS} -o ${TARGET}.bin ${SRCS}
@printf "\n"
@printf " ===> Size: \n"
${CS} -C ${TARGET}.bin
@printf " ===> Generating .HEX: \n"
${OBJCOPY} -j .text -j .data -O ihex ${TARGET}.bin ${TARGET}.hex
flash:
@printf "\n"
@printf " ===> Flashing: \n"
avrdude -p ${MCU} -B 4 -c usbasp -U flash:w:${TARGET}.hex:i -F -P usb
clean:
@printf "\n"
@printf " ===> Cleaning: \n"
rm -f *.bin *.hex
Check here the example for ATTiny13
=====
MCU=attiny13
F_CPU=1200000
CC=avr-gcc
CS=avr-size
OBJCOPY=avr-objcopy
CFLAGS=-std=c99 -Wall -g -Os -mmcu=${MCU} -DF_CPU=${F_CPU} -I.
TARGET=main
SRCS=main.c
all:
@printf "\n"
@printf " ===> Compiling: \n"
${CC} ${CFLAGS} -o ${TARGET}.bin ${SRCS}
@printf "\n"
@printf " ===> Size: \n"
${CS} -C ${TARGET}.bin
@printf " ===> Generating .HEX: \n"
${OBJCOPY} -j .text -j .data -O ihex ${TARGET}.bin ${TARGET}.hex
flash:
@printf "\n"
@printf " ===> Flashing: \n"
avrdude -p ${MCU} -B 4 -c usbasp -U flash:w:${TARGET}.hex:i -F -P usb
clean:
@printf "\n"
@printf " ===> Cleaning: \n"
rm -f *.bin *.hex
No comments:
Post a Comment