Skip to content

Instantly share code, notes, and snippets.

@lafiosca
Last active May 7, 2020 03:38
Show Gist options
  • Save lafiosca/bb877189a3bcc5c54c607485dee5935a to your computer and use it in GitHub Desktop.
Save lafiosca/bb877189a3bcc5c54c607485dee5935a to your computer and use it in GitHub Desktop.
Minimal ATMega8515L STK500 USB-Serial Adapter OSX deployment
#!/bin/bash
set -e
if (( $# != 1 ))
then
echo "Usage: $0 <file.c>"
exit 1
fi
FILE_PATH=$(realpath $1)
DIR=$(dirname $FILE_PATH)
FILE=$(basename $FILE_PATH)
if [[ ! -s $FILE ]]
then
echo "$1 is empty or does not exist"
exit 1
fi
if [[ ! $FILE =~ .\.c$ ]]
then
echo "$1 is not a .c file"
exit 2
fi
BASE=${FILE%.c}
cd "$DIR"
echo "Compiling $FILE"
avr-gcc -g -Os -mmcu=atmega8515 -c $FILE
avr-gcc -g -mmcu=atmega8515 -o $BASE.elf $BASE.o
echo "Converting object to hex"
avr-objcopy -j .text -j .data -O ihex $BASE.elf $BASE.hex
echo "Flashing AVR"
avrdude -p m8515 -c stk500 -v -U flash:w:$BASE.hex -P /dev/cu.usbserial-142440
echo "Done"
#ifndef F_CPU
#define F_CPU 8000000L // or whatever may be your frequency
#endif
#include <avr/io.h>
#include <util/delay.h> // for _delay_ms()
int main(void)
{
DDRB = 0x01; // initialize port C
while(1)
{
// LED on
PORTB = 0b00000001; // PB0 = High = Vcc
_delay_ms(500); // wait 500 milliseconds
//LED off
PORTB = 0b00000000; // PB0 = Low = 0v
_delay_ms(500); // wait 500 milliseconds
}
}
Install avrdude and the AVR toolchain from https://github.com/osx-cross/homebrew-avr
```
brew install avrdude
brew tap osx-cross/avr
brew install avr-gcc
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment