How to write and read from qspi flash ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to write and read from qspi flash ?

Jump to solution
4,776 Views
bjargalsaikhan
Contributor II

Hello, I am new to NXP products.

I am using MIMXRT1062DVL6A development board. 

The board has the qspi flash built into it. And I am able to boot from the flash. 

And inside my linker file, I allocated some region inside my flash. 

I just wanted to write something and read back from the qspi flash. 

1) What API's should I use? whether it is fsl_qspi, fsl_flexspi, or just regular spi? 

2) if it is possible could you direct me to the quick start or general documentation of a proper one?

Thank you very much.

Labels (2)
1 Solution
4,197 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Baasanjav Jargalsaikhan,

Thank you for your interest in NXP Semiconductor products and
for the opportunity to serve you.
1) What API's should I use? whether it is fsl_qspi, fsl_flexspi, or just regular spi?
-- You should use the FlexSPI ROM API driver.
2) if it is possible could you direct me to the quick start or general documentation of a proper one?
-- I've attached sample code for you to refer to, please check it.

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

13 Replies
4,197 Views
bjargalsaikhan
Contributor II

I got it working without initializing flexspi from the bootloader. Thank you for your advice jeremyzhou

0 Kudos
4,198 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Baasanjav Jargalsaikhan,

Thank you for your interest in NXP Semiconductor products and
for the opportunity to serve you.
1) What API's should I use? whether it is fsl_qspi, fsl_flexspi, or just regular spi?
-- You should use the FlexSPI ROM API driver.
2) if it is possible could you direct me to the quick start or general documentation of a proper one?
-- I've attached sample code for you to refer to, please check it.

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

4,197 Views
t_thurgood
Contributor III

Hi Jeremy Zhou,

I am engaged on a project using the MIMXRT1021 with xip QSPI flash (MX25L3233).

Can you please explain the setup using this MCU when implementing a small NV data store in flash memory.

My understanding is, that we will need to execute the access functions from I-TCM?

Our IDE is IAR Workbench. Do you have an application note/example project for the 1021 explaining how to do this?

Also we would like to be able to update the firmware image, i.e. dual banked flash code memory. We have a TCP/IP LAN connection.

What is the best way to achieve this feature with the xip qspi configuration (page writing etc).?

If anyone has implemented this kind of thing on the 1021, please help.

best regards,

Tony

0 Kudos
4,197 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Tony Thurgood

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
For RT1021, it doesn't support the FlexSPI ROM API driver, however, you can consider using the FlexSPI driver from the SDK library,
You can find it in the flexspi demo project in the above library.
To implement it, the FlexSPI driver function should run in the RAM such as the I-TCM prior to doing the flash operation likes the erase and program, otherwise, it will trigger the hardfault interrupt.
Hope it helps.

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
4,197 Views
t_thurgood
Contributor III

Hi Jeremy,

Thank you for your prompt reply.

Can you please tell me where I can find the SDK library/FlexSPI driver.

I found this driver folder, but that is for 1050 and EcoXiP... C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.3\arm\src\flashloader\NXP\FlashIMXRT1050_EVK_EcoXiP\drivers\fsl_flexspi.c

Perhaps we are missing a support package?

best regards,

Tony

0 Kudos
4,197 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Tony Thurgood

Thanks for your reply.

Please go to download the SDK library via the below link.
https://mcuxpresso.nxp.com/en/welcome

Hope it helps.

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
4,197 Views
bjargalsaikhan
Contributor II

Hello Jeremy Zhou,

Thank you very much for your help and generosity.

When the code executes flexspi_nor_flash_erase function, I am getting this error which is shown on the picture.

If it possible could you tell me what is going wrong?

my macros are:

#define FLASH_BASE_ADDR 0x60000000
#define FLASH_INSTANCE FLEXSPI_INSTANCE

#define TEST_OFFSET 0x800000
#define TEST_LENGTH 0x100
#define CONFIG_OPTION 0xc0000007

Capture.PNG

Otherwise, I am able to read from memory, by commenting out flexspi_nor_flash_erase function.

