Hi, I want the following to be done once I have flashed the program into the micro-controller. I am using TWR-KV46F150M evaluation board. These are the requirements that I am looking for when I say lock and unlock.
1. When the lock is enabled, the micro should not be able to erase the old code and flash new one when tried.
2. When lock is enabled, the micro doesn't let another person to read the information that is flashed before it was locked.
3. After the unlock is done, micro is as good as new and would allow the read/erase the previous flashed code.
do I have to change the clock settings for this? How will I be able to achieve it? Regards
已解决! 转到解答。
Hi,
Section 32.4.1 in reference manual has the detail.
To unlock, Verify Backdoor Access Key command should be send. Section 32.5.10.10 has the detail. If the chip is locked, only firmware can do it.
Regards,
Jing
Hi soaring_sun,
About your requirement,
1. Yes, please use FRFA_FPROT register (Program Flash Protection Registers), the detail is in section 33.4.3.6 in RM.
2. If you mean you want to disable SWD/JTAG port, Please use FSEC[SEC] bits. During the reset sequence, the register is loaded with the contents of the flash security byte in the Flash Configuration Field(0x40C) located in program flash memory.
3. FSEC[KEYEN] controls backdoor. By input correct backdoor key, flash can be unlocked.
You needn't change clock settings for these functions.
Regards,
Jing
Hi @jingpan
1. I am referring to the following TRM and the section which you mentioned 33.4.3.6 doesn't exist in this. For this particular micro controller, how should I go on about the locking?
https://www.nxp.com/webapp/sps/download/preDownload.jsp?render=true
2. When I disable the SWD/JTAG, how will I be able to unlock it once the locking process it complete? Since the SWD/JTAG is already disabled.
Hi @jingpan
I went through the documents and I have a fair idea of how it works. Do you have an example code for the same MKV46F256VLL16 board in which I will be able to lock and unlock effectively?
Regards
Hi,
It's very easy to lock and unlock. This control register's initial value is stored in flash address 0x400. When you want to change them, just modify the startup_kv46f16.s. It is at line 48
__attribute__ ((used,section(".FlashConfig"))) const struct {
unsigned int word1;
unsigned int word2;
unsigned int word3;
unsigned int word4;
} Flash_Config = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE};
After you modify it, build the project and download, the setting will take effect immediately.
Regards,
Jing
Hi @jingpan
So, in the startup_kv46f16.s at line 48,
0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE will be the password that corresponds to the four sections? So, when I have to lock them, I could change the above four to my password and lock them.
For unlocking, the same password should be written on the same four flash config and with programming that, it would unlock.
Is my understanding right?
Thanks and regards
Hi,
Section 32.4.1 in reference manual has the detail.
To unlock, Verify Backdoor Access Key command should be send. Section 32.5.10.10 has the detail. If the chip is locked, only firmware can do it.
Regards,
Jing