Just tried the new script. We are making progress, and the error message changes as follows.
Uploading 'Statechart_middleware_SAMD_ino' to 'Adafruit Metro M4 (SAMD51) (adafruit_adafruit_metro_m4)' using 'Atmel ICE over OpenOCD (vMicro)'
Open On-Chip Debugger 0.10.0+dev-01058-g853a05287 (2020-02-13-16:41)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html debug_level: 0
swd
****[vMicro]**** Uploading ELF :target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x0000058c msp: 0x2000d6a0
Error during upload using programmer
The uploader process failed
The uploader process failed
The uploader returned an error
** Programming Started **
Error: SAM: NVM lock error
Error: SAM: NVM programming error
Error: Failed to erase block containing 00000000
Error: SAM: failed to erase sector 0 at 0x00000000
Error: failed erasing sectors 0 to 9
embedded:startup.tcl:510: Error: ** Programming Failed **
in procedure 'program'
in procedure 'program_error' called at file "embedded:startup.tcl", line 575
at file "embedded:startup.tcl", line 510