I have set the flash configuration to protect high address 4K range and no security,
static const UINT8 NV_PROTECT_INIT @0xFF0C = 0xCF;
static const UINT8 NVFSEC_INIT @0xFF0F = 0xFE;
but after download program into mcu, i found the mcu enter security status, BDM debug was not available.
I wrote a program to read the value from address at 0xFF0C and 0xFF0F, and the register FPROT and FSEC, and send out those 4 values, here was the 4 values:
0xFF0C FPROT 0xFF0F FSEC
0xCF 0x7F 0xFE 0xFF.
I'm very confused about this, what happened to mcu?
Try looking for FLASH NOUNSECURE
The problem is that flash on S12XE is ECC protected, you can't write more bits without erase, else ECC check fails. Since CW on every download writes NVSEC with 0xFE, no matter do you specify it in your code or not, ECC for this flash phrase at 0xFF00-0xFF07 fails and MCU automatically engages security. NOUNSECURE will make CW not writing security bits, unless you specify them in your code.