@@ -80,6 +80,19 @@ def build(env):
80
80
env .template ("../cortex/delay_ns.hpp.in" , "delay_ns.hpp" )
81
81
env .template ("../cortex/delay_impl.hpp.in" , "delay_impl.hpp" )
82
82
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 ))
83
96
84
97
def post_build (env ):
85
98
env .substitutions = env .query ("::cortex-m:linkerscript" )
@@ -89,7 +102,49 @@ def post_build(env):
89
102
linkerscript = "../cortex/ram.ld.in"
90
103
if env .get (":platform:core:vector_table_location" , "rom" ) == "ram" :
91
104
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 :
93
148
if memory ["name" ] == "ccm" :
94
149
if "x" in memory ["access" ]:
95
150
# Executable CCM (Instruction Core-Coupled Memory)
0 commit comments