SAM4S should have a built-in SAM boot assistant (SAM-BA®). You should be able to use SAM4SProgrammer, something like:
prog = cw.programmers.SAM4SProgrammer
cw.program_target(scope, prog, "/path/to/firmware.hex")
I definitely used that previously with success. It should use the ERASE pin of the SAM4S to first erase it and then use SAM-BA bootloader to load the firmware (over serial).
This thread is talking about a similar issue.
Hopefully that helps, happy glitching ![]()