Ср июл 11, 2018 08:56:26
DSTATUS USER_initialize (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
Stat &= ~STA_NOINIT;
return Stat;
}
DRESULT USER_read (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to read */
)
{
EEPROM_SPI_ReadBuffer(buff, sector*512, 512);
return RES_OK;
}
DRESULT USER_write (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to write */
)
{
EEPROM_SPI_WriteBuffer((uint8_t*)buff, sector*512, 512);
return RES_OK;
}
DRESULT USER_ioctl (
BYTE pdrv, /* Physical drive nmuber (0..) */
BYTE cmd, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
DRESULT res = RES_ERROR;
switch (cmd)
{
case CTRL_SYNC:
return RES_OK;
case GET_SECTOR_SIZE:
*(WORD*)buff = 512; // SECTOR_SIZE
return RES_OK;
case GET_SECTOR_COUNT:
*(DWORD*)buff = 256; // размер EEPROM 131072 байт. 131072 / SECTOR_SIZE = 256
return RES_OK;
}
return RES_PARERR;
return res;
}
FATFS mynewdiskFatFs; /* File system object for User logical drive */
FIL MyFile; /* File object */
char mynewdiskPath[4]; /* User logical drive path */
uint32_t wbytes; /* File write counts */
uint8_t wtext[] = "Hello"; /* File write buffer */
if(FATFS_LinkDriver(&USER_Driver, mynewdiskPath) == 0)
{
if(f_mount(&mynewdiskFatFs, (TCHAR const*)mynewdiskPath, 0) == FR_OK)
{
if (f_mkfs((TCHAR const*)mynewdiskPath,0,512) == FR_OK)
if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)
{
if(f_write(&MyFile, wtext, sizeof(wtext), (void *)&wbytes) == FR_OK);
{
f_close(&MyFile);
}
}
}
}
FATFS_UnLinkDriver(mynewdiskPath);
for (i = 0; i <256; i++)
{
EEPROM_SPI_ReadBuffer(RxBuffer, (uint16_t)512*i, (uint16_t)512);
}