Hi,
the question is whether the MCU is secured or flash is protected. (see Flash Protection/Security Field in the data sheet)
1) If protected: FPROT can't be reprogrammend. The only protection byte stored in flash can be reprogrammed. This byte is automatically copied into FPROT register during reset. Then just reset the MCU and the flash is unprotected.
2) If secured: In this case the only possibility how to make internal resources accessible is to mass erase the MCU. For this purpse you can use without any problems CodeWarrior debuger or www.pemicro.com unsecure12. These two tools can help you to unsecure the MCU and you do not want to use your own code. However, the content of lost.
The device is after mass errase secured. Then after reset the content of the address FF0F is copied to the FSEC register. The content of the address 0xFF0F after mass erase is 0xFF which, using FSEC register pattern sets bits SEC to 11 which means the device is secured. So, if you want to be able to use device after mass erase you have to program the address 0xFF0F to the value which has bits SEC set to the value 10 unsecured. (Flash Security Register (FSEC)). This is the only way how to unsecure the device because all bits in the FSEC register are readable but are not writable.
Another way how to unsecure the device is to use unsecure command from CodeWarrior debugger or unsecure program from www.pemicro.com pages.
If you use USB multilink you have to use unsecure Option MultilinkCyclonePro->Unsecure in the CodeWarrior Hiwave Debugger.
or you can use external usecure program which can be downloaded from pemicro pages.
Unsecure_12 (8060 KB): Utility which unsecures HCS12 devices via P&E's BDM Interfaces such as Cyclone-PRO, USB-ML-12, and BDM-Multilink. .
http://www.pemicro.com/downloads/download_file.cfm?download_id=16
Unsecure_12 Help Files (20 KB) This .hlp file describes the use and operationg of the Unsecure_12 program which is used with P&E's interface devices to unsecure proeviously secured HCS12 microcontrollers.
http://www.pemicro.com/downloads/download_file.cfm?download_id=14
memories will be erased.
If you want to do it youurself then you can use as a clue command file which can be found in the p&e_erase_unsecure_hcs12.cmd command file of the CodeWarrior. The CodeWarrior (standard edition) can be downloaded from Fresscale pages and works like proffesional for 30 days. Then it has some limitations.
A content of p&e_erase_unsecure_hcs12.cmd command file is:
// ver 1.1 (7/7/04)
// HCS12X Core erasing + unsecuring command file:
// These commands mass erase the chip then program the security byte to 0xFE (unsecured state).
// Evaluate the clock divider to set in ECLKDIV/FCLKDIV registers:
// An average programming clock of 175 kHz is chosen.
// If the oscillator frequency is less than 10 MHz, the value to store
// in ECLKDIV/FCLKDIV is equal to " oscillator frequency (kHz) / 175 ".
// If the oscillator frequency is higher than 10 MHz, the value to store
// in ECLKDIV/FCLKDIV is equal to " oscillator frequency (kHz) / 1400 + 0x40 (to set PRDIV8 flag)".
// Datasheet proposed values:
//
// oscillator frequency ECLKDIV/FCLKDIV value (hexadecimal)
//
// 16 MHz $49
// 8 MHz $27
// 4 MHz $13
// 2 MHz $9
// 1 MHz $4
define CLKDIV 0x49
FLASH RELEASE // do not interact with regular flash programming monitor
//mass erase entire flash – all flash blocks
reset
wb 0x03c 0x00 //disable cop
wait 20
wb 0x100 CLKDIV // set FCLKDIV clock divider
wb 0x104 0xFF // FPROT all protection disabled
wb 0x105 0x30 // clear PVIOL and ACCERR in FSTAT register
wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
wb 0x105 0x02
wb 0x102 0x10 // set the WRALL bit in FTSTMOD to affect all blocks
ww 0x108 0xFFFE
ww 0x10A 0xFFFF
wb 0x106 0x41 // write MASS ERASE command in FCMD register
wb 0x105 0x80 // clear CBEIF in FSTAT register to execute the command
wait 20 // wait for command to complete [tenths of seconds]
//mass erase eeprom
wb 0x110 CLKDIV // set ECLKDV clock divider
wb 0x114 0xFF // EPROT all protection disabled
wb 0x115 0x30 // clear PVIOL and ACCERR in ESTAT register
wb 0x112 0x00 // clear the WRALL bit in FTSTMOD
wb 0x115 0x02
ww 0x118 0x0C00 // write to EADDR eeprom address register
ww 0x11A 0x0000 // write to EDATA eeprom data register
wb 0x116 0x41 // write MASS ERASE command in ECMD register
wb 0x115 0x80 // clear CBEIF in ESTAT register to execute the command
wait 20 // wait for command to complete
//reprogram Security byte to Unsecure state
reset
wb 0x03c 0x00 //disable cop
wait 20
wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
wb 0x105 0x02
wb 0x100 CLKDIV // set FCLKDIV clock divider
wb 0x100 CLKDIV // set FCLKDIV clock divider
wb 0x104 0xFF // FPROT all protection disabled
wb 0x105 0x30 // clear PVIOL and ACCERR in FSTAT register
wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
wb 0x105 0x02
ww 0xFF0E 0xFFFE // write security byte to "Unsecured" state
wb 0x106 0x20 // write MEMORY PROGRAM command in FCMD register
wb 0x105 0x80 // clear CBEIF in FSTAT register to execute the command
wait 20 // wait for command to complete
reset
undef CLKDIV // undefine variable
Best regards,
Ladislav