CMSIS SVD file parser that allows to convert SVD format to Python data structure
Project description
svd2py - Convert CMSIS SVD file to Python data structure
Introduction
Parser that allows to convert CMSIS SVD file format to Python data structure. Parser does not check SVD file syntax. It assume that parsing file is a proper SVD file.
Project structure
📦Svd2Py
┣━📂doc ─ Documentation
┣━📂svd2py ─ Python sources
┣━📂tests ─ pytest tests
┗━📜pyproject.toml
How it works
The parser translate SVD elements directly to Python data structures like dictionaries and list.
:white_check_mark: It does following thing:
- Translate SVD elements directly to Python data structures (dict and list),
:no_entry_sign: What is missing:
- Resolves derivedFrom element attribute,
- Parses and resolves dimElementGroup,
Let's assume you have following element in you SVD file:
<device schemaVersion="1.3" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd">
<name>TestDevic</name>
...
<peripherals>
<peripheral>
<name>TestPeripheral</name>
...
<registers>
<register derivedFrom="TestDerivedRegister">
<name>TestRegister</name>
...
<fields>
<field>
<name>TestField0</name>
...
</field>
<field>
<name>TestField1</name>
...
</field>
</fields>
</register>
...
</registers>
</peripheral>
...
</peripherals>
</device>
This will be converted to Python like this:
{
"device": {
"name": "TestDevice",
...
"peripherals": {
"peripheral": [
{
"name": "TestPeripheral",
...
"registers": {
"register": [
{
"attributes": {
"derivedFrom": "TestDerivedRegister"
},
"name": "TestRegister",
...
"fields": {
"field": [
{
"name": "TestField0",
...
},
{
"name": "TestField1",
...
}
]
}
},
]
...
}
},
]
...
},
"attributes": {
"schemaVersion": "1.3"
}
}
}
Install
pip install svd2py
How to use
import svd2py
svd_file = "sample.svd"
# Create SvdParser object passing path to SVD file
parser = svd2py.SvdParser()
# Invoke conver() function
result = parser.convert(svd_file)
Extras
The package also includes two command line tools:
- svd2yaml - Convert SVD file to YAML format,
- svd2json - Convert SVD file to JSON format.
svd2yaml
Usage: svd2yaml [OPTIONS] INPUT
svd2yaml - CMSIS SVD to YAML converter.
CMSIS SVD file parser that allows to convert SVD format to YAML data
structure
INPUT - path to SVD file.
Options:
--version Show the version and exit.
--help Show this message and exit.
svd2json
Usage: svd2json [OPTIONS] INPUT
svd2json - CMSIS SVD to JSON converter.
CMSIS SVD file parser that allows to convert SVD format to JSON data
structure
INPUT - path to SVD file.
Options:
--version Show the version and exit.
--help Show this message and exit.
Reference
class svd2py.SvdParser()
SVD file parser class. This is the main class for parsing SVD files.
convert(svd: Path | str)
svd - path to SVD file to parse.
Convert SVD file and return content in Python data structure.
It does not check SVD file syntax. If it is a proper XML file it will always return something.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file svd2py-1.0.2.tar.gz
.
File metadata
- Download URL: svd2py-1.0.2.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57dd020f5dc56fd90fa99de6667dfecf308081a311da45ffa4183e74e30c84ad |
|
MD5 | 3cef27c49cb59af66a5e2343fcf22476 |
|
BLAKE2b-256 | 171a9fc04939bfb6515c0c1d0f415efa1d8ceee43f3f301784e1ae13a2cb6bc5 |
File details
Details for the file svd2py-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: svd2py-1.0.2-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54fb340728d0b22cb373bbfa22d119dc3cb9c4eb15810c348cdc3c6d0c1f2576 |
|
MD5 | 639e3c8db7efd6c23bdb9f173255fd9d |
|
BLAKE2b-256 | 0943743fb6a6d2a90bb29545fc38e9f3b50507d53b2fc08b8130d2ba3507c95e |