Patrick Fitzgerald
Published

Linux CLI Compile C/C+ program and flash Arduino Uno

Use the CLI terminal window to compile and flash C language programs to the Arduino Uno.

BeginnerProtip1 hour1,661

Things used in this project

Story

Read more

Code

main.c

C/C++
This file is the main.c used in the project
#include <avr/io.h>
int main(void){   DDRB = 0xFF;
    while(1){PORTB++;
    int i; for (i=0; i < 0x7FFF; i++){;}}}

Makefile

Makefile
This is the Makefile used in the project.
make
make all
make clean
make flash
MCU=atmega328p
F_CPU=1200000
CC=avr-gcc
OBJCOPY=avr-objcopy
CFLAGS=-std=c99 -Wall -g -Os -mmcu=${MCU} -DF_CPU=${F_CPU} -I.
TARGET=main
SRCS=main.c 
all:
	${CC} ${CFLAGS} -o ${TARGET}.bin ${SRCS}
	${OBJCOPY} -j .text -j .data -O ihex ${TARGET}.bin ${TARGET}.hex		
flash:
	avrdude -p ${MCU} -c arduino -U flash:w:${TARGET}.hex:i -F -P /dev/ttyACM0
clean:
	rm -f *.bin *.hex

Credits

Patrick Fitzgerald
124 projects • 51 followers

Comments