From fdd239fe21a3721dc7fb55a9cf816544af7e9647 Mon Sep 17 00:00:00 2001 From: Freddie Chopin Date: Fri, 22 Mar 2019 22:35:02 +0100 Subject: [PATCH] Don't bypass cache in `lfs_cache_prog()` and `lfs_cache_read()` In some cases specific alignment of buffer passed to underlying device is required. For example SDMMC in STM32F7 (when used with DMA) requires the buffers to be aligned to 16 bytes. If you enable data cache in STM32F7, the alignment of buffer passed to any driver which uses DMA should generally be at least 32 bytes. While it is possible to provide sufficiently aligned "read", "prog" and per-file caches to littlefs, the cases where caches are bypassed are hard to control when littlefs is hidden under some additional layers. For example if you couple littlefs with stdio and use it via `FILE*`, then littlefs functions will operate on internal `FIlE*` buffer, usually allocated dynamically, so in these specific cases - with insufficient alignment (8 bytes on ARM Cortex-M). The easy path was taken - remove all cases of cache bypassing. Fixes #158 --- lfs.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lfs.c b/lfs.c index 25c88c6..1e93418 100644 --- a/lfs.c +++ b/lfs.c @@ -80,21 +80,6 @@ static int lfs_bd_read(lfs_t *lfs, diff = lfs_min(diff, rcache->off-off); } - if (size >= hint && off % lfs->cfg->read_size == 0 && - size >= lfs->cfg->read_size) { - // bypass cache? - diff = lfs_aligndown(diff, lfs->cfg->read_size); - int err = lfs->cfg->read(lfs->cfg, block, off, data, diff); - if (err) { - return err; - } - - data += diff; - off += diff; - size -= diff; - continue; - } - // load to cache, first condition can no longer fail LFS_ASSERT(block < lfs->cfg->block_count); rcache->block = block;