Skip to content

Commit

Permalink
Merge pull request #4 from stm32-rs/backport-stm32-rs
Browse files Browse the repository at this point in the history
Backport stm32-rs changes to svdpatch.py
  • Loading branch information
nickray authored Jan 14, 2020
2 parents 44303a2 + 77ad9c0 commit 953f5e3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
15 changes: 10 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

## [Unreleased]

## [v0.1.0] 2020-01-20

* Backport two changes to stm32-rs svdpatch.py
* Set minor version so stm32-rs can potentially rely on this

## [v0.0.4] 2020-01-12

* Added `strip` & `_strip_end` patching options for stripping bitfields
* Add `strip` & `_strip_end` patching options for stripping bitfields

## [v0.0.3] 2020-01-10

* Added missing `black` and `isort` requirements - @jessebraham
* Added `_strip_end` as an option for patching - @jessebraham
* Add missing `black` and `isort` requirements - @jessebraham
* Add `_strip_end` as an option for patching - @jessebraham

## [v0.0.2] 2019-08-20

Expand All @@ -18,5 +23,5 @@
## [v0.0.1] 2019-08-17

* Initial release, importing from `stm32-rs/scripts/svdpatch.py`
* Added `click` CLI, to call as `svd patch <yaml-file>`
* Added packaging
* Add `click` CLI, to call as `svd patch <yaml-file>`
* Add packaging
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ maintainer-email = "[email protected]"
home-page = "https://github.com/stm32-rs/svdtools"
requires-python = ">=3.6"
requires = [
"click >= 7.0",
"PyYAML",
"click ~= 7.0",
"PyYAML ~= 5.3",
]
classifiers=[
"License :: OSI Approved :: MIT License",
Expand Down
2 changes: 1 addition & 1 deletion svdtools/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.4
0.1.0
22 changes: 16 additions & 6 deletions svdtools/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,27 +289,37 @@ def derive_peripheral(self, pname, pderive):
for p in parent.findall("./peripheral[@derivedFrom='{}']".format(pname)):
p.set("derivedFrom", pderive)

def copy_peripheral(self, pname, pmod):
def copy_peripheral(self, pname, pmod, path):
"""
Create copy of peripheral
"""
parent = self.device.find("peripherals")
ptag = parent.find("./peripheral[name='{}']".format(pname))
pcopyname = pmod["from"]
pcopy = copy.deepcopy(parent.find("./peripheral[name='{}']".format(pcopyname)))
pcopysrc = pmod["from"].split(":")
pcopyname = pcopysrc[-1]
if len(pcopysrc) == 2:
pcopyfile = abspath(path, pcopysrc[0])
filedev = Device(ET.parse(pcopyfile))
source = filedev.device.find("peripherals")
else:
source = parent
pcopy = copy.deepcopy(source.find("./peripheral[name='{}']".format(pcopyname)))
if pcopy is None:
raise SvdPatchError("peripheral {} not found".format(pcopy))
if ptag is None:
pcopy.find("name").text = pname
raise SvdPatchError("unimplemented")
if source is parent:
for value in list(pcopy):
if value.tag in ("interrupt"):
pcopy.remove(value)
else:
for value in list(ptag):
if value.tag in ("name", "baseAddress", "interrupt"):
tag = pcopy.find(value.tag)
if tag is not None:
pcopy.remove(tag)
pcopy.append(value)
parent.remove(ptag)
parent.remove(ptag)
parent.append(pcopy)

def rebase_peripheral(self, pnew, pold):
Expand Down Expand Up @@ -885,7 +895,7 @@ def process_device(svd, device, update_fields=True):
# Handle any copied peripherals
for pname in device.get("_copy", {}):
val = device["_copy"][pname]
d.copy_peripheral(pname, val)
d.copy_peripheral(pname, val, device["_path"])

# Handle any modifications
for key in device.get("_modify", {}):
Expand Down

0 comments on commit 953f5e3

Please sign in to comment.