modm_data.cubemx

STMicro STM32CubeMX Database

 1# Copyright 2022, Niklas Hauser
 2# SPDX-License-Identifier: MPL-2.0
 3
 4"""
 5# STMicro STM32CubeMX Database
 6"""
 7
 8from .device_data import devices_from_family, devices_from_prefix, devices_from_partname, cubemx_device_list
 9
10__all__ = [
11    "devices_from_family",
12    "devices_from_prefix",
13    "devices_from_partname",
14    "cubemx_device_list",
15]
def devices_from_family(family: str) -> list[str]:
47def devices_from_family(family: str) -> list[str]:
48    """
49    :param family: A STM32 family name, for example, F0, H7, G4.
50    :return: A list of device names belonging to a STM32 family.
51    """
52    devices = _family_file().query(f'//Family[@Name="{family.upper()}"]/SubFamily/Mcu/@RefName')
53    devices = _format_raw_devices(devices)
54    LOGGER.info("Found devices of family '{}': {}".format(family, ", ".join(devices)))
55    return devices
Parameters
  • family: A STM32 family name, for example, F0, H7, G4.
Returns

A list of device names belonging to a STM32 family.

def devices_from_prefix(prefix: str) -> list[str]:
58def devices_from_prefix(prefix: str) -> list[str]:
59    """
60    :param prefix: A STM32 device prefix, for example, STM32, STM32H7, STM32G432.
61    :return: A list of device names starting with the prefix.
62    """
63    devices = _family_file().query(f'//Family/SubFamily/Mcu[starts-with(@RefName,"{prefix.upper()}")]')
64    devices = _format_raw_devices(devices)
65    devices = [d for d in devices if not stm32_data.ignoreDevice(d)]
66    LOGGER.info("Found devices for prefix '{}': {}".format(prefix, ", ".join(devices)))
67    return list(sorted(devices))
Parameters
  • prefix: A STM32 device prefix, for example, STM32, STM32H7, STM32G432.
Returns

A list of device names starting with the prefix.

def devices_from_partname(partname: str) -> list[dict[str]]:
 78def devices_from_partname(partname: str) -> list[dict[str]]:
 79    """
 80    Find the STM32 device name in the STM32CubeMX database and convert the data
 81    into a device specific key-value mapping describing the hardware.
 82
 83    .. note::
 84       One partname may contain multiple devices, for example, multiple
 85       asymmetric CPU cores like in the STM32H745 device.
 86
 87    :param partname: A full STM32 device name.
 88    :return: a list of dictionaries containing a device specific data structure.
 89    """
 90    deviceNames = _family_file().query(
 91        f'//Family/SubFamily/Mcu[starts-with(@RefName,"{partname[:12]}x{partname[13:]}")]'
 92    )
 93    comboDeviceName = sorted([d.get("Name") for d in deviceNames])[0]
 94    device_file = XmlReader(os.path.join(_MCU_PATH, comboDeviceName + ".xml"))
 95    did = did_from_string(partname.lower())
 96    LOGGER.info(f"Parsing '{did.string}'")
 97
 98    # information about the core and architecture
 99    cores = [c.text.lower().replace("arm ", "") for c in device_file.query("//Core")]
100    if len(cores) > 1:
101        did.naming_schema += "@{core}"
102    devices = [_properties_from_id(comboDeviceName, device_file, did.copy(), c) for c in cores]
103    return [d for d in devices if d is not None]

Find the STM32 device name in the STM32CubeMX database and convert the data into a device specific key-value mapping describing the hardware.

One partname may contain multiple devices, for example, multiple asymmetric CPU cores like in the STM32H745 device.

Parameters
  • partname: A full STM32 device name.
Returns

a list of dictionaries containing a device specific data structure.

def cubemx_device_list() -> list[modm_data.owl.DeviceIdentifier]:
70def cubemx_device_list() -> list[DeviceIdentifier]:
71    """
72    :return: A list of all STM32 device identifiers.
73    """
74    return [did_from_string(d) for d in devices_from_prefix("STM32")]
Returns

A list of all STM32 device identifiers.