Цитата(skripach @ Mar 1 2016, 21:19)

Отложите fatfs, напишите простенький тест для нижнего уровня (чтение\запись по 512) и найдите там все косяки, их там есть.
Написал, попробывал, читаю/пишу, всё корректно, но та же проблема.
Привожу полный код diskio.cpp
CODE
#include "diskio.h"
#include "ff_gen_drv.h"
#include "flash.h"
#include "spi.h"
extern Disk_drvTypeDef disk;
extern Spi spi(GPIO_PIN_10, GPIO_PIN_11, GPIO_PIN_12, GPIO_PIN_2);
extern Flash flash(spi);
/**
* @brief Initializes a Drive
* @param pdrv: Physical drive number (0..)
* @retval DSTATUS: Operation status
*/
DSTATUS disk_initialize(BYTE pdrv)
{
DSTATUS stat = RES_OK;
if(disk.is_initialized[pdrv] == 0)
{
disk.is_initialized[pdrv] = 1;
stat = disk.drv[pdrv]->disk_initialize();
}
return stat;
}
/**
* @brief Gets Disk Status
* @param pdrv: Physical drive number (0..)
* @retval DSTATUS: Operation status
*/
DSTATUS disk_status(BYTE pdrv)
{
DSTATUS stat;
stat = disk.drv[pdrv]->disk_status();
return stat;
}
/**
* @brief Reads Sector(s)
* @param pdrv: Physical drive number (0..)
* @param *buff: Data buffer to store read data
* @param sector: Sector address (LBA)
* @param count: Number of sectors to read (1..128)
* @retval DRESULT: Operation result
*/
DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, BYTE count)
{
DWORD realSector = sector * 512;
flash.readArray(realSector, count * 512, buff);
return RES_OK;
}
/**
* @brief Writes Sector(s)
* @param pdrv: Physical drive number (0..)
* @param *buff: Data to be written
* @param sector: Sector address (LBA)
* @param count: Number of sectors to write (1..128)
* @retval DRESULT: Operation result
*/
#if _USE_WRITE == 1
DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, BYTE count)
{
DWORD realSector = sector * 512;
for (int i = 0; i < count; ++i)
{
flash.eraseBlock512(realSector + i * 512);
}
for(int i = 0; i < (count * 2); ++i)
{
uint8_t temp[256];
for(int j = 0; j < sizeof(temp); ++j)
{
temp[j] = buff[i * 256 + j];
}
flash.writeData(realSector + i * 256, sizeof(temp), temp);
}
return RES_OK;
}
#endif /* _USE_WRITE == 1 */
/**
* @brief I/O control operation
* @param pdrv: Physical drive number (0..)
* @param cmd: Control code
* @param *buff: Buffer to send/receive control data
* @retval DRESULT: Operation result
*/
#if _USE_IOCTL == 1
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
{
DRESULT res = RES_ERROR;
switch (cmd)
{
case CTRL_SYNC:
res = RES_OK;
break;
case GET_SECTOR_COUNT:
*(DWORD*)buff = 2048;
res = RES_OK;
break;
case GET_SECTOR_SIZE:
*(DWORD*)buff = 512;
res = RES_OK;
break;
case GET_BLOCK_SIZE:
*(DWORD*)buff = 512;
res = RES_OK;
break;
}
return res;
}
#endif /* _USE_IOCTL == 1 */
/**
* @brief Gets Time from RTC
* @param None
* @retval Time in DWORD
*/
DWORD get_fattime (void)
{
return 0;
}
Сообщение отредактировал IgorKossak - Mar 4 2016, 13:24
Причина редактирования: [codebox] для длинного кода, [code] - для короткого!