You are nowhere trying to write data. It looks like the posted code is based on the code from
xqspips_flash_polled_example.c[
^].
If so, you have to copy the data to be written to
&WriteBuffer[DATA_OFFSET]
and call
FlashWrite()
page wise.
Untested example:
u32 nPage;
u32 nPages = nSrcLen / PAGE_SIZE;
u32 nLast = nSrcLen % PAGE_SIZE;
u32 nSpiAddress = 0; u32 nOffset = 0;
#if 0
u8 pPreserved[PAGE_SIZE];
if (nLast)
{
FlashRead(QspiInstancePtr, nSpiAddress + nPages * PAGE_SIZE, PAGE_SIZE, READ_CMD);
memcpy(pPreserved, &ReadBuffer[DATA_OFFSET], PAGE_SIZE);
}
#endif
u32 nMaxData = nPages * PAGE_SIZE;
if (nLast)
nMaxData += PAGE_SIZE;
FlashErase(QspiInstancePtr, nSpiAddress, nMaxData);
for (nPage = 0; nPage < nPages; nPage++, nOffset += PAGE_SIZE)
{
memcpy(&WriteBuffer[DATA_OFFSET], pSrcData + nOffset, PAGE_SIZE);
FlashWrite(QspiInstancePtr, nSpiAddress + nOffset, PAGE_SIZE, WRITE_CMD);
}
if (nLast)
{
memset(&WriteBuffer[DATA_OFFSET + nLast], 0, PAGE_SIZE - nLast);
memcpy(&WriteBuffer[DATA_OFFSET], pSrcData + nOffset, nLast);
FlashWrite(QspiInstancePtr, nSpiAddress + nOffset, PAGE_SIZE, WRITE_CMD);
}