Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This changelog tracks the Rust `svdtools` project. See

## [Unreleased]

## [v0.4.3] 2025-01-31

* Allow shorthand when `_derive` across clusters

## [v0.4.2] 2025-01-25

* Fix optional `fspec` in `set_field_modified_write_values`
Expand Down Expand Up @@ -209,7 +213,8 @@ Other changes:

* Initial release with feature-parity with the Python project.

[Unreleased]: https://github.com/rust-embedded/svdtools/compare/v0.4.2...HEAD
[Unreleased]: https://github.com/rust-embedded/svdtools/compare/v0.4.3...HEAD
[v0.4.3]: https://github.com/rust-embedded/svdtools/compare/v0.4.2...v0.4.3
[v0.4.2]: https://github.com/rust-embedded/svdtools/compare/v0.4.1...v0.4.2
[v0.4.1]: https://github.com/rust-embedded/svdtools/compare/v0.4.0...v0.4.1
[v0.4.0]: https://github.com/rust-embedded/svdtools/compare/v0.3.21...v0.4.0
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "svdtools"
version = "0.4.2"
version = "0.4.3"
repository = "https://github.com/rust-embedded/svdtools/"
description = "Tool for modifying bugs in CMSIS SVD"
authors = ["Andrey Zgarbul <zgarbul.andrey@gmail.com>", "MarcoIeni"]
Expand Down
20 changes: 16 additions & 4 deletions src/patch/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,24 @@ pub(crate) trait RegisterBlockExt: Name {
/// Remove fields from rname and mark it as derivedFrom rderive.
/// Update all derivedFrom referencing rname
fn derive_register(&mut self, rspec: &str, rderive: &Yaml, bpath: &BlockPath) -> PatchResult {
fn make_path(dpath: &str, bpath: &BlockPath) -> String {
let mut parts = dpath.split(".");
match (parts.next(), parts.next(), parts.next()) {
(Some(cname), Some(rname), None) if !bpath.path.is_empty() => bpath
.parent()
.unwrap()
.new_cluster(cname)
.new_register(rname)
.to_string(),
_ => dpath.into(),
}
}
let (rspec, ignore) = rspec.spec();
let (rderive, dim, info) = if let Some(rderive) = rderive.as_str() {
(
rderive,
None,
RegisterInfo::builder().derived_from(Some(rderive.into())),
RegisterInfo::builder().derived_from(Some(make_path(rderive, bpath))),
)
} else if let Some(hash) = rderive.as_hash() {
let rderive = hash.get_str("_from")?.ok_or_else(|| {
Expand All @@ -261,7 +273,7 @@ pub(crate) trait RegisterBlockExt: Name {
(
rderive,
make_dim_element(hash)?,
make_register(hash, Some(bpath))?.derived_from(Some(rderive.into())),
make_register(hash, Some(bpath))?.derived_from(Some(make_path(rderive, bpath))),
)
} else {
return Err(anyhow!("derive: incorrect syntax for {rspec}"));
Expand Down Expand Up @@ -1783,11 +1795,12 @@ fn collect_in_cluster(
.address_offset(address_offset);
let mut config = config.clone();
config.update_fields = true;
let cpath = path.new_cluster(cname);
let mut cluster = if single {
for (_, (rmod, mut registers)) in rdict.into_iter() {
let mut reg = registers.swap_remove(0);
let rmod = rmod.hash()?;
reg.process(rmod, &path.new_cluster(cname), &config)
reg.process(rmod, &cpath, &config)
.with_context(|| format!("Processing register `{}`", reg.name))?;
if let Some(name) = rmod.get_str("name")? {
reg.name = name.into();
Expand All @@ -1801,7 +1814,6 @@ fn collect_in_cluster(
for (rspec, (rmod, mut registers)) in rdict.into_iter() {
let mut reg = registers.swap_remove(0);
let rmod = rmod.hash()?;
let cpath = path.new_cluster(cname);
reg.process(rmod, &cpath, &config)
.with_context(|| format!("Processing register `{}`", reg.name))?;
reg.name = if let Some(name) = rmod.get_str("name")? {
Expand Down
21 changes: 16 additions & 5 deletions src/patch/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,22 @@ impl RegisterExt for Register {
fn derive_field(&mut self, fspec: &str, fderive: &Yaml, rpath: &RegisterPath) -> PatchResult {
fn make_path(dpath: &str, rpath: &RegisterPath) -> String {
let mut parts = dpath.split(".");
if let (Some(reg), Some(field), None) = (parts.next(), parts.next(), parts.next()) {
let fpath = rpath.block.new_register(reg).new_field(field);
fpath.to_string()
} else {
dpath.into()
match (parts.next(), parts.next(), parts.next(), parts.next()) {
(Some(cname), Some(rname), Some(fname), None) if !rpath.block.path.is_empty() => {
let fpath = rpath
.block
.parent()
.unwrap()
.new_cluster(cname)
.new_register(rname)
.new_field(fname);
fpath.to_string()
}
(Some(reg), Some(field), None, None) => {
let fpath = rpath.block.new_register(reg).new_field(field);
fpath.to_string()
}
_ => dpath.into(),
}
}
let (fspec, ignore) = fspec.spec();
Expand Down