Below is part of the config tool generated init code (SDK14.0, flexspi peripheral drivers 2.5.0) which does not work.
static void FLEXSPI2_init(void) {
/* FLEXSPI2 peripheral initialization */
FLEXSPI_Init(FLEXSPI2_PERIPHERAL, &FLEXSPI2_config);
/* Update LUT table. */
FLEXSPI_UpdateLUT(FLEXSPI2_PERIPHERAL, 0, FLEXSPI2_LUT, FLEXSPI2_LUT_LENGTH);
/* Configure flash settings according to serial flash feature. */
FLEXSPI_SetFlashConfig(FLEXSPI2_PERIPHERAL, &FLEXSPI2_config_Device_0, kFLEXSPI_PortA1);
}
The problem is the MCR0->MDIS bit is set to 1 in the FLEXSPI_Init function, which means the FLEXSPI is in stop mode. The LUT registers are unaccessible under that mode according to the reference manual, causing the write to LUT registers fails in the FLEXSPI_UpdateLUT function.
It can be fixed by simply changing the executing sequence of the init functions because the MCR0->MDIS bit is set to 0 in the FLEXSPI_SetFlashConfig function:
static void FLEXSPI2_init(void) {
/* FLEXSPI2 peripheral initialization */
FLEXSPI_Init(FLEXSPI2_PERIPHERAL, &FLEXSPI2_config);
/* Configure flash settings according to serial flash feature. */
FLEXSPI_SetFlashConfig(FLEXSPI2_PERIPHERAL, &FLEXSPI2_config_Device_0, kFLEXSPI_PortA1);
/* Update LUT table. */
FLEXSPI_UpdateLUT(FLEXSPI2_PERIPHERAL, 0, FLEXSPI2_LUT, FLEXSPI2_LUT_LENGTH);
}
But I think modifying the UpdateLUT function itself may be a better solution:
1. Save the MDIS bit state
2. Clear the MDIS bit
3. Write LUT registers
4. Restore the MDIS bit state
This assures the independency of this function, eliminating the risk of accidentally mess up with other steps in the initiating process.