@@ -132,10 +132,10 @@ def prepare(module, options):
132
132
if is_cortex_m :
133
133
module .add_collector (
134
134
PathCollector (name = "openocd.source" ,
135
- description = "Additional OpenOCD source files." ))
135
+ description = descr_opencd_source ))
136
136
module .add_collector (
137
137
PathCollector (name = "path.openocd" ,
138
- description = "Search path for OpenOCD configuration files" ))
138
+ description = "Search path for OpenOCD configuration files. " ))
139
139
140
140
if platform == "sam" :
141
141
module .add_collector (
@@ -242,7 +242,10 @@ def post_build(env):
242
242
# prepare custom path
243
243
openocd_cfg = env .get (":build:openocd.cfg" , "" )
244
244
if len (openocd_cfg ):
245
- env .substitutions ["openocd_user_path" ] = env .relative_outpath (openocd_cfg )
245
+ env .substitutions ["openocd_user_path" ] = env .relcwdoutpath (openocd_cfg )
246
+ env .substitutions ["openocd_search_dirs" ] = \
247
+ [env .relcwdoutpath (path ) for path in env .collector_values ("path.openocd" )]
248
+ env .substitutions ["openocd_sources" ] = env .collector_values ("openocd.source" )
246
249
247
250
has_rtt = env .has_module (":platform:rtt" )
248
251
env .substitutions ["has_rtt" ] = has_rtt
@@ -308,3 +311,31 @@ projects using the same target (like small bring-up and test projects).
308
311
and do not execute them by default. A stray `init` or similar in your script
309
312
will mess with modm's ability to program and debug a device correctly.
310
313
"""
314
+
315
+ descr_opencd_source = """# Additional OpenOCD source files
316
+
317
+ You can add multiple source files that will get included by the generated
318
+ `modm/openocd.cfg` to provide a default config for targets and boards.
319
+ You can add source files that are shipped with OpenOCD, for example,
320
+ `board/stm32f469discovery.cfg`, or custom source files from your own repository.
321
+
322
+ To avoid name clashes with the built-in config files, you should copy your own
323
+ source files into a separate folder and add it as a search path:
324
+
325
+ ```py
326
+ def build(env):
327
+ # Add a custom folder to the OpenOCD search paths
328
+ env.collect("modm:build:path.openocd", "repo/src/openocd/")
329
+
330
+ # Namespace this folder with your repository name to prevent name clashes
331
+ env.outbasepath = "repo/src/openocd/repo/board"
332
+ env.copy("board.cfg", "name.cfg")
333
+ # Now use a *relative* path to the source file inside this folder
334
+ env.collect("modm:build:openocd.source", "repo/board/name.cfg")
335
+
336
+ # Alternatively for a target config
337
+ env.outbasepath = "repo/src/openocd/repo/target"
338
+ env.copy("target.cfg", "name.cfg")
339
+ env.collect("modm:build:openocd.source", "repo/target/name.cfg")
340
+ ```
341
+ """
0 commit comments