2018-08-15 07:32 AM
I would like to implement FatFs on my STM32 MCU with SPI Flash, W25Q16JV.
Is there a sample code for this? How can I port it ?
Solved! Go to Solution.
2021-01-10 04:28 AM
Hello, I am able write and read successfully.
change the line in "ffconf.h" file as below
#define _MAX_SS 4096
change the line in "spi_flash.h" file as below
#define FLASH_SECTOR_SIZE 4096
the attached file should be modified as well
2018-08-15 08:10 AM
So take your code you have for read/write/erase of the SPI FLASH, and integrate that with the DISKIO layer of FatFs
2018-08-15 11:42 AM
Hello Clive,
I generated a sample code by CubeMX and selected fatfs as "User-Defined". There is file, "user_diskio.c" file which is generated bu CubeMX.
Will I put my code into the below function. In addition, there is read and write function available. However there is no erase function.
Diskio_drvTypeDef USER_Driver =
{
USER_initialize,
USER_status,
USER_read,
#if _USE_WRITE
USER_write,
#endif /* _USE_WRITE == 1 */
#if _USE_IOCTL == 1
USER_ioctl,
#endif /* _USE_IOCTL == 1 */
};
2018-08-15 02:04 PM
You have to manage the access to the flash so that FatFs can read/write 512 byte sector(s). You'd need to deal with the erase operation, and read-erase-write where a sector spanned a block on the underlying device.
2018-08-17 12:55 AM
I can only erase as little as 4K sector on the flash memory, but you say 512 byte.
I will do it something like below. Do you think that it is OK.
DRESULT disk_read(
BYTE drv, /* Physical drive nmuber(0..) */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address(LBA) */
BYTE count /* Number of sectors to read(1..255) */
)
{
int i;
for(i=0;i<count;i++)
{
W25X_Read_Sector(sector,buff);
sector ++;
buff += FLASH_SECTOR_SIZE;
}
return RES_OK;
}
DRESULT disk_write(
BYTE drv, /* Physical drive nmuber(0..) */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address(LBA) */
BYTE count /* Number of sectors to write(1..255) */
)
{
int i;
for(i=0;i<count;i++)
{ W25X_Erase_Sector(sector);
W25X_Write_Sector(sector,(u8*)buff);
sector ++;
buff += FLASH_SECTOR_SIZE;
}
return RES_OK;
}
2018-08-17 01:04 AM
FLASH_SECTOR_SIZE = 4096
2018-12-13 04:47 AM
Hi voyvoda,
I'm dealing with the same problem right now.
Did you able to achive porting the FatFS to the SPI flash through your way?
Thanks,
Ogulcan
2018-12-14 12:10 AM
2018-12-14 02:15 AM
Teşekkürler :)
2019-01-10 01:10 AM
SPI flash dosyanızı izninizle ben de indirip inceledim. hatta hal kütüphanesi ile çalışacak hale getirdim ancak bir konudan emin olamadım. diskio.c dosyası içerisinde disk_ioctl fonksiyonunda switch içerisinde case CTRL_ERASE_SECTOR: durumu braketle devre dışı bırakılmış. neden devredışı yapılmış olabilir. yani veri yazmadan önce ilgili sektörün silinmesi gerekmiyor mu. Bilginiz var ise paylaşır mısınız. Teşekkürler