Browse Source

Intial commit

master
CVR 3 months ago
parent
commit
8206c11344
  1. 4
      .gitignore
  2. 19
      .vscode/c_cpp_properties.json
  3. 3
      .vscode/settings.json
  4. 19
      LICENSE
  5. 2
      README.md
  6. 7
      eeprom.sh
  7. 38
      makefile
  8. 28
      src/eeprom.cpp
  9. 8
      src/eeprom.h
  10. 15
      test/main.cpp

4
.gitignore

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

19
.vscode/c_cpp_properties.json

@ -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

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

19
LICENSE

@ -0,0 +1,19 @@
MIT License Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

2
README.md

@ -0,0 +1,2 @@
# eeprom

7
eeprom.sh

@ -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

@ -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

@ -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

@ -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

@ -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);
}
Loading…
Cancel
Save