Skip to content

Commit f610421

Browse files
committed
[stm32] Adapt memory regions for H7 dual-core devices
For the Cortex-M7 core: - "flash" region is set to flash bank 0. For the Cortex-M4 core: - "flash" region is set to flash bank 1. The default boot address coincides with the start of flash bank 1 (0x08100 0000) for all device sizes. - Main stack is placed into D2 domain SRAM1 local to the core. Non-default boot addresses configured via option bytes are not supported yet.
1 parent 94c36f3 commit f610421

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

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

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ def build(env):
8080
env.template("../cortex/delay_ns.hpp.in", "delay_ns.hpp")
8181
env.template("../cortex/delay_impl.hpp.in", "delay_impl.hpp")
8282

83+
def _get_memory_by_address(memories, address):
84+
for memory in memories:
85+
start = memory["start"]
86+
end = start + memory["size"]
87+
if address >= start and address < end:
88+
return memory
89+
raise KeyError("No memory found containing address '0x{:x}'".format(address))
90+
91+
def _get_memory_by_name(memories, name):
92+
for memory in memories:
93+
if memory["name"] == name:
94+
return memory
95+
raise KeyError("No memory found with name '{}'".format(name))
8396

8497
def post_build(env):
8598
env.substitutions = env.query("::cortex-m:linkerscript")
@@ -89,7 +102,49 @@ def post_build(env):
89102
linkerscript = "../cortex/ram.ld.in"
90103
if env.get(":platform:core:vector_table_location", "rom") == "ram":
91104
linkerscript = "ram_remap_vector_table.ld.in"
92-
for memory in env.substitutions["memories"]:
105+
106+
identifier = env[":target"].identifier
107+
memories = env.substitutions["memories"]
108+
109+
# H7 dual-core devices
110+
if identifier.family == "h7" and identifier.get("core"):
111+
# only use half of flash for each core of H7 dual core devices
112+
# TODO: allow non-default configurations with custom boot addresses
113+
core = identifier.core
114+
if identifier.size == "i":
115+
# one contiguous segment of flash organized in two banks
116+
# bank 0: 0x0800 0000 - 0x080F FFFF, used for CM7 program
117+
# bank 1: 0x0810 0000 - 0x081F FFFF, used for CM4 program
118+
flash = _get_memory_by_address(memories, 0x08000000)
119+
flash["size"] //= 2
120+
if core == "m4":
121+
flash["start"] += flash["size"]
122+
elif identifier.size == "g":
123+
# two discontiguous segments of flash
124+
# bank 0: 0x0800 0000 - 0x0807 FFFF, used for CM7 program
125+
# bank 1: 0x0810 0000 - 0x0817 FFFF, used for CM4 program
126+
flash_bank0 = _get_memory_by_address(memories, 0x08000000)
127+
flash_bank1 = _get_memory_by_address(memories, 0x08100000)
128+
if core == "m7":
129+
# remove flash segment used for CM4
130+
memories.remove(flash_bank1)
131+
flash_bank0["name"] = "flash"
132+
else: # m4
133+
# remove flash segment used for CM7
134+
memories.remove(flash_bank0)
135+
flash_bank1["name"] = "flash"
136+
else:
137+
raise RuntimeError("H7 dual-core devices with size '{}' are not supported!".format(identifier.size))
138+
139+
# place CM4 stack in local d2_sram
140+
# first memory in list is used as stack
141+
# move d2_sram to the beginning of the list
142+
if core == "m4":
143+
cont_regions = env.substitutions["cont_ram_regions"]
144+
d2_sram_index = cont_regions.index(_get_memory_by_name(cont_regions, "d2_sram1"))
145+
cont_regions[0], cont_regions[d2_sram_index] = cont_regions[d2_sram_index], cont_regions[0]
146+
147+
for memory in memories:
93148
if memory["name"] == "ccm":
94149
if "x" in memory["access"]:
95150
# Executable CCM (Instruction Core-Coupled Memory)

0 commit comments

Comments
 (0)