I have a doubt about the Address of FSEC byte mentioned in the reference manual for MKE02Z64VLD2.
According to the manual snippet above, the following flash configuration should secure the MCU;
But that is not true, the above code gives me the following FTMRH register read out;
My FSEC value of 0x7D shows up in the FPROT register instead!
I know that while I am in debug mode the MCU is unsecured, hence I will only see FSEC as 0xFE, but the 0x7D should not go to the FPROT address.
But, If I use the following Flash Config, then it appears to secure the MCU correctly;
This only means one thing that the address description in the manual is
incorrect correct but my interpretation is incorrect.
Please check the binary file that you are loading to verify that the bytes are at the correct locations in it.
Beware that some debuggers don't allow programming of the values in the image without first unlocking this function (for safety reasons so that people don't inadvertently lock chips).
If you secure the device I expect that after a further reset it would no longer be possible to connect with the debugger to view the registers.
I would recommend testing patterns that don't secure the flash (also in the unused 0x408..0x40b area) and reading them back directly from the flash so that you are sure they are programmed as expected before interpreting the values seen in the FTMRH registers.