Skip to content

Commit

Permalink
Auto generate memory.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Piroro-hs committed Apr 21, 2021
1 parent 22f9d06 commit 575c747
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 45 deletions.
81 changes: 45 additions & 36 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ default = ["unproven"]
unproven = ["embedded-hal/unproven"]
device-selected = []
direct-call-deprecated = []
ld = []
rt = ["stm32f3/rt"]
can = ["embedded-hal-can"]

Expand All @@ -75,6 +76,14 @@ svd-f303 = ["stm32f3/stm32f303"]
svd-f373 = ["stm32f3/stm32f373"]
svd-f3x4 = ["stm32f3/stm32f3x4"]

mem-4 = []
mem-6 = []
mem-8 = []
mem-b = []
mem-c = []
mem-d = []
mem-e = []

gpio-f302 = []
gpio-f303 = []
gpio-f303e = []
Expand All @@ -84,40 +93,40 @@ gpio-f373 = []
# Any changes here should be mirrored in README.md, src/lib.rs, and
# .github/workflows/ci.yml.
stm32f301 = ["svd-f301", "direct-call-deprecated"]
stm32f301x6 = ["stm32f301", "gpio-f302", "device-selected"]
stm32f301x8 = ["stm32f301", "gpio-f302", "device-selected"]
stm32f301x6 = ["stm32f301", "mem-6", "gpio-f302", "device-selected"]
stm32f301x8 = ["stm32f301", "mem-8", "gpio-f302", "device-selected"]
stm32f318 = ["svd-f301", "direct-call-deprecated"]
stm32f318x8 = ["stm32f318", "gpio-f302", "device-selected"]
stm32f318x8 = ["stm32f318", "mem-8", "gpio-f302", "device-selected"]
stm32f302 = ["svd-f302", "direct-call-deprecated"]
stm32f302x6 = ["stm32f302", "gpio-f302", "device-selected"]
stm32f302x8 = ["stm32f302", "gpio-f302", "device-selected"]
stm32f302xb = ["stm32f302", "gpio-f303", "device-selected"]
stm32f302xc = ["stm32f302", "gpio-f303", "device-selected"]
stm32f302xd = ["stm32f302", "gpio-f303e", "device-selected"]
stm32f302xe = ["stm32f302", "gpio-f303e", "device-selected"]
stm32f302x6 = ["stm32f302", "mem-6", "gpio-f302", "device-selected"]
stm32f302x8 = ["stm32f302", "mem-8", "gpio-f302", "device-selected"]
stm32f302xb = ["stm32f302", "mem-b", "gpio-f303", "device-selected"]
stm32f302xc = ["stm32f302", "mem-c", "gpio-f303", "device-selected"]
stm32f302xd = ["stm32f302", "mem-d", "gpio-f303e", "device-selected"]
stm32f302xe = ["stm32f302", "mem-e", "gpio-f303e", "device-selected"]
stm32f303 = ["svd-f303", "direct-call-deprecated"]
stm32f303x6 = ["stm32f303", "gpio-f333", "device-selected"]
stm32f303x8 = ["stm32f303", "gpio-f333", "device-selected"]
stm32f303xb = ["stm32f303", "gpio-f303", "device-selected"]
stm32f303xc = ["stm32f303", "gpio-f303", "device-selected"]
stm32f303xd = ["stm32f303", "gpio-f303e", "device-selected"]
stm32f303xe = ["stm32f303", "gpio-f303e", "device-selected"]
stm32f303x6 = ["stm32f303", "mem-6", "gpio-f333", "device-selected"]
stm32f303x8 = ["stm32f303", "mem-8", "gpio-f333", "device-selected"]
stm32f303xb = ["stm32f303", "mem-b", "gpio-f303", "device-selected"]
stm32f303xc = ["stm32f303", "mem-c", "gpio-f303", "device-selected"]
stm32f303xd = ["stm32f303", "mem-d", "gpio-f303e", "device-selected"]
stm32f303xe = ["stm32f303", "mem-e", "gpio-f303e", "device-selected"]
stm32f328 = ["svd-f303", "direct-call-deprecated"]
stm32f328x8 = ["stm32f328", "gpio-f333", "device-selected"]
stm32f328x8 = ["stm32f328", "mem-8", "gpio-f333", "device-selected"]
stm32f358 = ["svd-f303", "direct-call-deprecated"]
stm32f358xc = ["stm32f358", "gpio-f303", "device-selected"]
stm32f358xc = ["stm32f358", "mem-c", "gpio-f303", "device-selected"]
stm32f398 = ["svd-f303", "direct-call-deprecated"]
stm32f398xe = ["stm32f398", "gpio-f303e", "device-selected"]
stm32f398xe = ["stm32f398", "mem-e", "gpio-f303e", "device-selected"]
stm32f373 = ["svd-f373", "direct-call-deprecated"]
stm32f373x8 = ["stm32f373", "gpio-f373", "device-selected"]
stm32f373xb = ["stm32f373", "gpio-f373", "device-selected"]
stm32f373xc = ["stm32f373", "gpio-f373", "device-selected"]
stm32f373x8 = ["stm32f373", "mem-8", "gpio-f373", "device-selected"]
stm32f373xb = ["stm32f373", "mem-b", "gpio-f373", "device-selected"]
stm32f373xc = ["stm32f373", "mem-c", "gpio-f373", "device-selected"]
stm32f378 = ["svd-f373", "direct-call-deprecated"]
stm32f378xc = ["stm32f378", "gpio-f373", "device-selected"]
stm32f378xc = ["stm32f378", "mem-c", "gpio-f373", "device-selected"]
stm32f334 = ["svd-f3x4", "direct-call-deprecated"]
stm32f334x4 = ["stm32f334", "gpio-f333", "device-selected"]
stm32f334x6 = ["stm32f334", "gpio-f333", "device-selected"]
stm32f334x8 = ["stm32f334", "gpio-f333", "device-selected"]
stm32f334x4 = ["stm32f334", "mem-4", "gpio-f333", "device-selected"]
stm32f334x6 = ["stm32f334", "mem-6", "gpio-f333", "device-selected"]
stm32f334x8 = ["stm32f334", "mem-8", "gpio-f333", "device-selected"]

