Hi
In order to secure the flash of the device, an appropriate value has to be written into the Flash Security Register (FSEC register). Writing to the FSEC register is actually something that is done by the MCU itself, automatically after RESET, and not by the user.
What the user has to do, is to store the value to be written in a parrticular Non-Volatile location. This is a special address in Flash memory and everytime the MCU comes out of RESET, the value at this flash address is automatically loaded into the Flash Security register.
The address in Flash where you have to store this value is typically 0xFF0F. You can check this by consulting your Flash Module chapter in your device's datasheet.
What the user has to do is to declare a constant value and make sure it is included into the S19 and programmed at that address. To know the value to write, again please check the FSEC register description in your datasheet. Typically, the two least significant bits in this register determine whether the MCU is secured or not. These bits are called SEC1 and SEC0 and securing your device is equivalent to writing a good value into these bits. What is a good value? One thing to know is that, whatever value you write, the BDM programmer will automatically unsecure your device. This is necessary for the BDM to erase and program your device's Flash. Of the 4 possible combinations of SEC1 and SEC0, only one represents an unsecure state. So the BDM will wite this value, which is value 1-0. SEC1 = 1. SEC0 = 0.
After this is done, your S19 will be programmed, and eventually whatever value you wrote will be written again into SEC1, SEC0. Because SEC0 is already at value zero, the other securing value that does not conflict with this is to set SEC1=0, SEC0=0. (a bit already set to zero cannot be set back to one, the inverse, however, is possible) So I do recommend that you use the value SEC1=0 SEC0=0 to secure your device. A resulting useful value for the register is FSEC= 0xF0.
To declare such a value, in your code you have to declare a constant. Under CodeWarror, the syntax would be :
const unsigned char myvalue@0xFF0F = 0xF0;
For more information, I suggest you refer reference manual, search “Flash Security Register(FSEC)”
if you want to use back door key, please refer an2880
https://www.nxp.com/docs/en/application-note/AN2880.pdf
the demo code an2880sw
software for AN2880
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------