RT1052 how to achieve the ability to save code on a flash and read and write falsh free space
this may help you.
https://www.nxp.com/docs/en/nxp/application-notes/AN12238.pdf
FYI. More AN can be downloaded from here:
i.MX RT1050 MCU/Applications Crossover Processor | Arm® Cortex®-M7 @600 MHz, 512KB SRAM |NXP