diff --git a/CHANGELOG.md b/CHANGELOG.md index b27ed24b..098ac4de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] +- Add `base-address-shift` config flag + ## [v0.31.5] - 2024-01-04 - `move` in `RegisterBlock::reg_iter` implementation (iterator of register/cluster array) diff --git a/src/config.rs b/src/config.rs index 8a359dd1..644e59a1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -28,6 +28,7 @@ pub struct Config { pub reexport_core_peripherals: bool, pub reexport_interrupt: bool, pub ident_formats: IdentFormats, + pub base_address_shift: u64, } #[allow(clippy::upper_case_acronyms)] diff --git a/src/generate/peripheral.rs b/src/generate/peripheral.rs index 9e50d123..5f1cae85 100644 --- a/src/generate/peripheral.rs +++ b/src/generate/peripheral.rs @@ -40,7 +40,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result let span = Span::call_site(); let p_ty = ident(&name, &config.ident_formats.peripheral, span); let name_str = p_ty.to_string(); - let address = util::hex(p.base_address); + let address = util::hex(p.base_address + config.base_address_shift); let description = util::respace(p.description.as_ref().unwrap_or(&p.name)); let mod_ty = name.to_snake_case_ident(span); @@ -83,7 +83,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result let description = pi.description.as_deref().unwrap_or(&p.name); let p_ty = ident(name, &config.ident_formats.peripheral, span); let name_str = p_ty.to_string(); - let address = util::hex(pi.base_address); + let address = util::hex(pi.base_address + config.base_address_shift); let p_snake = name.to_sanitized_snake_case(); snake_names.push(p_snake.to_string()); let mut feature_attribute_n = feature_attribute.clone(); diff --git a/src/main.rs b/src/main.rs index c9a6f379..6c366fea 100755 --- a/src/main.rs +++ b/src/main.rs @@ -199,6 +199,17 @@ fn run() -> Result<()> { .action(ArgAction::SetTrue) .help("Reexport interrupt macro from cortex-m-rt like crates"), ) + .arg( + Arg::new("base_address_shift") + .short('b') + .long("base-address-shift") + .alias("base_address_shift") + .action(ArgAction::Set) + .help("Add offset to all base addresses on all peripherals in the SVD file.") + .long_help("Add offset to all base addresses on all peripherals in the SVD file. +Useful for soft-cores where the peripheral address range isn't necessarily fixed. +Ignore this option if you are not building your own FPGA based soft-cores."), + ) .arg( Arg::new("log_level") .long("log")