Skip to content

Commit

Permalink
[stm32] Place stack in SRAM by default on H7, add lbuild option
Browse files Browse the repository at this point in the history
The DTCM is not DMA-capable on H7 devices. An lbuild option is added to
select the stack location between SRAM and DTCM.
  • Loading branch information
chris-durand committed Nov 16, 2023
1 parent 605aaba commit 14ccbcd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/modm/platform/core/stm32/idtcm.ld.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ SECTIONS
%% set dtcm_section = "DTCM"
%% endif

%% if stack_in_dtcm
{{ linker.section_stack(dtcm_section) }}
%% else
{{ linker.section_stack(cont_ram.cont_name|upper) }}
%% endif

%% if "dtcm" in cont_ram.cont_name
{{ linker.section_ram(cont_ram.cont_name|upper, "FLASH", table_copy, table_zero,
Expand Down
11 changes: 11 additions & 0 deletions src/modm/platform/core/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ def prepare(module, options):
default="rom")
)

if options[":target"].identifier.family == "h7":
module.add_option(
EnumerationOption(
name="stack_location",
description="SRAM (default) or DTCM (faster, but not DMA-capable)",
enumeration=["sram", "dtcm"],
default="sram")
)

module.depends(":platform:cortex-m")
return True

Expand Down Expand Up @@ -83,6 +92,7 @@ def build(env):


def post_build(env):
target = env[":target"].identifier
env.substitutions = env.query("::cortex-m:linkerscript")
env.substitutions.update(env.query("::cortex-m:vector_table"))
env.outbasepath = "modm/link"
Expand All @@ -100,5 +110,6 @@ def post_build(env):
linkerscript = "dccm.ld.in"
elif memory["name"] == "dtcm":
# Executable ITCM and DTCM (Tightly-Coupled Memory)
env.substitutions["stack_in_dtcm"] = env.get(":platform:core:stack_location", "dtcm") == "dtcm"
linkerscript = "idtcm.ld.in"
env.template(linkerscript, "linkerscript.ld")

0 comments on commit 14ccbcd

Please sign in to comment.