I am using the IAR Embedded Workbench as my tool base and this sets the named objects into a safe space to erase/program flash from. The application I am running is located in SPI Flash as well, so I have addressed the issue of erasing/writing flash from memory.
initialize by copy {
readwrite,
/* Explicitly place flash operation functions in RAM. */
object mflash_drv.o,
object fsl_flexspi.o,
object fsl_cache.o,
object flexspi_nor_flash_ops.o,
object dlUtils.o,
section .textrw,
section CodeQuickAccess,
section DataQuickAccess
};
The data programmed into the flash is complete as verified by a CRC that emcompasses the entire data block being written. So it is something that happens when I re-enable interrupts.
the code looks something like this:
asm("CPSID I"); //Mask interrupts
flexspi_nor_flash_init(SPIFLASH_BASE);
numSectors = (dataLen / SECTOR_SIZE);
if ((dataLen % SECTOR_SIZE) != 0)
numSectors++;
/* Enter quad mode. */
status = flexspi_nor_enable_quad_mode(SPIFLASH_BASE);
// erase all necessary sectors.
for (i = 32; i < numSectors+32; i++)
{
status = flexspi_nor_flash_erase_sector(SPIFLASH_BASE, i * SECTOR_SIZE);
if (status != kStatus_Success)
{
dlFlag = FALSE;
return status; // Error erasing, abort
}
for (j = 0; j < PAGES_PER_SECTOR; j++)
{
status = flexspi_nor_flash_page_program(SPIFLASH_BASE,
(i * SECTOR_SIZE) + (j * FLASH_PAGE_SIZE),
(const uint32_t *)(srcAddr));
srcAddr += FLASH_PAGE_SIZE;
if (status != kStatus_Success)
{
dlFlag = FALSE;
return status;
}
}
}
asm("CPSIE I"); //Unmask interrupts