mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-03 03:31:41 +03:00
Merge branch 'feat/align_fatfs_buffers' into 'master'
feat(storage/fatfs): Allow fatfs buffers to be aligned for DMA access Closes IDF-9714 See merge request espressif/esp-idf!44942
This commit is contained in:
@@ -194,6 +194,16 @@ menu "FAT Filesystem support"
|
||||
Disable this option if optimizing for performance. Enable this option if
|
||||
optimizing for internal memory size.
|
||||
|
||||
config FATFS_ALLOC_PREFER_ALIGNED_WORK_BUFFERS
|
||||
bool "Prefer aligned, DMA capable RAM when allocating FATFS buffers"
|
||||
default y if SOC_SDMMC_HOST_SUPPORTED
|
||||
default n
|
||||
help
|
||||
Tries to allocate FATFS heap buffers in a way they can be used directly by the SDMMC driver without
|
||||
extra copies when DMA is enabled (for example when using PSRAM on ESP32-P4).
|
||||
Disable this if you need the absolute minimum heap overhead and do not use SDMMC.
|
||||
This option can be combined with CONFIG_FATFS_ALLOC_PREFER_EXTRAM,
|
||||
in which case, the following order is tried: DMA capable RAM, external RAM, internal RAM.
|
||||
|
||||
config FATFS_USE_FASTSEEK
|
||||
bool "Enable fast seek algorithm when using lseek function through VFS FAT"
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "ff.h"
|
||||
#include "sdkconfig.h"
|
||||
#ifdef CONFIG_FATFS_ALLOC_PREFER_EXTRAM
|
||||
#include "esp_heap_caps.h"
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Allocate/Free a Memory Block */
|
||||
@@ -19,14 +17,32 @@ void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if
|
||||
unsigned msize /* Number of bytes to allocate */
|
||||
)
|
||||
{
|
||||
#ifdef CONFIG_FATFS_ALLOC_PREFER_EXTRAM
|
||||
return heap_caps_malloc_prefer(msize, 2, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM,
|
||||
MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL);
|
||||
#else
|
||||
return malloc(msize);
|
||||
#endif
|
||||
}
|
||||
void *ptr = NULL;
|
||||
(void) ptr;
|
||||
|
||||
#if CONFIG_FATFS_ALLOC_PREFER_EXTRAM && CONFIG_FATFS_ALLOC_PREFER_ALIGNED_WORK_BUFFERS
|
||||
ptr = heap_caps_calloc_prefer(1, msize, 2, MALLOC_CAP_DMA | MALLOC_CAP_CACHE_ALIGNED | MALLOC_CAP_SPIRAM, MALLOC_CAP_CACHE_ALIGNED | MALLOC_CAP_SPIRAM);
|
||||
if (ptr != NULL) {
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_FATFS_ALLOC_PREFER_ALIGNED_WORK_BUFFERS
|
||||
ptr = heap_caps_calloc_prefer(1, msize, 2, MALLOC_CAP_DMA | MALLOC_CAP_CACHE_ALIGNED, MALLOC_CAP_CACHE_ALIGNED);
|
||||
if (ptr != NULL) {
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_FATFS_ALLOC_PREFER_ALIGNED_WORK_BUFFERS
|
||||
ptr = heap_caps_calloc(1, msize, MALLOC_CAP_SPIRAM);
|
||||
if (ptr != NULL) {
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return heap_caps_calloc(1, msize, MALLOC_CAP_DEFAULT);
|
||||
}
|
||||
|
||||
void ff_memfree (
|
||||
void* mblock /* Pointer to the memory block to free (no effect if null) */
|
||||
|
||||
Reference in New Issue
Block a user