Skip to content

Commit fa7a339

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

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
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: 19 additions & 10 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
104-
SCB_EnableICache();
98+
%% if has_icache and not enable_icache
99+
SCB_DisableICache();
105100
SCB_InvalidateICache();
106101
%% endif
107-
%% if with_dcache
108-
// Enable data cache with default WBWA policy
109-
SCB_EnableDCache();
102+
%% if has_dcache and not enable_dcache
103+
SCB_DisableDCache();
110104
SCB_CleanInvalidateDCache();
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
@@ -119,6 +117,17 @@ void __modm_startup(void)
119117
// Enable trapping of divide by zero for UDIV/SDIV instructions.
120118
SCB->CCR |= SCB_CCR_DIV_0_TRP_Msk;
121119
%% endif
120+
%#
121+
%% if enable_icache
122+
// Enable instruction cache
123+
SCB_EnableICache();
124+
SCB_InvalidateICache();
125+
%% endif
126+
%% if enable_dcache
127+
// Enable data cache with default WBWA policy
128+
SCB_EnableDCache();
129+
SCB_CleanInvalidateDCache();
130+
%% endif
122131
%#
123132
// Call all hardware initialize hooks
124133
table_call(__hardware_init_start, __hardware_init_end);

0 commit comments

Comments
 (0)