Skip to content

Commit 13e35ea

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

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
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: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,18 @@ 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-
// Copy and zero all internal memory
99-
table_copy(__table_copy_intern_start, __table_copy_intern_end);
100-
table_zero(__table_zero_intern_start, __table_zero_intern_end);
101-
%#
102-
%% if with_icache
103-
// Enable instruction cache
98+
%% if enable_icache
10499
SCB_EnableICache();
105-
SCB_InvalidateICache();
100+
%% elif has_icache
101+
SCB_DisableICache();
106102
%% endif
107-
%% if with_dcache
108-
// Enable data cache with default WBWA policy
109-
SCB_EnableDCache();
110-
SCB_CleanInvalidateDCache();
103+
%% if has_dcache
104+
SCB_DisableDCache();
111105
%% endif
106+
%#
107+
// Copy and zero all internal memory
108+
table_copy(__table_copy_intern_start, __table_copy_intern_end);
109+
table_zero(__table_zero_intern_start, __table_zero_intern_end);
112110
%#
113111
%% if core != "cortex-m0"
114112
// Set the vector table location
@@ -129,7 +127,12 @@ void __modm_startup(void)
129127

130128
// Initialize heap as implemented by the heap option
131129
__modm_initialize_memory();
132-
130+
%#
131+
%% if enable_dcache
132+
// Enable D-Cache with default WBWA policy *after* all memory operations
133+
SCB_EnableDCache();
134+
%#
135+
%% endif
133136
// Call all constructors of static objects
134137
table_call(__init_array_start, __init_array_end);
135138

0 commit comments

Comments
 (0)