Merge pull request #4 from AYM1607/feature/erase

Added the erase command to fill the EEPROM with 0xFF
This commit is contained in:
Mariano Uvalle 2020-12-13 13:41:18 -06:00 committed by GitHub
commit adc5e6a078
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 5 deletions

3
.gitignore vendored
View file

@ -163,3 +163,6 @@ tags
[._]*.un~ [._]*.un~
# End of https://www.toptal.com/developers/gitignore/api/vim,python # 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 program();
void dump(); void dump();
void erase();
void dumpFirts256Bytes() { void dumpFirts256Bytes() {
byte data; byte data;
@ -71,6 +72,9 @@ void loop() {
// Dump the eeprom. // Dump the eeprom.
dump(); dump();
break; break;
case 0x02:
// Erase the EEPROM (fill with 0xFF).
erase();
default: default:
// Ignore invalid commands. // Ignore invalid commands.
break; break;
@ -224,6 +228,14 @@ void disableSoftwareProtection() {
delay(10); delay(10);
} }
void erase() {
for (long addr = 0; addr < 32768; addr++) {
writeEEPROM(addr, 0xFF, true);
}
// Ack the operation.
Serial.write(0xFF);
}
void program() { void program() {
// For now, the programmer will always write to the whole eeprom. // For now, the programmer will always write to the whole eeprom.
byte value; byte value;
@ -239,8 +251,8 @@ void program() {
} }
void dump() { void dump() {
long startAddress = 0; unsigned long startAddress = 0;
long byteCount = 0; unsigned long byteCount = 0;
byte value; byte value;
// Wait and read the starting address to dump. // Wait and read the starting address to dump.
while (Serial.available() < 2); while (Serial.available() < 2);

View file

@ -10,6 +10,7 @@ def get_parsed_args():
program_parser = subparsers.add_parser("program") program_parser = subparsers.add_parser("program")
dump_parser = subparsers.add_parser("dump") dump_parser = subparsers.add_parser("dump")
erase_parser = subparsers.add_parser("erase")
# Parser for the "program" subcommand. # Parser for the "program" subcommand.
program_parser.add_argument( 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", help="Print the dump to the screen after storing it to the file",
action="store_true", 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() return parser.parse_args()
@ -92,9 +102,7 @@ def dump(args):
address = int(args.start) address = int(args.start)
byte_count = int(args.byte_count) byte_count = int(args.byte_count)
# Give a chance to the arduino to reset. # TODO: Avoid arduino autoreset.
# TODO: Arduino resets by default when opening a serial
# connection, there's ways to avoid this. Investigate more.
print("Waiting for the arduino to reset...") print("Waiting for the arduino to reset...")
time.sleep(2) time.sleep(2)
@ -115,6 +123,23 @@ def dump(args):
print("Done dumping!") 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(): def main():
args = get_parsed_args() args = get_parsed_args()
@ -122,6 +147,8 @@ def main():
program(args) program(args)
elif args.operation == "dump": elif args.operation == "dump":
dump(args) dump(args)
elif args.operation == "erase":
erase(args)
else: else:
print("Unrecognized command, exiting now...") print("Unrecognized command, exiting now...")

Binary file not shown.

Binary file not shown.