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.