diff options
| -rw-r--r-- | embassy-stm32/src/lib.rs | 4 | ||||
| -rw-r--r-- | examples/stm32f4/build.rs | 31 | ||||
| -rw-r--r-- | examples/stm32f4/memory.x | 7 | ||||
| -rw-r--r-- | examples/stm32h7/build.rs | 21 | ||||
| -rw-r--r-- | examples/stm32h7/memory.x | 5 | ||||
| m--------- | stm32-data | 0 | ||||
| -rw-r--r-- | stm32-metapac-gen/src/assets/build.rs | 8 | ||||
| -rw-r--r-- | stm32-metapac-gen/src/lib.rs | 40 |
8 files changed, 49 insertions, 67 deletions
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 89fd86448..b5fe29d61 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -39,7 +39,9 @@ pub mod eth; | |||
| 39 | pub mod exti; | 39 | pub mod exti; |
| 40 | #[cfg(i2c)] | 40 | #[cfg(i2c)] |
| 41 | pub mod i2c; | 41 | pub mod i2c; |
| 42 | #[cfg(pwr)] | 42 | |
| 43 | // until we have all PWR covered. | ||
| 44 | #[cfg(all(any(pwr_h7, pwr_h7smps), pwr))] | ||
| 43 | pub mod pwr; | 45 | pub mod pwr; |
| 44 | #[cfg(rng)] | 46 | #[cfg(rng)] |
| 45 | pub mod rng; | 47 | pub mod rng; |
diff --git a/examples/stm32f4/build.rs b/examples/stm32f4/build.rs deleted file mode 100644 index d534cc3df..000000000 --- a/examples/stm32f4/build.rs +++ /dev/null | |||
| @@ -1,31 +0,0 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | } | ||
diff --git a/examples/stm32f4/memory.x b/examples/stm32f4/memory.x deleted file mode 100644 index f21e32572..000000000 --- a/examples/stm32f4/memory.x +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | /* These values correspond to the STM32F429ZI */ | ||
| 5 | FLASH : ORIGIN = 0x08000000, LENGTH = 2048K | ||
| 6 | RAM : ORIGIN = 0x20000000, LENGTH = 192K | ||
| 7 | } | ||
diff --git a/examples/stm32h7/build.rs b/examples/stm32h7/build.rs deleted file mode 100644 index 555cdf687..000000000 --- a/examples/stm32h7/build.rs +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | use std::env; | ||
| 2 | use std::fs::File; | ||
| 3 | use std::io::Write; | ||
| 4 | use std::path::PathBuf; | ||
| 5 | |||
| 6 | fn main() { | ||
| 7 | // Put `memory.x` in our output directory and ensure it's | ||
| 8 | // on the linker search path. | ||
| 9 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 10 | File::create(out.join("memory.x")) | ||
| 11 | .unwrap() | ||
| 12 | .write_all(include_bytes!("memory.x")) | ||
| 13 | .unwrap(); | ||
| 14 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 15 | |||
| 16 | // By default, Cargo will re-run a build script whenever | ||
| 17 | // any file in the project changes. By specifying `memory.x` | ||
| 18 | // here, we ensure the build script is only re-run when | ||
| 19 | // `memory.x` is changed. | ||
| 20 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 21 | } | ||
diff --git a/examples/stm32h7/memory.x b/examples/stm32h7/memory.x deleted file mode 100644 index ef9485d12..000000000 --- a/examples/stm32h7/memory.x +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | FLASH : ORIGIN = 0x08000000, LENGTH = 2048K | ||
| 4 | RAM : ORIGIN = 0x24000000, LENGTH = 384K | ||
| 5 | } | ||
diff --git a/stm32-data b/stm32-data | |||
| Subproject 0ad27b2fd1126c6c9d9f4602d1331f5d82f4aa2 | Subproject f36d629d54840b8f76a89fbd1f179aa1c31702b | ||
diff --git a/stm32-metapac-gen/src/assets/build.rs b/stm32-metapac-gen/src/assets/build.rs index c16bd6407..13050315e 100644 --- a/stm32-metapac-gen/src/assets/build.rs +++ b/stm32-metapac-gen/src/assets/build.rs | |||
| @@ -9,6 +9,14 @@ fn main() { | |||
| 9 | .unwrap() | 9 | .unwrap() |
| 10 | .to_ascii_lowercase(); | 10 | .to_ascii_lowercase(); |
| 11 | 11 | ||
| 12 | // Put `memory.x` in our output directory and ensure it's | ||
| 13 | // on the linker search path. | ||
| 14 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 15 | //File::create(out.join("memory.x")) | ||
| 16 | //.unwrap() | ||
| 17 | //.write_all(include_bytes!("memory.x")) | ||
| 18 | //.unwrap(); | ||
| 19 | |||
| 12 | #[cfg(feature = "rt")] | 20 | #[cfg(feature = "rt")] |
| 13 | println!("cargo:rustc-link-search=src/chips/{}", _chip_name); | 21 | println!("cargo:rustc-link-search=src/chips/{}", _chip_name); |
| 14 | 22 | ||
diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index f508b3658..93b811168 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs | |||
| @@ -19,12 +19,24 @@ pub struct Chip { | |||
| 19 | pub family: String, | 19 | pub family: String, |
| 20 | pub line: String, | 20 | pub line: String, |
| 21 | pub cores: Vec<Core>, | 21 | pub cores: Vec<Core>, |
| 22 | pub flash: u32, | 22 | pub flash: Memory, |
| 23 | pub ram: u32, | 23 | pub ram: Memory, |
| 24 | pub packages: Vec<Package>, | 24 | pub packages: Vec<Package>, |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] | 27 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] |
| 28 | pub struct Memory { | ||
| 29 | pub bytes: u32, | ||
| 30 | pub regions: HashMap<String, MemoryRegion>, | ||
| 31 | } | ||
| 32 | |||
| 33 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] | ||
| 34 | pub struct MemoryRegion { | ||
| 35 | pub base: u32, | ||
| 36 | pub bytes: Option<u32>, | ||
| 37 | } | ||
| 38 | |||
| 39 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] | ||
| 28 | pub struct Core { | 40 | pub struct Core { |
| 29 | pub name: String, | 41 | pub name: String, |
| 30 | pub peripherals: HashMap<String, Peripheral>, | 42 | pub peripherals: HashMap<String, Peripheral>, |
| @@ -636,6 +648,9 @@ pub fn gen(options: Options) { | |||
| 636 | .unwrap() | 648 | .unwrap() |
| 637 | .write_all(device_x.as_bytes()) | 649 | .write_all(device_x.as_bytes()) |
| 638 | .unwrap(); | 650 | .unwrap(); |
| 651 | |||
| 652 | // generate default memory.x | ||
| 653 | gen_memory_x(&chip_dir, &chip); | ||
| 639 | } | 654 | } |
| 640 | 655 | ||
| 641 | for (module, version) in all_peripheral_versions { | 656 | for (module, version) in all_peripheral_versions { |
| @@ -674,6 +689,7 @@ pub fn gen(options: Options) { | |||
| 674 | let re = Regex::new("# *! *\\[.*\\]").unwrap(); | 689 | let re = Regex::new("# *! *\\[.*\\]").unwrap(); |
| 675 | let data = re.replace_all(&data, ""); | 690 | let data = re.replace_all(&data, ""); |
| 676 | file.write_all(data.as_bytes()).unwrap(); | 691 | file.write_all(data.as_bytes()).unwrap(); |
| 692 | |||
| 677 | } | 693 | } |
| 678 | 694 | ||
| 679 | // Generate src/lib_inner.rs | 695 | // Generate src/lib_inner.rs |
| @@ -734,6 +750,7 @@ pub fn gen(options: Options) { | |||
| 734 | 750 | ||
| 735 | // Generate build.rs | 751 | // Generate build.rs |
| 736 | fs::write(out_dir.join("build.rs"), include_bytes!("assets/build.rs")).unwrap(); | 752 | fs::write(out_dir.join("build.rs"), include_bytes!("assets/build.rs")).unwrap(); |
| 753 | |||
| 737 | } | 754 | } |
| 738 | 755 | ||
| 739 | fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option<usize> { | 756 | fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option<usize> { |
| @@ -741,3 +758,22 @@ fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option<usize> { | |||
| 741 | .windows(needle.len()) | 758 | .windows(needle.len()) |
| 742 | .position(|window| window == needle) | 759 | .position(|window| window == needle) |
| 743 | } | 760 | } |
| 761 | |||
| 762 | fn gen_memory_x(out_dir: &PathBuf, chip: &Chip) { | ||
| 763 | let mut memory_x = String::new(); | ||
| 764 | |||
| 765 | let flash_bytes = chip.flash.regions.get("BANK_1").unwrap().bytes.unwrap(); | ||
| 766 | let flash_origin = chip.flash.regions.get("BANK_1").unwrap().base; | ||
| 767 | |||
| 768 | let ram_bytes = chip.ram.regions.get("SRAM").unwrap().bytes.unwrap(); | ||
| 769 | let ram_origin = chip.ram.regions.get("SRAM").unwrap().base; | ||
| 770 | |||
| 771 | write!(memory_x, "MEMORY\n{{\n").unwrap(); | ||
| 772 | write!(memory_x, " FLASH : ORIGIN = 0x{:x}, LENGTH = {}\n", flash_origin, flash_bytes).unwrap(); | ||
| 773 | write!(memory_x, " RAM : ORIGIN = 0x{:x}, LENGTH = {}\n", ram_origin, ram_bytes).unwrap(); | ||
| 774 | write!(memory_x, "}}").unwrap(); | ||
| 775 | |||
| 776 | let mut file = File::create(out_dir.join("memory.x")).unwrap(); | ||
| 777 | file.write_all( memory_x.as_bytes() ).unwrap(); | ||
| 778 | |||
| 779 | } | ||
