I want the flash memory to be inaccessible for reading, at least in a specific area were confidential data reside.
In order to achieve this, I write 0xFF (or 0xFD or 0xFC) in the least significant byte of the FTFA_SEC register, all these values, different from 0xFE, should configure in secure mode, as explained in section 27.3.1 Flash Configuration Field Description in RM of KL03.
One method I use is acting on startup_MKL03Z4.s file ,changing last word ,as showed below
/* Flash Configuration */
.section .FlashConfig, “a”
.long 0xFFFFFFFF
.long 0xFFFFFFFF
.long 0xFFFFFFFF
.long 0xFFFF3DFE //will be 0xFFFF3DFF
Other method is inside the .c files ,initializing FlashConfig
_attribute__ ((used,section(".FlashConfig"))) const struct {
unsigned int word1;
unsigned int word2;
unsigned int word3;
unsigned int word4;
} Flash_Config = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x**FFFF3DFF**};
Imagining myself as an intruder who wants to spy on the data inside the flash memory and for clarity ,I will limit myself to the area 0x3800 0x3BFF, the sector where I have written the most confidential data. Let’s write a new project, but this time with Flash configuration in non-secure mode(0xFFFF3DFE). The Multilink Universal programmer allows you not to erase flash memory areas during programming, if you use the following setting: Debug Configurations -> Debugger-> Advanced Options-> Preserve this range 0x3B00 -0x3BFF. What happens is that simply by using this option it is possible to keep the selected memory area unchanged, and I can see the code written by the previous program.
I want to avoid this, I want that, despite the 0x3800-0x3BFF area could be selected as preserved, its content appears not readable unless it is erased, resulting filled by 0xFF .How can this be achieved?