disk_writep

The disk_writep function writes data to the sector.

DRESULT disk_writep (
  BYTE* buff,  /* [IN] Pointer to the data to be written */
  DWORD sc,    /* [IN] Sector number or Number of bytes to wtite */
);

Parameters

buff
Pointer to the data to be written to the sector. If a null pointer is given, the function initiates or finalizes a write transaction to the sector.
sc
Specifies nubmer of bytes to write if buff is not a null pointer. If buff is a null pointer and sc is not a zero, the function initiates a write transactin to the sector. If buff is a null pointer and sc is zero, the function finalizes the current sector write transactin.

Return Value

RES_OK (0)
The function succeeded.
RES_ERROR
A hard error occured during the write operation and could not recover it or the medium is write protected.
RES_PARERR
Invalid parameter.
RES_NOTRDY
The device has not been initialized.

Description

A sector write operation is done in following sequence.

  1. disk_writep(0, sector_number); Initiate a sector write transaction.
  2. disk_writep(data, byte_to_write); Start to write data to the sector.
  3. disk_writep(data, byte_to_write); And data can be written upto 512 bytes with one or more calls.
  4. disk_writep(data, byte_to_write); ...
  5. disk_writep(0, 0); Finalize the write transaction. If number of bytes sent is less than 512, rest of bytes in the sector is filled by zero.

If a write transaction is in progress, disk_readp() function will fail and disk_initialize() function finalize the current write transaction.

Remarks

This funciton is needed when PF_USE_WRITE == 1.

Return