Here you can find documentation of the Embedded Programming group assignment which maps to the following Fab Academy assignment weeks.
I followed this avr-gcc & avrdude makefile tutorial | Compile C & upload to AVR board (mac) and adjusted some parameters to generate hex code from a elf file (which is generated from a c file) via avr-gcc and then upload the hex file to the ATtiny 412 board via avrdude.
Follow the order below to install avr-gcc properly:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
:
install Homebrew
xcode-select --install
:
install Xcode
brew tap osx-cross/avr
brew install avrdude
: install AVR Downloader/Uploader
#include <avr/io.h>
#include <util/delay.h>
int main(void) {
PORTA.DIRSET = PIN3_bm;// or PORTA.DIR = 0b01000000; // Use LED: PA3 as Output
PORTA.DIRCLR = PIN6_bm;// Use Button: PA6 as Input
while (1) {
PORTA.OUT |= LED_AVR;
_delay_ms(500);
PORTA.OUT &= ~LED_AVR;
_delay_ms(500);
}
}
FILENAME = hello.412.blink
PORT = /dev/tty.usbserial-D3072T1T
DEVICE = attiny412
PYUPDI_DEVICE = tiny412
# PROGRAMMER = jtag2updi
BAUD = 115200
# For adding device packs of the latest chips (e.g. ATtiny412, 1614...)
INCLUDE = "/Users/USER_NAME/Documents/AVR/Atmel.ATtiny_DFP.1.8.332/include"
PACK = "/Users/USER_NAME/Documents/AVR/Atmel.ATtiny_DFP.1.8.332/gcc/dev/attiny412"
COMPILE = avr-gcc -Wall -Os -DF_CPU=20000000 -mmcu=${DEVICE} -I ${INCLUDE} -B ${PACK}
default: compile upload clean
compile:
${COMPILE} -c ${FILENAME}.c -o ${FILENAME}.o
//highlight-next-line
${COMPILE} -o ${FILENAME}.elf ${FILENAME}.o # Problem: Can't generate .elf from .o file.
avr-objcopy -j .text -j .data -O ihex ${FILENAME}.elf ${FILENAME}.hex
avr-size --format=avr --mcu=${DEVICE} ${FILENAME}.elf
upload:
# avrdude -v -p ${DEVICE} -c ${PROGRAMMER} -P ${PORT} -b ${BAUD} -U flash:w:${FILENAME}.hex:i
pyupdi -d ${PYUPDI_DEVICE} -b ${BAUD} -c ${PORT} -f ${FILENAME}.hex -v
clean:
rm ${FILENAME}.o
rm ${FILENAME}.elf
rm ${FILENAME}.hex
Since the command for uploading the hex file to the ATtiny 412 board through pyupdi has been defined in the upload section of the Makefile, we just need to type the following commands in the terminal with the ATtiny 412 board connected to the UPDI programmer introduced here.
cd path/to/hex/and/Makefile/file
make