Skip to content

Commit 89646ac

Browse files
committed
[cortex-m7] Enable I/D-Cache optionally
1 parent bb42736 commit 89646ac

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/modm/platform/core/cortex/module.lb

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,20 @@ def prepare(module, options):
219219
maximum="64Ki",
220220
default="3Ki"))
221221

222-
if "f" in options[":target"].get_driver("core")["type"]:
222+
core = options[":target"].get_driver("core")["type"]
223+
if "m7" in core:
224+
module.add_option(
225+
BooleanOption(
226+
name="enable_icache",
227+
description="Enable Instruction-Cache",
228+
default=True))
229+
module.add_option(
230+
BooleanOption(
231+
name="enable_dcache",
232+
description="Enable Data-Cache",
233+
default=True))
234+
235+
if "f" in core:
223236
module.add_option(
224237
EnumerationOption(
225238
name="float-abi",
@@ -331,8 +344,7 @@ def validate(env):
331344
def build(env):
332345
env.substitutions = env.query("vector_table")
333346
core = env.substitutions["core"]
334-
with_icache = "m7" in core
335-
with_dcache = with_icache and not (env.has_module(":platform:dma") or env.has_module(":platform:bdma"))
347+
enable_dcache = env.get("enable_dcache", False) and not (env.has_module(":platform:dma") or env.has_module(":platform:bdma"))
336348
env.substitutions.update({
337349
"target": env[":target"].identifier,
338350
"with_fault_storage": env.has_module(":platform:fault"),
@@ -341,12 +353,14 @@ def build(env):
341353
"with_fpu": env.get("float-abi", "soft") != "soft",
342354
"with_multicore": env.has_module(":platform:multicore"),
343355
"with_msplim": sum(c.isnumeric() for c in core) == 2,
344-
"with_icache": with_icache,
345-
"with_dcache": with_dcache,
356+
"enable_icache": env.get("enable_icache", False),
357+
"enable_dcache": enable_dcache,
358+
"has_icache": env.has_option("enable_icache"),
359+
"has_dcache": env.has_option("enable_dcache"),
346360
})
347361
env.outbasepath = "modm/src/modm/platform/core"
348362

349-
if env.substitutions["with_icache"] and not env.substitutions["with_dcache"]:
363+
if env.get("enable_dcache", False) and not enable_dcache:
350364
env.log.warning("Cortex-M7 D-Cache is disabled due to using DMA!")
351365

352366
# startup script

src/modm/platform/core/cortex/startup.c.in

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,23 @@ table_zero(const uint32_t *const start, const uint32_t *const end)
9595
// Called by Reset_Handler in reset_handler.s
9696
void __modm_startup(void)
9797
{
98+
%% if has_icache and not enable_icache
99+
SCB_DisableICache();
100+
%% endif
101+
%% if has_dcache and not enable_dcache
102+
SCB_DisableDCache();
103+
%% endif
104+
%#
98105
// Copy and zero all internal memory
99106
table_copy(__table_copy_intern_start, __table_copy_intern_end);
100107
table_zero(__table_zero_intern_start, __table_zero_intern_end);
101108
%#
102-
%% if with_icache
109+
%% if enable_icache
103110
// Enable instruction cache
104111
SCB_EnableICache();
105112
SCB_InvalidateICache();
106113
%% endif
107-
%% if with_dcache
114+
%% if enable_dcache
108115
// Enable data cache with default WBWA policy
109116
SCB_EnableDCache();
110117
SCB_CleanInvalidateDCache();

0 commit comments

Comments
 (0)