Added the erase command to fill the EEPROM with 0xFF

This commit is contained in:
Mariano Uvalle 2020-12-13 13:37:11 -06:00
parent 58c74ebc86
commit 7ef7a0bfef
5 changed files with 47 additions and 5 deletions

3
.gitignore vendored
View file

@ -163,3 +163,6 @@ tags
[._]*.un~
# End of https://www.toptal.com/developers/gitignore/api/vim,python
# Binary files
*.bin

View file

@ -25,6 +25,7 @@ static char printBuff[128];
void program();
void dump();
void erase();
void dumpFirts256Bytes() {
byte data;
@ -71,6 +72,9 @@ void loop() {
// Dump the eeprom.
dump();
break;
case 0x02:
// Erase the EEPROM (fill with 0xFF).
erase();
default:
// Ignore invalid commands.
break;
@ -224,6 +228,14 @@ void disableSoftwareProtection() {
delay(10);
}
void erase() {
for (long addr = 0; addr < 32768; addr++) {
writeEEPROM(addr, 0xFF, true);
}
// Ack the operation.
Serial.write(0xFF);
}
void program() {
// For now, the programmer will always write to the whole eeprom.
byte value;
@ -239,8 +251,8 @@ void program() {
}
void dump() {
long startAddress = 0;
long byteCount = 0;
unsigned long startAddress = 0;
unsigned long byteCount = 0;
byte value;
// Wait and read the starting address to dump.
while (Serial.available() < 2);

View file

@ -10,6 +10,7 @@ def get_parsed_args():
program_parser = subparsers.add_parser("program")
dump_parser = subparsers.add_parser("dump")
erase_parser = subparsers.add_parser("erase")
# Parser for the "program" subcommand.
program_parser.add_argument(
@ -58,6 +59,15 @@ def get_parsed_args():
help="Print the dump to the screen after storing it to the file",
action="store_true",
)
# Parser for the erase command .
erase_parser.add_argument(
"-p",
"--port",
help="Serial port where the programmer is located",
required=True,
)
return parser.parse_args()
@ -92,9 +102,7 @@ def dump(args):
address = int(args.start)
byte_count = int(args.byte_count)
# Give a chance to the arduino to reset.
# TODO: Arduino resets by default when opening a serial
# connection, there's ways to avoid this. Investigate more.
# TODO: Avoid arduino autoreset.
print("Waiting for the arduino to reset...")
time.sleep(2)
@ -115,6 +123,23 @@ def dump(args):
print("Done dumping!")
def erase(args):
print("Erasing...")
with serial.Serial(args.port, 115200) as ser:
# TODO: Avoid arduino autoreset.
print("Waiting for the arduino to reset...")
time.sleep(2)
ser.write((2).to_bytes(1, "big"))
# Wait for the ack.
if ser.read() == b"\xFF":
print("Erasing completed!")
else:
print("Erasing failed")
def main():
args = get_parsed_args()
@ -122,6 +147,8 @@ def main():
program(args)
elif args.operation == "dump":
dump(args)
elif args.operation == "erase":
erase(args)
else:
print("Unrecognized command, exiting now...")

Binary file not shown.

Binary file not shown.