Compare commits

...

No commits in common. "f5fbe735a43f83d09740b3738850738821298a02" and "8206c113449b09d22812f2000a832448749094ca" have entirely different histories.

10 changed files with 126 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.hex
*.elf
*.bin

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "test/usart"]
path = test/usart
url = https://git.chch.tech/avr/usart.git

19
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/lib/avr/include/"
],
"defines": [
"__AVR_ATmega16__"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu18",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}

7
eeprom.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/sh
avrdude -p $1 -c $2 -t << END
write eeprom 0 $3
dump eeprom 0 16
quit
END

38
makefile Normal file
View File

@ -0,0 +1,38 @@
MCU?=atmega32
F_CPU=8000000
PROG?=dragon_jtag
DEBUGGER = dragon
PORT?=/dev/ttyUSB0
TYPE?=DEBUG
CC=avr-g++
OBJCOPY=avr-objcopy
CFLAGS=-Wall -g -O -mmcu=${MCU} -DF_CPU=${F_CPU} -I. -std=gnu++11 -D${TYPE} -Wno-write-strings
TARGET=main
SRCS=src/eeprom.cpp test/main.cpp test/usart/src/usart.cpp
default: build flash
build:
${CC} ${CFLAGS} -o bin/${TARGET}.bin ${SRCS}
${CC} ${CFLAGS} -o bin/${TARGET}.elf ${SRCS}
${OBJCOPY} -j .text -j .data -O ihex bin/${TARGET}.bin bin/${TARGET}.hex
flash:
avrdude -p ${MCU} -c ${PROG} -P ${PORT} ${BAUD} -U flash:w:bin/main.hex
clean:
rm -f bin/*
debug: flash avarice
avr-gdb -ex "target remote :4242" bin/main.elf
avarice:
sleep 1
avarice --file bin/main.elf --part ${MCU} --${DEBUGGER} :4242 &
term:
screen /dev/ttyUSB0 1000000
eeprom:
sh eeprom.sh

28
src/eeprom.cpp Normal file
View File

@ -0,0 +1,28 @@
#include "eeprom.h"
namespace eeprom
{
void write(uint8_t address, uint8_t data) {
/* Wait for completion of previous write */
while(EECR & (1<<EEWE));
/* Set up address and data registers */
EEAR = address;
EEDR = data;
/* Write logical one to EEMWE */
EECR |= (1<<EEMWE);
/* Start eeprom write by setting EEWE */
EECR |= (1<<EEWE);
}
uint8_t read(uint8_t address) {
/* Wait for completion of previous write */
while(EECR & (1<<EEWE));
/* Set up address register */
EEAR = address;
/* Start eeprom read by writing EERE */
EECR |= (1<<EERE);
/* Return data from data register */
return EEDR;
}
} // namespace eeprom

8
src/eeprom.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include <avr/io.h>
namespace eeprom
{
void write(uint8_t address, uint8_t data);
uint8_t read(uint8_t address);
} // namespace eeprom

15
test/main.cpp Normal file
View File

@ -0,0 +1,15 @@
#include "../src/eeprom.h"
#include "usart/src/usart.h"
#include <avr/io.h>
#include <util/delay.h>
int main() {
usart::init(1000000);
printf("\033[2J");
for(int i=0;i<16;i++)
printf("%i %x\n\r", i, eeprom::read(i));
DDRB |= (1<<PB3);
}

1
test/usart Submodule

@ -0,0 +1 @@
Subproject commit 05034f925671f06abe15097326b05eceeef0bc1e