Board - iMXRT1040-EVK, SDK - mcuXpresso SDK v25.03.00, Windows, McuXpresso IDE
Hi,
I am trying to read data from the external NOR Flash on the EVK. I am using the flexspi nor edma example, but instead of using memcpy to read data I want to use "flexspi_nor_read_data()" function. Below is my code:
int main(void)
{
...
status = flexspi_nor_read_data( EXAMPLE_FLEXSP, (EXAMPLE_FLEXSPI_AMBA_BASE + EXAMPLE_SECTOR * SECTOR_SIZE),(void*)s_nor_read_buffer,sizeof(s_nor_read_buffer));
if (memcmp(s_nor_read_buffer, s_nor_program_buffer, sizeof(s_nor_program_buffer)) != 0)
{
PRINTF("Program data - read out data value incorrect !\r\n ");
return -1;
}
else
{
PRINTF("Program data - successfully. \r\n");
}
...
}
status_t flexspi_nor_read_data(FLEXSPI_Type *base, uint32_t startAddress, uint32_t *buffer, uint32_t length)
{
...
g_completionFlag = false;
status = FLEXSPI_TransferEDMA(base, &flexspiHandle, &flashXfer);
if (status != kStatus_Success)
{
return status;
}
/* Wait for transfer completed. */
while (!g_completionFlag)
{
}
...
}
The program goes to an infinite loop at while (!g_completionFlag) and I am getting status as 7002 as a return value from "FLEXSPI_TransferEDMA()"
I also tried the flexspi polling example, but getting the same output.
Why would the read function not work but we are able to read using memcpy?
Thanks
Solved! Go to Solution.
I found the problem. I was sending incorrect address to the read function. Modified code for calling the flexspi_nor_read_data() is below.
main()
{
...
status = flexspi_nor_read_data( EXAMPLE_FLEXSPI,
(EXAMPLE_SECTOR * SECTOR_SIZE),
(void *)s_nor_read_buffer,
sizeof(s_nor_read_buffer));
...
}
Thanks
I found the problem. I was sending incorrect address to the read function. Modified code for calling the flexspi_nor_read_data() is below.
main()
{
...
status = flexspi_nor_read_data( EXAMPLE_FLEXSPI,
(EXAMPLE_SECTOR * SECTOR_SIZE),
(void *)s_nor_read_buffer,
sizeof(s_nor_read_buffer));
...
}
Thanks
By further debugging I found out when flexspi_nor_read_data() is called the EDMA IRQ Rx handler DMA1_DMA17_DriverIRQHandler() does not get called. However when reading chip ID using flexspi_nor_get_vendor_id() the DMA1_DMA17_DriverIRQHandler() is called and the read is successful. Modified flexspi_nor_get_vendor_id() is shown below. Any help is highly appreciated.
status_t flexspi_nor_get_vendor_id(FLEXSPI_Type *base, uint8_t *vendorId)
{
uint32_t temp;
flexspi_transfer_t flashXfer;
flashXfer.deviceAddress = 0;
flashXfer.port = kFLEXSPI_PortA1;
flashXfer.cmdType = kFLEXSPI_Read;
flashXfer.SeqNumber = 1;
flashXfer.seqIndex = NOR_CMD_LUT_SEQ_IDX_READID;
flashXfer.data = &temp;
flashXfer.dataSize = 1;
status_t status;
status = FLEXSPI_TransferEDMA(base, &flexspiHandle, &flashXfer);
if (status != kStatus_Success)
{
return status;
}
/* Wait for transfer completed. */
while (!g_completionFlag)
{
}
*vendorId = temp;
/* Do software reset or clear AHB buffer directly. */
#if defined(FSL_FEATURE_SOC_OTFAD_COUNT) && defined(FLEXSPI_AHBCR_CLRAHBRXBUF_MASK) && \
defined(FLEXSPI_AHBCR_CLRAHBTXBUF_MASK)
base->AHBCR |= FLEXSPI_AHBCR_CLRAHBRXBUF_MASK | FLEXSPI_AHBCR_CLRAHBTXBUF_MASK;
base->AHBCR &= ~(FLEXSPI_AHBCR_CLRAHBRXBUF_MASK | FLEXSPI_AHBCR_CLRAHBTXBUF_MASK);
#else
FLEXSPI_SoftwareReset(base);
#endif
return status;
}
Thanks