Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8206c11344 | ||
|
|
913afdb5dd |
No files matched your search
@@ -0,0 +1,4 @@
|
|||||||
|
*.hex
|
||||||
|
*.elf
|
||||||
|
*.bin
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "test/usart"]
|
||||||
|
path = test/usart
|
||||||
|
url = https://git.chch.tech/avr/usart.git
|
||||||
Vendored
+19
@@ -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
|
||||||
|
}
|
||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"git.ignoreLimitWarning": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
avrdude -p $1 -c $2 -t << END
|
||||||
|
write eeprom 0 $3
|
||||||
|
dump eeprom 0 16
|
||||||
|
quit
|
||||||
|
END
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Submodule
+1
Submodule test/usart added at 05034f9256.
Reference in new issue
Block a user