Hi,
I'm working with S32K116 microcontrollers, trying to set the MCU in secure mode and later switch it to unsecure mode using the backdoor key, as described in the S32K Reference Manual in section 36.5.12.2.1. To do this, I have a code where the first step is modifying the startup_S32K116.S file by adding the backdoor key in the flash configuration section and setting the FSEC to 0xF instead of 0xE at the end, to put the MCU in secure mode. Here's an example in the following image:

Then, I create a function to update the FCCOB register, as described in the manual, to check if the key is correct and switch the MCU back to unsecure mode:

Finally, in my main function, I ensure that a message is sent via UART at the start of the program, indicating that the MCU is in secure mode. Then, it calls the key verification function and sends another UART message showing the current status.

I first flashed the program in unsecure mode to verify that it worked and sent the messages via UART. Then, I flashed it in secure mode, but nothing happened, and I could no longer flash the MCU again.
Why isn't it working?
Best regards, and thank you in advance.