diff --git a/.gitignore b/.gitignore index dbddb40..7aeaa1f 100644 --- a/.gitignore +++ b/.gitignore @@ -163,3 +163,6 @@ tags [._]*.un~ # End of https://www.toptal.com/developers/gitignore/api/vim,python + +# Binary files +*.bin diff --git a/arduino_programs/arduino_programmer/arduino_programmer.ino b/arduino_programs/arduino_programmer/arduino_programmer.ino index d6e5065..b9e6ac8 100644 --- a/arduino_programs/arduino_programmer/arduino_programmer.ino +++ b/arduino_programs/arduino_programmer/arduino_programmer.ino @@ -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); diff --git a/cli/cli.py b/cli/cli.py index 312eac6..d8ff7cc 100644 --- a/cli/cli.py +++ b/cli/cli.py @@ -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...") diff --git a/cli/dump.bin b/cli/dump.bin deleted file mode 100644 index fdd2a6b..0000000 Binary files a/cli/dump.bin and /dev/null differ diff --git a/cli/program.bin b/cli/program.bin deleted file mode 100644 index e05b194..0000000 Binary files a/cli/program.bin and /dev/null differ