2020-08-13 12:17 AM
I am trying to interface a SPI flash from Winbond (W25Q64JV) with FATFS
I have no previous experience with FATFS.
I initialize FATFS in CubeMX with the option "used-defined" and modified the MAXIMUM and MINIMUM Sector Size to 4096, as it is the smallest possible erase sector dimension.
I also have a library with function to read, write, erase and other stuff in my Flash with the SPI which works fine.
I know that I only have then to completed the file "user_diskio.c" generated by CubeMX to interface my flash library with the FATFS library. Specially the functions:
DSTATUS USER_initialize (BYTE pdrv);
DSTATUS USER_status (BYTE pdrv);
DRESULT USER_read (BYTE pdrv, BYTE *buff, DWORD sector, UINT count);
DRESULT USER_write (BYTE pdrv, const BYTE *buff, DWORD sector, UINT count);
DRESULT USER_ioctl (BYTE pdrv, BYTE cmd, void *buff);
As I don't see any erase function to complete, one of my question is to know if I need to erase the sector before writing in it in the USER_write function ?
Thanks in advance for your help
2020-08-13 12:35 AM
That type of flash (unmanaged NOR flash) are usually not used with a file system, especially not FATFS. This is because the first blocks contianing meta-data (file allocation tables, root directory) will be used (rewritten) alot and wear out. There is no wear-leveling layer in those chips.
A typical use of FATFS would be on SD-cards or EMMC chips.
2020-08-13 12:48 AM
I understand your answer, it is a good point and well explained, thank you.
However, even if it is not usuall, it is still possible to implement it right ?
The application would be to store a firmware for a firmware update which works with a bootloader using FATFS. That's the reason of why the use of FATFS.
And also, if I am not wrong, the containing meta-data file will be rewritten only when there is a new file. As it is not so often that I will push a firmware update, I think it won't be an issue
2020-08-13 01:08 AM
It can be done. You have to implement erase and program within the write function. It has been done before, search the forum for stm32_spi_flash_fatfs.
But, most MCU projects I'm aware of avoid the additional file system layer if possible. Its another item to test and a possible source of nasty errors.
2020-08-13 01:42 AM
Good luck with that. I'm trying to get FATFS running on an SDMMC and there just seems to be no documentation on where the Cube code ends and what's left for the coder implement. I would appreciate it if you post up how you get on as a benefit for those following in your footsteps.
2020-08-13 01:52 AM
For a SD specific backend, there is sample code here: https://github.com/STMicroelectronics/STM32CubeF0/tree/master/Drivers/BSP/Adafruit_Shield
And the original FATFS authors docs: http://elm-chan.org/fsw/ff/00index_e.html