;; reset MCU r ;; select first JTAG device config 0,0 ;; JLink.exe should have cleared the read-protect bits by now ;; HOWEVER: clearing the read-protect bits doesn't clear the SPRMOD bit ;; We need a BB->AA transition on the read-protect to clear SPRMOD ;; check current status mem32 40023C18,1 mem32 40023C14,1 ;;write option bytes keycode w4 40023c08,08192A3B w4 40023c08,4C5D6E7F ;; turn on SPRMOD and read-protect w4 40023c18,8FFF0000 w4 40023c14,8FFFBBE0 ;; write and wait for write to finish w4 40023c14,8FFFBBE2 sleep 500 ;; verify not busy and bits written mem32 40023C0C,1 mem32 40023C18,1 mem32 40023C14,1 ;; turn off SPRMOD and read-protect w4 40023c18,0FFF0000 w4 40023c14,0FFFAAE0 ;; write and wait for write to finish w4 40023c14,0FFFAAE2 sleep 20000 ;; verify not busy and bits written mem32 40023C0C,1 mem32 40023C18,1 mem32 40023C14,1 ;; lock option bytes w4 40023c14,0FFFAAE1 ;; end script exit