Skip to content

Commit 651da2d

Browse files
committed
Add base-address-shift configuration flag
1 parent e21c210 commit 651da2d

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
99

10+
- Add `base-address-shift` config flag
11+
1012
## [v0.31.5] - 2024-01-04
1113

1214
- `move` in `RegisterBlock::reg_iter` implementation (iterator of register/cluster array)

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct Config {
2828
pub reexport_core_peripherals: bool,
2929
pub reexport_interrupt: bool,
3030
pub ident_formats: IdentFormats,
31+
pub base_address_shift: u64,
3132
}
3233

3334
#[allow(clippy::upper_case_acronyms)]

src/generate/peripheral.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
4040
let span = Span::call_site();
4141
let p_ty = ident(&name, &config.ident_formats.peripheral, span);
4242
let name_str = p_ty.to_string();
43-
let address = util::hex(p.base_address);
43+
let address = util::hex(p.base_address + config.base_address_shift);
4444
let description = util::respace(p.description.as_ref().unwrap_or(&p.name));
4545

4646
let mod_ty = name.to_snake_case_ident(span);
@@ -83,7 +83,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
8383
let description = pi.description.as_deref().unwrap_or(&p.name);
8484
let p_ty = ident(name, &config.ident_formats.peripheral, span);
8585
let name_str = p_ty.to_string();
86-
let address = util::hex(pi.base_address);
86+
let address = util::hex(pi.base_address + config.base_address_shift);
8787
let p_snake = name.to_sanitized_snake_case();
8888
snake_names.push(p_snake.to_string());
8989
let mut feature_attribute_n = feature_attribute.clone();

src/main.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,12 @@ fn run() -> Result<()> {
171171
.action(ArgAction::SetTrue)
172172
.help("Make advanced checks due to parsing SVD"),
173173
)
174-
// TODO: deprecate
175174
.arg(
176175
Arg::new("pascal_enum_values")
177176
.long("pascal-enum-values")
178177
.alias("pascal_enum_values")
179178
.action(ArgAction::SetTrue)
180-
.help("Use PascalCase in stead of CONSTANT_CASE for enumerated values"),
179+
.help("Use PascalCase in stead of UPPER_CASE for enumerated values"),
181180
)
182181
.arg(
183182
Arg::new("source_type")
@@ -199,6 +198,17 @@ fn run() -> Result<()> {
199198
.action(ArgAction::SetTrue)
200199
.help("Reexport interrupt macro from cortex-m-rt like crates"),
201200
)
201+
.arg(
202+
Arg::new("base_address_shift")
203+
.short('b')
204+
.long("base-address-shift")
205+
.alias("base_address_shift")
206+
.action(ArgAction::Set)
207+
.help("Add offset to all base addresses on all peripherals in the SVD file.")
208+
.long_help("Add offset to all base addresses on all peripherals in the SVD file.
209+
Useful for soft-cores where the peripheral address range isn't necessarily fixed.
210+
Ignore this option if you are not building your own FPGA based soft-cores."),
211+
)
202212
.arg(
203213
Arg::new("log_level")
204214
.long("log")
@@ -249,9 +259,6 @@ fn run() -> Result<()> {
249259
config.source_type = SourceType::from_path(file)
250260
}
251261
let path = config.output_dir.as_deref().unwrap_or(Path::new("."));
252-
if config.pascal_enum_values {
253-
config.ident_formats.enum_value.case = Some(svd2rust::config::Case::Pascal);
254-
}
255262

256263
info!("Parsing device from SVD file");
257264
let device = load_from(input, &config)?;

0 commit comments

Comments
 (0)