I'm attempting to flash the SPIFI chip from a plain image application (in SRAMX) but execution is getting stuck in SPIFI_Init() -> SPIFI_ResetCommand() because the RESET flag in the STAT register is not being cleared by hardware.
I'm using the latest 2.7.0 SDK in MCUXpresso 11.1.1_3241.
Here's how I'm trying to initialize the SPIFI interface (pins should already be set up from BOARD_InitPins):
spifi_config_t config = {0};
uint32_t sourceClockFreq;
RESET_PeripheralReset(kSPIFI_RST_SHIFT_RSTn);
CLOCK_AttachClk(kFRO_HF_to_SPIFI_CLK);
sourceClockFreq = CLOCK_GetSpifiClkFreq();
CLOCK_SetClkDiv(kCLOCK_DivSpifiClk, sourceClockFreq / FLASH_BAUDRATE, false);
CLOCK_EnableClock(kCLOCK_Spifi);
SPIFI_GetDefaultConfig(&config);
SPIFI_Init(SPIFI0, &config);
Here's the SPIFI_ResetCommand() code it's getting stuck on (part of the SDK - but just to show it's the same):
static inline void SPIFI_ResetCommand(SPIFI_Type *base)
{
base->STAT = SPIFI_STAT_RESET_MASK;
/* Wait for the RESET flag cleared by HW */
while ((base->STAT & SPIFI_STAT_RESET_MASK) != 0x00U)
{
}
}
What could cause the RESET flag to not be cleared?
Update: just to add some part numbers, I'm using LPC54016 - LQFP100 and AT25SF081-SSHD flash. FLASH_BAUDRATE has been reduced down to 24Mhz (#define FLASH_BAUDRATE (24000000)) for testing.
Hi Peter - this is probably a long shot since this thread is several years old at this point - but did this ever get resolved?
We are having similar issues with that flash part and an LPC54608.
Thanks!
After going back to the SPIFI Polling Transfer driver example project (for the LPC54018 but I swapped out the CPU definitions) I noticed the call to CLOCK_GetSpifiClkFreq should actually have been CLOCK_GetFroHfFreq. However now it's getting stuck again reading the status here:
inline static char FlashGetStatus(void) {
SPIFI_SetCommand(SPIFI0, &StFlashCommands[GET_STATUS]);
while ((SPIFI0->STAT & SPIFI_STAT_INTRQ_MASK) == 0U) { }
return SPIFI_ReadDataByte(SPIFI0);
}
I've tried adding:
SPIFI_EnableInterrupt(SPIFI0, kSPIFI_CommandFinishInterruptEnable);
During initialization but this hasn't helped - although this isn't called in the example project. I've tried comparing the initialization process between the projects, but I can't find any noticeable difference. I've also tried comparing the IOCON registers at the same point in both projects, but there's no difference apart from the reserved 10 bit being set in my project (I'm not sure why this is happening, I used the code generation for the pin setup and after BOARD_InitBootPins() the IOCON isn't touched by my code).
Here's the initialization in my main project:
static char FlashInitInternal(void) {
uint32_t sourceClockFreq;
spifi_config_t config = {0};
RESET_PeripheralReset(kSPIFI_RST_SHIFT_RSTn);
CLOCK_AttachClk(kFRO_HF_to_SPIFI_CLK);
sourceClockFreq = CLOCK_GetFroHfFreq();
CLOCK_SetClkDiv(kCLOCK_DivSpifiClk, sourceClockFreq / FLASH_BAUDRATE, false);
SPIFI_GetDefaultConfig(&config);
SPIFI_Init(SPIFI0, &config);
/* Enable quad transfer */
char prev_status = FlashGetStatus();
SPIFI_SetCommand(SPIFI0, &StFlashCommands[WRITE_ENABLE]);
SPIFI_SetCommand(SPIFI0, &StFlashCommands[WRITE_REGISTER]);
SPIFI_WriteDataByte(SPIFI0, prev_status);
SPIFI_WriteDataByte(SPIFI0, QUAD_ENABLE);
FlashWaitForCompletion();
FlashReadMode();
return 0;
}
inline static char FlashGetStatus(void) {
SPIFI_SetCommand(SPIFI0, &StFlashCommands[GET_STATUS]);
while ((SPIFI0->STAT & SPIFI_STAT_INTRQ_MASK) == 0U) { }
return SPIFI_ReadDataByte(SPIFI0);
}
inline static void FlashReadMode(void)
{
SPIFI_ResetCommand(SPIFI0);
SPIFI_SetMemoryCommand(SPIFI0, &StFlashCommands[READ]);
}
And here's the initialization in the example project:
RESET_PeripheralReset(kSPIFI_RST_SHIFT_RSTn);
/* Set SPIFI clock source */
CLOCK_AttachClk(kFRO_HF_to_SPIFI_CLK);
sourceClockFreq = CLOCK_GetFroHfFreq();
/* Set the clock divider */
CLOCK_SetClkDiv(kCLOCK_DivSpifiClk, sourceClockFreq / EXAMPLE_SPI_BAUDRATE, false);
/* Initialize SPIFI */
SPIFI_GetDefaultConfig(&config);
SPIFI_Init(SPIFI0, &config);
char prev_status;
SPIFI_SetCommand(SPIFI0, &command[GET_STATUS]);
while ((SPIFI0->STAT & SPIFI_STAT_INTRQ_MASK) == 0U)
{
}
prev_status = SPIFI_ReadDataByte(EXAMPLE_SPIFI);
SPIFI_SetCommand(SPIFI0, &command[WRITE_ENABLE]);
SPIFI_SetCommand(SPIFI0, &command[WRITE_REGISTER]);
SPIFI_WriteDataByte(SPIFI0, prev_status);
SPIFI_WriteDataByte(SPIFI0, QUAD_ENABLE);
check_if_finish();
SPIFI_SetMemoryCommand(SPIFI0, &command[READ]);
Hello Peter,
How do you config the spifi_command refer to your flash chip ?
Refer to UM of LPC54016 and data sheet of AT25SF081-SSHD flash to check whether config well.