From 83feee4d454ac253191fb65bfca93e65d546ce40 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 8 May 2025 12:44:33 +0200 Subject: [PATCH] feat(radio): static disk cache (#6170) --- .../linker/stm32h750_sdram/extra_sections.ld | 7 +++++++ .../linker/stm32h7rs_sdram/extra_sections.ld | 7 +++++++ radio/src/disk_cache.cpp | 8 +++++++- radio/src/disk_cache.h | 5 +++++ radio/src/targets/common/arm/stm32/h7/memory_sections.h | 3 +-- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/radio/src/boards/generic_stm32/linker/stm32h750_sdram/extra_sections.ld b/radio/src/boards/generic_stm32/linker/stm32h750_sdram/extra_sections.ld index a6da2e2f1..e0cc41760 100644 --- a/radio/src/boards/generic_stm32/linker/stm32h750_sdram/extra_sections.ld +++ b/radio/src/boards/generic_stm32/linker/stm32h750_sdram/extra_sections.ld @@ -29,6 +29,13 @@ _stext_iram = LOADADDR(.iram); +/* Disk cache buffers */ +.disk_cache (NOLOAD) : +{ + . = ALIGN(4); + *(.disk_cache) +} > RAM_D1 + /* Extra DMA section */ .dram (NOLOAD) : { diff --git a/radio/src/boards/generic_stm32/linker/stm32h7rs_sdram/extra_sections.ld b/radio/src/boards/generic_stm32/linker/stm32h7rs_sdram/extra_sections.ld index 82785b1e7..f9382cd3a 100644 --- a/radio/src/boards/generic_stm32/linker/stm32h7rs_sdram/extra_sections.ld +++ b/radio/src/boards/generic_stm32/linker/stm32h7rs_sdram/extra_sections.ld @@ -29,6 +29,13 @@ _stext_iram = LOADADDR(.iram); +/* Disk cache buffers */ +.disk_cache (NOLOAD) : +{ + . = ALIGN(4); + *(.disk_cache) +} > PSRAM + /* Extra DMA section */ .dram (NOLOAD) : { diff --git a/radio/src/disk_cache.cpp b/radio/src/disk_cache.cpp index 4280b075b..9bd48776a 100644 --- a/radio/src/disk_cache.cpp +++ b/radio/src/disk_cache.cpp @@ -38,6 +38,10 @@ #define BLOCK_SIZE FF_MAX_SS #define DISK_CACHE_BLOCK_SIZE (DISK_CACHE_BLOCK_SECTORS * BLOCK_SIZE) +#if !defined(__DISK_CACHE) +#define __DISK_CACHE __SDRAM +#endif + DiskCache diskCache; class DiskCacheBlock @@ -112,9 +116,11 @@ DiskCache::DiskCache() : lastBlock(0), blocks(nullptr), diskDrv(nullptr) stats.noWrites = 0; } +static DiskCacheBlock _cache_blocks[DISK_CACHE_BLOCKS_NUM] __DISK_CACHE; + void DiskCache::initialize(const diskio_driver_t* drv) { - blocks = new DiskCacheBlock[DISK_CACHE_BLOCKS_NUM]; + blocks = _cache_blocks; diskDrv = drv; } diff --git a/radio/src/disk_cache.h b/radio/src/disk_cache.h index b8869107f..83f1abbc5 100644 --- a/radio/src/disk_cache.h +++ b/radio/src/disk_cache.h @@ -24,8 +24,13 @@ #include "hal/fatfs_diskio.h" // tunable parameters +#if !defined(DISK_CACHE_BLOCKS_NUM) #define DISK_CACHE_BLOCKS_NUM 32 // no cache blocks +#endif + +#if !defined(DISK_CACHE_BLOCK_SECTORS) #define DISK_CACHE_BLOCK_SECTORS 16 // no sectors +#endif struct DiskCacheStats { diff --git a/radio/src/targets/common/arm/stm32/h7/memory_sections.h b/radio/src/targets/common/arm/stm32/h7/memory_sections.h index 29fd715bb..51fa6eb9e 100644 --- a/radio/src/targets/common/arm/stm32/h7/memory_sections.h +++ b/radio/src/targets/common/arm/stm32/h7/memory_sections.h @@ -27,5 +27,4 @@ #define __IRAM __attribute__((section(".iram"))) #define __SDRAM __attribute__((section(".sdram"), aligned(4))) #define __SDRAMFONTS __attribute__((section(".sdram_fonts"), aligned(4))) - - +#define __DISK_CACHE __attribute__((section(".disk_cache"), aligned(4)))