The disk_read function reads data from the storage device.
DRESULT disk_read (
BYTE pdrv, /* [IN] Physical drive number */
BYTE* buff, /* [OUT] Pointer to the read data buffer */
DWORD sector, /* [IN] Start sector number */
UINT count /* [IN] Number of sectros to read */
- Specifies the physical drive number.
- Pointer to the byte array to store the read data. The size of data to be read is sector size * count bytes.
- Specifies the start sector number in logical block address (LBA).
- Specifies number of sectors to read. FatFs specifis with 1 to 128.
- RES_OK (0)
- The function succeeded.
- Any hard error occured during the read operation and could not recover it.
- Invalid parameter.
- The disk drive has not been initialized.
The memory address specified by buff is not that always aligned to word boundary because the type of argument is defined as BYTE*. The misaligned read/write request can occure at direct transfer. If the bus architecture, especially DMA controller, does not allow misaligned memory access, it should be solved in this function. There are some workarounds described below to avoid this issue.
- Convert word transfer to byte transfer in this function. - Recommended.
- For f_read(), avoid long read request that includes a whole of sector. - Direct transfer will never occure.
- For f_read(fp, buff, btr, &br), make sure that (((UINT)buff & 3) == (f_tell(fp) & 3)) is true. - Word aligned direct transfer is guaranteed.
Generally, a multiple sector transfer request must not be split into single sector transactions to the storage device, or you will not get good read throughput.