Skip to content

Commit cd3895f

Browse files
authored
Update cmsis_mcu_descr.py for custom targets
the fetch-missing is scanning also custom_target.json5 file if exist in project, for help not solve missing memory banks
1 parent 99fcb5b commit cd3895f

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

tools/python/mbed_tools/cli/cmsis_mcu_descr.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
TARGETS_JSON5_PATH = MBED_OS_DIR / "targets" / "targets.json5"
3636
CMSIS_MCU_DESCRIPTIONS_JSON_PATH = MBED_OS_DIR / "targets" / "cmsis_mcu_descriptions.json5"
3737

38+
CUSTOM_DIR = THIS_SCRIPT_DIR.parent.parent.parent.parent.parent
39+
CUSTOM_TARGETS_JSON5_PATH = CUSTOM_DIR / "custom_targets" / "custom_targets.json5"
3840

3941
# Top-level command
4042
@click.group(
@@ -69,12 +71,16 @@ def open_cmsis_cache(*, must_exist: bool = True) -> cmsis_pack_manager.Cache:
6971

7072
def get_mcu_names_used_by_targets_json5() -> Set[str]:
7173
"""
72-
Accumulate set of all `device_name` properties used by all targets defined in targets.json5
74+
Accumulate set of all `device_name` properties used by all targets defined in targets.json5 and custom_targets.json5
7375
"""
74-
LOGGER.info("Scanning targets.json5 for used MCU names...")
7576
used_mcu_names = set()
76-
targets_json5_contents = decode_json_file(TARGETS_JSON5_PATH)
77-
for target_details in targets_json5_contents.values():
77+
LOGGER.info("Scanning targets.json5 for used MCU names...")
78+
json5_contents = decode_json_file(TARGETS_JSON5_PATH)
79+
if os.path.exists(CUSTOM_TARGETS_JSON5_PATH):
80+
LOGGER.info("Scanning custom_targets.json5 for used MCU names...")
81+
json5_contents.update(decode_json_file(CUSTOM_TARGETS_JSON5_PATH))
82+
83+
for target_details in json5_contents.values():
7884
if "device_name" in target_details:
7985
used_mcu_names.add(target_details["device_name"])
8086
return used_mcu_names
@@ -153,12 +159,12 @@ def check_missing():
153159

154160
@cmsis_mcu_descr.command(
155161
name="fetch-missing",
156-
short_help="Fetch any missing MCU descriptions used by targets.json5."
162+
short_help="Fetch any missing MCU descriptions used by targets.json5 or custom_targets.json5."
157163
)
158164
def fetch_missing():
159165
"""
160-
Scans through cmsis_mcu_descriptions.json for any missing MCU descriptions that are referenced by
161-
targets.json5. If any are found, they are imported from the CMSIS cache.
166+
Scans through cmsis_mcu_descriptions.json for any missing MCU descriptions that are referenced by
167+
targets.json5 or custom_targets.json5. If any are found, they are imported from the CMSIS cache.
162168
163169
Note that downloaded descriptions should be checked for accuracy before they are committed.
164170
"""
@@ -186,8 +192,11 @@ def fetch_missing():
186192
f"wrong part number, or this MCU simply doesn't exist in the CMSIS index and has "
187193
f"to be added manually?")
188194
missing_mcus_dict[mcu] = cmsis_cache.index[mcu]
195+
196+
if os.path.exists(CUSTOM_TARGETS_JSON5_PATH):
197+
print(f"Remove 'device_name' and add the 'memories' section as 'memory_banks' section\nfrom following entries to {CUSTOM_TARGETS_JSON5_PATH}:")
198+
else:
199+
print(f"Add the following entries to {CMSIS_MCU_DESCRIPTIONS_JSON_PATH}:")
189200

190-
print(f"Add the following entries to {CMSIS_MCU_DESCRIPTIONS_JSON_PATH}:")
191201
print(json.dumps(missing_mcus_dict, indent=4, sort_keys=True))
192-
193-
sys.exit(1)
202+
sys.exit(1)

0 commit comments

Comments
 (0)