1.6.18.6 1.7.19.6 1.8.15.6 1.25.14.6 1.26.13.6 1.27.14.6 1.28.17.6 1.32.21.6 1.34.12.6 1.42.12.6 QSPIx_MemoryWrite Function

C

// x - Instance of the QSPI peripheral

bool QSPIx_MemoryWrite
(
qspi_memory_xfer_t *qspi_memory_xfer,
uint32_t *tx_data,
uint32_t tx_data_length,
uint32_t address 
);

Summary

Writes to the specified address of the serial flash device.

Description

This function can be used to write maximum of one page of data to the specified address of the serial flash device connected as a QSPI slave. If the number of bytes to be written is greater than the page size then QSPIx_MemoryWrite API needs to be called multiple times.

Note: Before sending next write request, QSPIx_RegisterRead() can be called to read the status register of the slave device to check if the previous write operation is completed.

Precondition

QSPIx_Initialize must have been called for the associated QSPI instance. Write enable command has to be sent before write memory request.

Parameters

Param Description
*qspi_memory_xfer pointer to QSPI memory transfer structure holding the instructioncode register and instruction frame register information.
*tx_data Pointer to transmit buffer holding the data to write into memory.
tx_data_length number of bytes to write.
address Memory location to write to.

Returns

  • True on transfer request success.

  • False on transfer request failure.

Example

#define WRITE_PAGE_CODE 0x02
#define WRITE_IN_PROGRESS (1 << 0)

static qspi_memory_xfer_t qspi_memory_xfer;
static uint8_t buffer[256];
uint32_t address = 0x0;

for (int i = 0; i < 256; i++)
{
    buffer[i] = i;
}

// Write to memory location starting from address 0x0
qspi_memory_xfer.instruction = WRITE_PAGE_CODE;

// Use QAUD SPI Lane
qspi_memory_xfer.width = QUAD_CMD;

if (QSPI0_MemoryWrite(&qspi_memory_xfer, buffer, sizeof(buffer), address) == false)
{
    // Handle Error
}

// Query the status register and wait until WIP bit is cleared.
while(status_reg & WRITE_IN_PROGRESS);