Thank you very much for your time. 

0 Kudos
4,197 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Baasanjav Jargalsaikhan,

Thanks for your reply.
Whether you can share the testing code you run, in addition,  I'd like to know what board you use for testing.

Looking forward to your reply.
Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
4,197 Views
bjargalsaikhan
Contributor II

Hello, jeremyzhou

I am using MIMXRT1060-EVK board: i.MX RT1060 Evaluation Kit | NXP 

The code that I am using for testing is the same as the example code, which it executes erase function and read back. 

Test code: When it reaches the bolded section it gives an error above. If I comment it out and try to read everything is fine.

printf("Initializing ROM API...\n");
bl_api_init();

clock_init();

printf("Test Flash driver APIs...\n");

uint8_t *pBufStart = (uint8_t *)programBuffer;
for (uint32_t i = 0; i < sizeof(programBuffer); i++)
{
*pBufStart++ = (uint8_t)(i & 0xFF);
}

configOption.option0.U = CONFIG_OPTION;

status_t status = flexspi_nor_get_config(FLASH_INSTANCE, &flashConfig, &configOption);
if (status != kStatus_Success)
{
printf("Flash get configuration failed\n");

}
else
{
printf("Flash get configuration passed\n");
}

status = flexspi_nor_flash_init(FLASH_INSTANCE, &flashConfig);
if (status != kStatus_Success)
{
printf("Flash initialization failed\n");

}
else
{
printf("Flash initialization passed\n");
}

status = flexspi_nor_flash_erase(FLASH_INSTANCE, &flashConfig, TEST_OFFSET, TEST_LENGTH);
if (status != kStatus_Success)
{
printf("Flash erase failed\n");
return;
}
else
{
printf("Flash erase passed\n");
}

flexspi_nor_flash_read(FLASH_INSTANCE, &flashConfig, verifyBuffer, TEST_OFFSET, sizeof(programBuffer));
bool hasErased = true;
for (uint32_t i = 0; i < ARRAY_SIZE(verifyBuffer); i++)
{
if (verifyBuffer[i] != 0xffffffffu)
{
hasErased = false;
break;
}
}
if (hasErased)
{
printf("Flash erase verify passed\n");
}
else
{
printf("Flash erase verify failed\n");
return;
}

status = flexspi_nor_flash_page_program(FLASH_INSTANCE, &flashConfig, TEST_OFFSET, programBuffer);
if (status != kStatus_Success)
{
printf("Flash program failed\n");
return;
}
else
{
printf("Flash program passed\n");
}
// Verify
flexspi_nor_flash_read(FLASH_INSTANCE, &flashConfig, verifyBuffer, TEST_OFFSET, sizeof(programBuffer));
if (memcmp(verifyBuffer, programBuffer, sizeof(programBuffer)) == 0)
{
printf("Flash program verify passed\n");
}
else
{
printf("Flash program verify failed\n");
}

//////////////////////////////////////////////////////////// 

WHAT I AM THINKING:

All of my code is programmed into the flash such as .text, and etc.

Am I trying to erase a flash from the flash?

or it is not the case that the code automatically moves to RAM and erase ROM from RAM after it boots up?

Thank you very much.

0 Kudos
4,197 Views
bjargalsaikhan
Contributor II

Should I need to copy everything from flash to RAM then erase a flash? 

If so could you direct me? 

Thank you. 

0 Kudos
4,197 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Baasanjav Jargalsaikhan,

Thanks for your reply.
On MIMXRT1060 board, the QSPI flash (IS25WP064) is 8M bytes, however, in your code, the offset is 0x800000, this address map would n't cover the QSPI flash, I think it's the root cause of your issue.
I've attached a testing code which works well on the MIMXRT1060, please refer to it for details.

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

4,197 Views
bjargalsaikhan
Contributor II

Thank you very much.

0 Kudos
4,197 Views
kimberlyrandall
Contributor I

I guess the code itself needs to be modified..Its not up to the mark according to me 

0 Kudos