From 65c7e5238f091ab3d62eee23801fb1681bc53629 Mon Sep 17 00:00:00 2001 From: jzlv Date: Thu, 23 Sep 2021 19:21:38 +0800 Subject: [PATCH] [fix][fatfs] add user macro FS_MAX_SS,fix pDiskioDriver register when using one more interface --- components/fatfs/diskio.c | 48 ++++++++++++++++++++---------- components/fatfs/fatfs_posix_api.c | 5 ++-- components/fatfs/fatfs_posix_api.h | 2 +- components/fatfs/ffconf.h | 4 ++- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/components/fatfs/diskio.c b/components/fatfs/diskio.c index a87638c7..44db7c3e 100644 --- a/components/fatfs/diskio.c +++ b/components/fatfs/diskio.c @@ -40,22 +40,38 @@ FATFS_DiskioDriverTypeDef pDiskioDriver = { /*-----------------------------------------------------------------------*/ void disk_driver_callback_init(FATFS_DiskioDriverTypeDef *pNewDriver) { - pDiskioDriver.RAM_disk_status = pNewDriver->RAM_disk_status; - pDiskioDriver.MMC_disk_status = pNewDriver->MMC_disk_status; - pDiskioDriver.USB_disk_status = pNewDriver->USB_disk_status; - pDiskioDriver.RAM_disk_initialize = pNewDriver->RAM_disk_initialize; - pDiskioDriver.MMC_disk_initialize = pNewDriver->MMC_disk_initialize; - pDiskioDriver.USB_disk_initialize = pNewDriver->USB_disk_initialize; - pDiskioDriver.RAM_disk_read = pNewDriver->RAM_disk_read; - pDiskioDriver.MMC_disk_read = pNewDriver->MMC_disk_read; - pDiskioDriver.USB_disk_read = pNewDriver->USB_disk_read; - pDiskioDriver.RAM_disk_write = pNewDriver->RAM_disk_write; - pDiskioDriver.MMC_disk_write = pNewDriver->MMC_disk_write; - pDiskioDriver.USB_disk_write = pNewDriver->USB_disk_write; - pDiskioDriver.RAM_disk_ioctl = pNewDriver->RAM_disk_ioctl; - pDiskioDriver.MMC_disk_ioctl = pNewDriver->MMC_disk_ioctl; - pDiskioDriver.USB_disk_ioctl = pNewDriver->USB_disk_ioctl; - pDiskioDriver.Translate_Result_Code = pNewDriver->Translate_Result_Code; + if (pNewDriver->RAM_disk_status) + pDiskioDriver.RAM_disk_status = pNewDriver->RAM_disk_status; + if (pNewDriver->MMC_disk_status) + pDiskioDriver.MMC_disk_status = pNewDriver->MMC_disk_status; + if (pNewDriver->USB_disk_status) + pDiskioDriver.USB_disk_status = pNewDriver->USB_disk_status; + if (pNewDriver->RAM_disk_initialize) + pDiskioDriver.RAM_disk_initialize = pNewDriver->RAM_disk_initialize; + if (pNewDriver->MMC_disk_initialize) + pDiskioDriver.MMC_disk_initialize = pNewDriver->MMC_disk_initialize; + if (pNewDriver->USB_disk_initialize) + pDiskioDriver.USB_disk_initialize = pNewDriver->USB_disk_initialize; + if (pNewDriver->RAM_disk_read) + pDiskioDriver.RAM_disk_read = pNewDriver->RAM_disk_read; + if (pNewDriver->MMC_disk_read) + pDiskioDriver.MMC_disk_read = pNewDriver->MMC_disk_read; + if (pNewDriver->USB_disk_read) + pDiskioDriver.USB_disk_read = pNewDriver->USB_disk_read; + if (pNewDriver->RAM_disk_write) + pDiskioDriver.RAM_disk_write = pNewDriver->RAM_disk_write; + if (pNewDriver->MMC_disk_write) + pDiskioDriver.MMC_disk_write = pNewDriver->MMC_disk_write; + if (pNewDriver->USB_disk_write) + pDiskioDriver.USB_disk_write = pNewDriver->USB_disk_write; + if (pNewDriver->RAM_disk_ioctl) + pDiskioDriver.RAM_disk_ioctl = pNewDriver->RAM_disk_ioctl; + if (pNewDriver->MMC_disk_ioctl) + pDiskioDriver.MMC_disk_ioctl = pNewDriver->MMC_disk_ioctl; + if (pNewDriver->USB_disk_ioctl) + pDiskioDriver.USB_disk_ioctl = pNewDriver->USB_disk_ioctl; + if (pNewDriver->Translate_Result_Code) + pDiskioDriver.Translate_Result_Code = pNewDriver->Translate_Result_Code; } /*-----------------------------------------------------------------------*/ diff --git a/components/fatfs/fatfs_posix_api.c b/components/fatfs/fatfs_posix_api.c index f1bbc419..ddf91078 100644 --- a/components/fatfs/fatfs_posix_api.c +++ b/components/fatfs/fatfs_posix_api.c @@ -30,10 +30,11 @@ #include "fatfs_posix_api.h" #include "ff.h" #include "stdlib.h" +#include "string.h" /*Memory request interface*/ -static void *(*vfs_malloc)(size_t size) = mmheap_alloc; //默认的内存申请接口 -static void (*vfs_free)(void *ptr) = mmheap_free; //默认的内存释放接口 +static void *(*vfs_malloc)(size_t size) = malloc; //默认的内存申请接口 +static void (*vfs_free)(void *ptr) = free; //默认的内存释放接口 /** * @brief fs init diff --git a/components/fatfs/fatfs_posix_api.h b/components/fatfs/fatfs_posix_api.h index 7d116de6..11dfe0e8 100644 --- a/components/fatfs/fatfs_posix_api.h +++ b/components/fatfs/fatfs_posix_api.h @@ -36,7 +36,7 @@ extern "C" { #endif #include "ff.h" -#include "drv_mmheap.h" +#include "stdio.h" typedef int ff_dev_t; //32为int数据,高12位主设备号,低20位次设备号 diff --git a/components/fatfs/ffconf.h b/components/fatfs/ffconf.h index 95883460..abdb5573 100644 --- a/components/fatfs/ffconf.h +++ b/components/fatfs/ffconf.h @@ -151,7 +151,7 @@ /* Number of volumes (logical drives) to be used. (1-10) */ #define FF_STR_VOLUME_ID 1 -#define FF_VOLUME_STRS "sd2", "sd", "ram", "nand", "cg", "usb", +#define FF_VOLUME_STRS "ram", "sd", "usb", "nand", "cg", "sd2", /* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings. / When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive / number in the path name. FF_VOLUME_STRS defines the volume ID strings for each @@ -172,7 +172,9 @@ / funciton will be available. */ #define FF_MIN_SS 512 +#ifndef FF_MAX_SS #define FF_MAX_SS 512 +#endif /* This set of options configures the range of sector size to be supported. (512, / 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and / harddisk. But a larger value may be required for on-board flash memory and some