Skip to content

Class for processing SVD documents and transforming those into dictionary

License

Notifications You must be signed in to change notification settings

MightyDevices/python-cmsis-svd-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-cmsis-svd-parser

Class for processing SVD documents and transforming those into a dictionary and back again! Supports 1.3 version of the CMSIS-SVD schema. Helps A LOT if you are trying to generate the header files for your MCU projects!

What is returned

Dictionary returned after parsing is a nested one (obviously). Levels of hierarchy are as follows

  • device - top of the dictionary
    • cpu - additional info about cpu employed in particular mcu
  • peripherals - list of all peripherals
    • interrups - list of interrupts defined by the peripheral
  • clusters | registers - peripheral may contain bare registers or clusters of registers. Clusters may be nested. Registers may not, obviously.
  • fields - bit-fields of particular registers
  • enumerated_values - name and list of enumerated values applicable for a given field
  • enumerated_value - single enumerated value

Usage

# import the xml parser
import xml.etree.ElementTree as ET
# import the svd reader/writer
from SVDWriter import SVDWriter
from SVDReader import SVDReader

# load the file using xml parser
root = ET.parse('example.svd').getroot()
# parse the device file
device = SVDReader.process(root)

#
# DO YOUR STUFF HERE
#

# process back to the xml tree
xml = SVDWriter.process(device, make_pretty=True)
# convert to string and save to file
open("test.svd", "wb").write(ET.tostring(xml))

Example

Please see the Examples directory for a quick demonstration. Run the example by typing: python ListPeriphRegs.py or python ReadWriteSVD.py in the Examples directory

About

Class for processing SVD documents and transforming those into dictionary

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages