1
0

P&E_Multilink_USB_Erase_unsecure_hcs12.cmd 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // ver 1.1 (7/7/04)
  2. // HCS12X Core erasing + unsecuring command file:
  3. // These commands mass erase the chip then program the security byte to 0xFE (unsecured state).
  4. // Evaluate the clock divider to set in ECLKDIV/FCLKDIV registers:
  5. DEFINEVALUEDLG "Information required to unsecure the device" "CLKDIV" 0x49 "To unsecure the device, the command script needs \nthe correct value for ECLKDIV/FCLKDIV onchip\nregisters.\nIf the bus frequency is less than 10 MHz, the value\nto store in ECLKDIV/FCLKDIV is equal to:\n \"bus frequency (kHz) / 175\"\n\nIf the bus frequency is higher than 10 MHz, the value\nto store in ECLKDIV/FCLKDIV is equal to:\n \" bus frequency (kHz) / 1400 + 64\"\n(+64 (0x40) is to set PRDIV8 flag)\n\nDatasheet proposed values:\n\nbus frequency\t\tE/FCLKDIV value (decimal)\n\n 16 \tMHz\t\t73\n 8 \tMHz\t\t39\n 4 \tMHz\t\t19\n 2 \tMHz\t\t9\n 1 \tMHz\t\t4\n"
  6. // An average programming clock of 175 kHz is chosen.
  7. // If the oscillator frequency is less than 10 MHz, the value to store
  8. // in ECLKDIV/FCLKDIV is equal to " oscillator frequency (kHz) / 175 ".
  9. // If the oscillator frequency is higher than 10 MHz, the value to store
  10. // in ECLKDIV/FCLKDIV is equal to " oscillator frequency (kHz) / 1400 + 0x40 (to set PRDIV8 flag)".
  11. // Datasheet proposed values:
  12. //
  13. // oscillator frequency ECLKDIV/FCLKDIV value (hexadecimal)
  14. //
  15. // 16 MHz $49
  16. // 8 MHz $27
  17. // 4 MHz $13
  18. // 2 MHz $9
  19. // 1 MHz $4
  20. FLASH RELEASE // do not interact with regular flash programming monitor
  21. //mass erase flash
  22. reset
  23. wb 0x03c 0x00 //disable cop
  24. wait 20
  25. wb 0x100 CLKDIV // set FCLKDIV clock divider
  26. wb 0x104 0xFF // FPROT all protection disabled
  27. wb 0x105 0x30 // clear PVIOL and ACCERR in FSTAT register
  28. wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
  29. wb 0x105 0x02
  30. wb 0x102 0x10 // set the WRALL bit in FTSTMOD to affect all blocks
  31. ww 0x108 0xFFFE
  32. ww 0x10A 0xFFFF
  33. wb 0x106 0x41 // write MASS ERASE command in FCMD register
  34. wb 0x105 0x80 // clear CBEIF in FSTAT register to execute the command
  35. wait 20 // wait for command to complete
  36. //mass erase eeprom
  37. wb 0x110 CLKDIV // set ECLKDV clock divider
  38. wb 0x114 0xFF // EPROT all protection disabled
  39. wb 0x115 0x30 // clear PVIOL and ACCERR in ESTAT register
  40. wb 0x112 0x00 // clear the WRALL bit in FTSTMOD
  41. wb 0x115 0x02
  42. ww 0x118 0x0C00 // write to EADDR eeprom address register
  43. ww 0x11A 0x0000 // write to EDATA eeprom data register
  44. wb 0x116 0x41 // write MASS ERASE command in ECMD register
  45. wb 0x115 0x80 // clear CBEIF in ESTAT register to execute the command
  46. wait 20 // wait for command to complete
  47. //reprogram Security byte to Unsecure state
  48. reset
  49. wb 0x03c 0x00 //disable cop
  50. wait 20
  51. wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
  52. wb 0x105 0x02
  53. wb 0x100 CLKDIV // set FCLKDIV clock divider
  54. wb 0x100 CLKDIV // set FCLKDIV clock divider
  55. wb 0x104 0xFF // FPROT all protection disabled
  56. wb 0x105 0x30 // clear PVIOL and ACCERR in FSTAT register
  57. wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
  58. wb 0x105 0x02
  59. ww 0xFF0E 0xFFFE // write security byte to "Unsecured" state
  60. wb 0x106 0x20 // write MEMORY PROGRAM command in FCMD register
  61. wb 0x105 0x80 // clear CBEIF in FSTAT register to execute the command
  62. wait 20 // wait for command to complete
  63. reset
  64. undef CLKDIV // undefine variable