modm_data.picosdk
Raspberry Pi Pico SDK
Parses the CMSIS-SVD files of the RP2040 and RP2350 devices from the Pico SDK.
1# Copyright 2026, Niklas Hauser 2# SPDX-License-Identifier: MPL-2.0 3 4""" 5# Raspberry Pi Pico SDK 6 7Parses the CMSIS-SVD files of the RP2040 and RP2350 devices from the Pico SDK. 8""" 9 10from .device_data import device_files, device_from_file, did_from_string 11 12__all__ = [ 13 "device_files", 14 "device_from_file", 15 "did_from_string", 16]
def
device_files(prefix: str) -> list[pathlib.Path]:
64def device_files(prefix: str) -> list[Path]: 65 """ 66 :param prefix: A device prefix, for example, `rp2040`. 67 :return: A sorted list of SVD files matching the prefix. 68 """ 69 return sorted(_SVD_PATH.glob(f"{prefix.lower()}*.svd"))
Parameters
- prefix: A device prefix, for example,
rp2040.
Returns
A sorted list of SVD files matching the prefix.
def
device_from_file(path: pathlib.Path) -> list[dict]:
121def device_from_file(path: Path) -> list[dict]: 122 """ 123 Extracts the device data from an RP SVD file. 124 125 :param path: Path to the SVD file. 126 :return: A list of device property dictionaries, one per device described 127 by the SVD file. 128 """ 129 device_file = XmlReader(path) 130 p = _device_from_svd(device_file, did_from_string(Path(path).stem)) 131 devices = [] 132 for variant in _DEVICES[Path(path).stem.lower()]: 133 d = dict(p) 134 d["id"] = did_from_string(variant["name"]) 135 LOGGER.info("Parsing '%s'", d["id"].string) 136 d["gpios"] = [dict(g) for g in p["gpios"] if g["bank"] != "bank0" or g["idx"] < variant["gpios"]] 137 adc_pin, channels = variant["adc_pin"], variant["adc_channels"] 138 d["adc_channels"] = [{"id": c, "name": f"Ch{c}"} for c in range(channels)] 139 d["adc_channels"].append({"id": channels, "name": "Temperature"}) 140 for gpio in d["gpios"]: 141 gpio["signals"] = [_func_to_signal(p["modules_map"], func) for func in gpio["funcs"]] 142 if gpio["bank"] == "bank0" and 0 <= gpio["idx"] - adc_pin < channels: 143 gpio["signals"].append({"driver": "adc", "name": f"in{gpio['idx'] - adc_pin}", "af": "-1"}) 144 del d["modules_map"] 145 devices.append(d) 146 return devices
Extracts the device data from an RP SVD file.
Parameters
- path: Path to the SVD file.
Returns
A list of device property dictionaries, one per device described by the SVD file.
16def did_from_string(string: str) -> DeviceIdentifier: 17 """ 18 Parses RP device strings, for example, `rp2040` or `rp2350a`, organized as 19 `{platform}{cores}{type}{ram}{flash}{package}`. The package letter only 20 exists for the RP2350 family: A is the QFN-60 with 30 GPIOs, B the QFN-80 21 with 48 GPIOs. 22 """ 23 string = string.lower() 24 if not string.startswith("rp") or len(string) not in (6, 7): 25 raise ValueError(f"Unknown identifier '{string}'!") 26 schema = "{platform}{cores}{type}{ram}{flash}" 27 if len(string) == 7: 28 schema += "{package}" 29 i = DeviceIdentifier(schema) 30 i.set("platform", "rp") 31 i.set("cores", string[2]) 32 i.set("type", string[3]) 33 i.set("ram", string[4]) 34 i.set("flash", string[5]) 35 i.set("family", string[2:4]) 36 if len(string) == 7: 37 i.set("package", string[6]) 38 return i
Parses RP device strings, for example, rp2040 or rp2350a, organized as
{platform}{cores}{type}{ram}{flash}{package}. The package letter only
exists for the RP2350 family: A is the QFN-60 with 30 GPIOs, B the QFN-80
with 48 GPIOs.