Skip to content

Instantly share code, notes, and snippets.

@CarlosDomingues
Last active March 6, 2021 20:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CarlosDomingues/bca6f31391bedd300024 to your computer and use it in GitHub Desktop.
Save CarlosDomingues/bca6f31391bedd300024 to your computer and use it in GitHub Desktop.
Steps for Arduino bare metal programming

First install:

$sudo apt-get install avrdude gcc-avr avr-libc

Then:

$avr-gcc -Os -DF_CPU=16000000UL -mmcu=atmega328p -c -o led.o led.c

-DF_CPU is the CPU clock speed

$avr-gcc -mmcu=atmega328p led.o -o led

$avr-objcopy -O ihex -R .eeprom led led.hex

$sudo avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyACM0 -b 115200 -U flash:w:led.hex

Instead of sudoing in the last command you can also use:

$sudo adduser Username dialout

Then logout and login again. You now will be able to write at ttyACM0 without being sudo.

To use UART:

$sudo apt-get install minicom

See which serial port Arduino is connected to:

$dmesg | grep tty

Run

$minicom -s

Go to Serial port Setup Then change "Serial Device" to the one you saw with grep (ttyACM0 in my case) And Bps to 9600 (or the Baud rate you are using) 8N1 And Hardware Flow controle to "no"

Then use the option "Save as dfl"

restart minicom (without sudo) $minicom

ALTERNATE SCHEME

Open two terminals:

1 - $less -f /dev/ttyACM0 2 - $echo '1' > /dev/ttyACM0

To configure baudrate, etc... use the "stty" command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment