DRV_W25_PageWrite Function
C
bool DRV_W25_PageWrite( const DRV_HANDLE handle, void *tx_data, uint32_t tx_data_length, uint32_t address );
Summary
Writes one page of data starting at the specified address.
Description
This function schedules a non-blocking write operation for writing maximum one page of data into flash memory.
The requesting client should call DRV_W25_TransferStatusGet() API to know the current status of the request.
Preconditions
The DRV_W25_Open() routine must have been called for the specified W25 driver instance. The flash address location which has to be written, must have been erased before using the W25_xxxErase() routine. The flash address has to be a Page aligned address.
Parameters
Param | Description |
---|---|
handle | A valid open-instance handle, returned from the driver's open routine |
*tx_data | The source buffer containing data to be programmed into W25 Flash |
tx_data_length | Total number of bytes to be written. should not be greater than page size |
address | Write memory start address from where the data should be written |
Returns
true
if the write request is successfully sent to the flash
false
if Write enable fails before sending sector erase command to flash
if write command itself fails
Example
#define PAGE_SIZE 256 #define BUFFER_SIZE 1024 #define MEM_ADDRESS 0x0 DRV_HANDLE handle; // Returned from DRV_W25_Open uint8_t CACHE_ALIGN writeBuffer[BUFFER_SIZE]; bool status = false; if(false == DRV_W25_SectorErase(handle)) { // Error handling here } // Wait for erase to be completed while(DRV_W25_TransferStatusGet(handle) == DRV_W25_TRANSFER_BUSY); for (uint32_t j = 0; j < BUFFER_SIZE; j += PAGE_SIZE) { if (DRV_W25_PageWrite(handle, (void *)&writeBuffer[j], (MEM_ADDRESS + j)) == false) { status = false; break; } // Wait for write to be completed while(DRV_W25_TransferStatusGet(handle) == DRV_W25_TRANSFER_BUSY); status = true; } if(status == false) { // Error handling here }
Remarks
This routine will block wait until write request is submitted successfully.
Client should wait until write is complete to send next transfer request.