defmt-default = ["defmt"]
defmt-trace = ["defmt"]
Expand All @@ -137,45 +146,45 @@ opt-level = "s"

[[example]]
name = "pwm"
required-features = ["stm32f303xc"]
required-features = ["ld", "stm32f303xc"]

[[example]]
name = "toggle"
required-features = ["rt", "stm32f303xc"]
required-features = ["ld", "stm32f303xc"]

[[example]]
name = "usb_serial"
required-features = ["rt", "stm32f303xc", "stm32-usbd"]
required-features = ["ld", "stm32f303xc", "stm32-usbd"]

[[example]]
name = "spi"
required-features = ["stm32f303"]
required-features = ["ld", "stm32f303"]

[[example]]
name = "can"
required-features = ["rt", "can", "stm32f303"]
required-features = ["ld", "can", "stm32f303"]

[[example]]
name = "serial_dma"
required-features = ["stm32f303"]
required-features = ["ld", "stm32f303"]

[[example]]
name = "adc"
required-features = ["stm32f303"]
required-features = ["ld", "stm32f303"]

[[example]]
name = "i2c_scanner"
required-features = ["stm32f303xc"]
required-features = ["ld", "stm32f303xc"]

[[example]]
name = "gpio_erased"
required-features = ["rt", "stm32f303xc"]
required-features = ["ld", "stm32f303xc"]

[[example]]
name = "gpio_interrupts"
required-features = ["rt", "stm32f303xc"]
required-features = ["ld", "rt", "stm32f303xc"]

[[test]]
name = "rcc"
required-features = ["rt", "defmt"]
required-features = ["defmt"]
harness = false
65 changes: 65 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use std::{env, fs::File, io::prelude::*, path::PathBuf};

fn main() {
if cfg!(feature = "ld") {
gen_memory_x();
}
println!("cargo:rerun-if-changed=build.rs");
}

fn gen_memory_x() {
#![allow(clippy::unneeded_wildcard_pattern)]

let mem_cfg_set = (
cfg!(feature = "mem-4"),
cfg!(feature = "mem-6"),
cfg!(feature = "mem-8"),
cfg!(feature = "mem-b"),
cfg!(feature = "mem-c"),
cfg!(feature = "mem-d"),
cfg!(feature = "mem-e"),
);
let flash = match mem_cfg_set {
(true, ..) => 16,
(_, true, ..) => 32,
(_, _, true, ..) => 64,
(.., true, _, _, _) => 128,
(.., _, true, _, _) => 256,
(.., _, _, true, _) => 384,
(.., _, _, _, true) => 512,
_ => unreachable!(),
};
let ccmram = if cfg!(feature = "svd-f303") || cfg!(feature = "svd-f3x4") {
match mem_cfg_set {
(true, ..) | (_, true, ..) | (_, _, true, ..) => 4,
(.., true, _, _, _) | (.., _, true, _, _) => 8,
(.., _, _, true, _) | (.., _, _, _, true) => 16,
_ => unreachable!(),
}
} else {
0
};
let ram = match mem_cfg_set {
(true, ..) | (_, true, ..) | (_, _, true, ..) => 16,
(.., true, _, _, _) if cfg!(feature = "svd-f373") => 24,
(.., true, _, _, _) if cfg!(feature = "svd-f302") => 32,
(.., _, true, _, _) if cfg!(feature = "svd-f373") => 32,
(.., true, _, _, _) if cfg!(feature = "svd-f303") => 40,
(.., _, true, _, _) if cfg!(feature = "svd-f302") => 40,
(.., _, true, _, _) if cfg!(feature = "svd-f303") => 48,
(.., _, _, true, _) | (.., _, _, _, true) if cfg!(feature = "svd-f302") => 64,
(.., _, _, true, _) | (.., _, _, _, true) if cfg!(feature = "svd-f303") => 80,
_ => unreachable!(),
} - ccmram;

let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let mut file = File::create(out_dir.join("memory.x")).unwrap();
writeln!(file, "MEMORY {{").unwrap();
writeln!(file, " FLASH (rx) : o = 0x8000000, l = {}K", flash).unwrap();
if ccmram > 0 {
writeln!(file, " CCMRAM (rwx) : o = 0x10000000, l = {}K", ccmram).unwrap();
}
writeln!(file, " RAM (rwx) : o = 0x20000000, l = {}K", ram).unwrap();
writeln!(file, "}}").unwrap();
println!("cargo:rustc-link-search={}", out_dir.display());
}
9 changes: 0 additions & 9 deletions memory.x

This file was deleted.

0 comments on commit 575c747

Please sign in to comment.