mass_erase_kinetis.tcl 830 B

12345678910111213141516171819202122232425262728293031
  1. # This script performs the mass erase operation for Kinetis targets
  2. # Command mass erase with system reset and core reset
  3. set mdmapControl [cmdwin::reg MDMAP_C -np]
  4. set mdmapControl [expr $mdmapControl | 0x19]
  5. cmdwin::reg MDMAP_C = $mdmapControl
  6. # Release system reset while still holding core reset
  7. set mdmapControl [expr $mdmapControl & 0xFFFFFFF7]
  8. cmdwin::reg MDMAP_C = $mdmapControl
  9. # Wait for the mass erase operation to complete
  10. set done 0
  11. for {set i 0} {$i < 10} {incr i} {
  12. refresh
  13. set mdmapControl [cmdwin::reg MDMAP_C -np]
  14. if {($mdmapControl & 1) == 0} {
  15. set done 1
  16. break;
  17. }
  18. wait 50
  19. }
  20. # Release the core reset
  21. set mdmapControl [expr $mdmapControl & 0xFFFFFFEF]
  22. cmdwin::reg MDMAP_C = $mdmapControl
  23. if {$done} {
  24. puts "OK: Mass erase succeeded"
  25. } else {
  26. puts "Error: Timeout"
  27. }