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 ( 9 devices_from_family, 10 devices_from_prefix, 11 devices_from_partname, 12 cubemx_device_list, 13 temperature_codes, 14) 15 16__all__ = [ 17 "devices_from_family", 18 "devices_from_prefix", 19 "devices_from_partname", 20 "cubemx_device_list", 21 "temperature_codes", 22]
def
devices_from_family(family: str) -> list[str]:
45def devices_from_family(family: str) -> list[str]: 46 """ 47 :param family: A STM32 family name, for example, F0, H7, G4. 48 :return: A list of device names belonging to a STM32 family. 49 """ 50 devices = _family_file().query(f'//Family[@Name="{family.upper()}"]/SubFamily/Mcu/@RefName') 51 devices = _format_raw_devices(devices) 52 LOGGER.info("Found devices of family '{}': {}".format(family, ", ".join(devices))) 53 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]:
56def devices_from_prefix(prefix: str) -> list[str]: 57 """ 58 :param prefix: A STM32 device prefix, for example, STM32, STM32H7, STM32G432. 59 :return: A list of device names starting with the prefix. 60 """ 61 devices = _family_file().query(f'//Family/SubFamily/Mcu[starts-with(@RefName,"{prefix.upper()}")]') 62 devices = _format_raw_devices(devices) 63 devices = [d for d in devices if not stm32_data.ignoreDevice(d)] 64 LOGGER.info("Found devices for prefix '{}': {}".format(prefix, ", ".join(devices))) 65 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]]:
120def devices_from_partname(partname: str) -> list[dict[str]]: 121 """ 122 Find the STM32 device name in the STM32CubeMX database and convert the data 123 into a device specific key-value mapping describing the hardware. 124 125 .. note:: 126 One partname may contain multiple devices, for example, multiple 127 asymmetric CPU cores like in the STM32H745 device. 128 129 :param partname: A full STM32 device name. 130 :return: a list of dictionaries containing a device specific data structure. 131 """ 132 deviceNames = _family_file().query(f'//Family/SubFamily/Mcu[starts-with(@RefName,"{partname}")]') 133 comboDeviceName = sorted([d.get("Name") for d in deviceNames])[0] 134 device_file = XmlReader(os.path.join(_MCU_PATH, comboDeviceName + ".xml")) 135 did = did_from_string(partname.lower()) 136 LOGGER.info(f"Parsing '{did.string}'") 137 138 # information about the core and architecture 139 cores = [c.text.lower().replace("arm ", "").replace("+", "plus") for c in device_file.query("//Core")] 140 if len(cores) > 1: 141 did.naming_schema += "@{core}" 142 devices = [_properties_from_id(partname, comboDeviceName, device_file, did.copy(), c) for c in cores] 143 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.
89def cubemx_device_list() -> list[DeviceIdentifier]: 90 """ 91 :return: A list of all STM32 device identifiers. 92 """ 93 return [did_from_string(d) for d in devices_from_prefix("STM32")]
Returns
A list of all STM32 device identifiers.
def
temperature_codes(partname: str) -> list[str]:
71def temperature_codes(partname: str) -> list[str]: 72 """ 73 CubeMX uses `x` as placeholder for the temperature range in the device name. 74 This function computes the temperature codes from the maximum operating 75 temperature, since every higher range also supports all the lower ranges. 76 77 :param partname: A STM32 device name with temperature placeholder. 78 :return: A sorted list of temperature codes, for example, `["3", "6", "7"]`. 79 """ 80 codes = set() 81 for device in _family_file().query(f'//Family/SubFamily/Mcu[@RefName="{partname}"]'): 82 temp_max = device.find("Temperature") 83 temp_max = "" if temp_max is None else temp_max.get("Max") 84 temp_max = int(float(temp_max)) if len(temp_max) else min(_TEMPERATURE_CODES) 85 codes.update(code for temp, code in _TEMPERATURE_CODES.items() if temp_max >= temp) 86 return sorted(codes)
CubeMX uses x as placeholder for the temperature range in the device name.
This function computes the temperature codes from the maximum operating
temperature, since every higher range also supports all the lower ranges.
Parameters
- partname: A STM32 device name with temperature placeholder.
Returns
A sorted list of temperature codes, for example,
["3", "6", "7"].