Browse Source

Added host/arduino EEPROM programmer code

master
Stephen 1 year ago
parent
commit
345986ac9e
2 changed files with 128 additions and 0 deletions
  1. +98
    -0
      programmer/arduino/programmer/programmer.ino
  2. +30
    -0
      programmer/host/flashRom.py

+ 98
- 0
programmer/arduino/programmer/programmer.ino View File

@ -0,0 +1,98 @@
#define ADDR0 22
#define DATA0 2
#define DATA8 41
#define WE 10
#define OE 11
#define LWR_CE 12
#define UPR_CE 13
void setup()
{
for(int i = 0; i <= 18; i++)
{
pinMode(i + ADDR0, OUTPUT);
}
pinMode(WE, OUTPUT);
pinMode(OE, OUTPUT);
pinMode(LWR_CE, OUTPUT);
pinMode(UPR_CE, OUTPUT);
Serial.begin(57600);
}
bool writing = false;
long numBytes = 0;
long pos = 0;
void loop()
{
if(!writing && Serial.available() >= 2)
{
//0xBEEF means we just started
byte in1 = Serial.read();
byte in2 = Serial.read();
if(in1 == 0xBE && in2 == 0xEF)
{
writing = true;
//Next thing received will be # bytes
numBytes = Serial.parseInt();
Serial.read(); //next byte is garbage, used as a separator
pos = 0;
setData(OUTPUT);
digitalWrite(OE, HIGH);
digitalWrite(WE, HIGH);
digitalWrite(LWR_CE, LOW);
digitalWrite(UPR_CE, LOW);
Serial.println("OK");
}
}
else if(writing && Serial.available() >= 2)
{
writeAddr(pos++);
writeDataLwr(Serial.read());
writeDataUpr(Serial.read());
digitalWrite(WE, LOW);
delay(5);
digitalWrite(WE, HIGH);
if(--numBytes == 0) //We're done
{
writing = false;
}
}
}
void setData(int dir)
{
for(int i = 0; i < 8; i++)
{
pinMode(i + DATA0, dir);
pinMode(i + DATA8, dir);
}
}
void writeAddr(long addr)
{
for(int i = 0; i <= 18; i++)
{
digitalWrite(ADDR0 + i, addr & 1);
addr >>= 1;
}
}
void writeDataLwr(byte data)
{
for(int i = 0; i < 8; i++)
{
digitalWrite(DATA0 + i, data & 1);
data >>= 1;
}
}
void writeDataUpr(byte data)
{
for(int i = 0; i < 8; i++)
{
digitalWrite(DATA8 + i, data & 1);
data >>= 1;
}
}

+ 30
- 0
programmer/host/flashRom.py View File

@ -0,0 +1,30 @@
import serial
import sys
if (len(sys.argv) != 3):
print(f"Usage: {sys.argv[0]} port image")
print(f"Ex. {sys.argv[0]} /dev/ttyUSB0 firmware.bin", sys.argv[0])
exit(1)
ser = None
try:
ser = serial.Serial(
port=sys.argv[1],
baudrate=57600
)
except:
print("Could not open serial port")
exit(1)
ser.isOpen()
imagefile = open(sys.argv[2], "rb")
img = imagefile.read()
imagefile.close()
print(f"Have {str(len(img))} bytes to send")
#magic hex
ser.write([0xBE, 0xEF])
ser.write(str(len(img)).encode())
ser.write(0x55) #garbage - is thrown away
ser.write(img)
ser.close()

Loading…
Cancel
Save