This is to inform anyone else that encounters this problem.
I was trying to read the program once registers located in the FTFE device.
When I tried accessing the FTFE device from a bareboard application I could read the registers without a problem, but when I tried accessing them from a MQX application I couldn't.
After debugging this problem for a few days it turns out the the FTFE device cannot be accessed when the MCU is set to run in HSRUN mode.
The FlashX driver does not have any mechanism to work around this problem so every access to the FTFE device in HSRUN mode will end up in error.
It turns out there is a function to set a different operation mode called _bsp_set_operation_mode.
There is one problem with it. It will only set HSRUN mode correctly, but not RUN mode.
In the HSRUN case there is this line:
SMC_PMCTRL |= (uint8_t)0x60UL;
There should be a similar line in the RUN case clearing those same bits:
SMC_PMCTRL &= (uint8_t)~0x60UL;
Finally, there is another problem I found in the FTFE device that won't let you write single bytes to it.
In the K60 there is a FTFL device. I could write single bytes to it (assuming those bytes are erased). With the K66 there is no way of writing single bytes.
The only way to write to the FTFE device is in blocks of 8 bytes. When trying to write a single byte the driver tries to set that byte to whatever value chosen. If there are bytes written in that block of 8 before it, the write will fail and lockup the device.
I think this sums up my last few days of working on the new K66 with the FTFE device...
I wouldn't disable the HSRUN altogether - that may impact the overall performance of your system.
You should just disable HSRUN for the period of flash access.
curmode = _lpm_get_operation_mode();
// Do your flash operations here
_lpm_set_operation_mode(curmode); //return to previous run mode