选择使用TINY模式可以节省内存,具体其他配置可查看配置详解
生成代码后需要完善的函数有:初始化、读、写、状态、查询
打开user_diskio.c文件进行补充
函数初始化,加入存储设备的初始化函数
状态函数,建议直接返回RES_OK
读函数,加入存储设备读取函数
写函数,加入存储设备写函数
查询、命令函数,需要添加以下命令的返回,在diskio.h中53行可进行查看
#define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */ #define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */ #define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */ #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */ #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */主要就是,块大小、块数量,其他均返回正常即可
DRESULT USER_ioctl ( BYTE pdrv, /* Physical drive nmuber (0..) */ BYTE cmd, /* Control code */ void *buff /* Buffer to send/receive control data */ ) { /* USER CODE BEGIN IOCTL */ DRESULT dre = RES_OK; switch(cmd) { case CTRL_SYNC: dre = RES_OK; break; case GET_SECTOR_COUNT: *(uint32_t*)buff = w25qxx.SectorCount; dre = RES_OK; break; case GET_SECTOR_SIZE: *(uint32_t*)buff = w25qxx.SectorSize; dre = RES_OK; break; case GET_BLOCK_SIZE: *(uint32_t*)buff = w25qxx.BlockSize; dre = RES_OK; break; case CTRL_TRIM: dre = RES_OK; break; default: break; } return dre; /* USER CODE END IOCTL */
from: https://blog.csdn.net/shaynerain