commit dc2f86c244e16e22071dee8b92dbc620d0eb2c13
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date: Sat, 30 Aug 2025 14:06:23 -0300
first commit
Diffstat:
3 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,17 @@
+ARDUINO_PORT = /dev/ttyACM0
+
+.PHONY: all
+
+all: compile
+
+compile: main.c
+ avr-gcc -Os -DF_CPU=16000000UL -mmcu=atmega328p -c -o main.o main.c
+ avr-gcc -o main.bin main.o
+ avr-objcopy -O ihex -R .eeprom main.bin main.hex
+
+upload: compile
+ avrdude -F -V -c arduino -p ATMEGA328P \
+ -P $(ARDUINO_PORT) -b 115200 -U flash:w:main.hex
+
+clean:
+ rm -f main.bin main.hex main.o
diff --git a/README.md b/README.md
@@ -0,0 +1,30 @@
+# Arduino Bare Metal Blink Example
+
+This is a simple arduino program to blink the built-in led
+
+## Dependencies
+
+* `avr-gcc` and `avr-libc` to compile the code
+* `avrdude` for uploading the program to the microcontroller
+
+## Compile and upload to the board
+
+Having the dependencies installed, compile the code running `make` or:
+
+```console
+$ make compile
+```
+
+Then with the board connected to the computer, check the port with:
+
+```console
+$ ls /dev/tty*
+```
+
+Often appears as `/dev/ttyUSB*` or `/dev/ttyACM*`, however it appears it should
+match the `ARDUINO_PORT` variable on `Makefile`. Finally upload the code to the
+arduino with
+
+```console
+$ make upload
+```
diff --git a/main.c b/main.c
@@ -0,0 +1,12 @@
+// Port B input pins register address
+#define PINB (*(volatile unsigned char*) 0x23)
+
+int main(void) {
+
+ while(1) {
+ PINB |= (1 << 5);
+ for(volatile long i = 0; i < 500000L; ++i);
+ }
+
+ return 0;
+}