aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Kröger <[email protected]>2021-08-04 12:43:51 +0200
committerTimo Kröger <[email protected]>2021-08-04 12:43:51 +0200
commite21faaeb47e84b57ffb748b289b5dcba6cc52118 (patch)
tree313b90e268bac75185ce1949b630af9fc63e0262
parentb36337b3d23e99a23968deb7e8d5c65119e9bf0d (diff)
cargo fmt
-rw-r--r--stm32-metapac-gen/src/lib.rs37
1 files changed, 28 insertions, 9 deletions
diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs
index b10f250de..abeb6d846 100644
--- a/stm32-metapac-gen/src/lib.rs
+++ b/stm32-metapac-gen/src/lib.rs
@@ -446,8 +446,8 @@ pub fn gen(options: Options) {
446 let clock = match &p.clock { 446 let clock = match &p.clock {
447 Some(clock) => clock.as_str(), 447 Some(clock) => clock.as_str(),
448 None => { 448 None => {
449 // No clock was specified, derive the clock name from the enable register name. 449 // No clock was specified, derive the clock name from the enable register name.
450 let re = Regex::new("([A-Z]+\\d*).*").unwrap(); 450 let re = Regex::new("([A-Z]+\\d*).*").unwrap();
451 let caps = re.captures(enable_reg).expect( 451 let caps = re.captures(enable_reg).expect(
452 "unable to derive clock name from register name {}", 452 "unable to derive clock name from register name {}",
453 ); 453 );
@@ -666,7 +666,6 @@ pub fn gen(options: Options) {
666 let re = Regex::new("# *! *\\[.*\\]").unwrap(); 666 let re = Regex::new("# *! *\\[.*\\]").unwrap();
667 let data = re.replace_all(&data, ""); 667 let data = re.replace_all(&data, "");
668 file.write_all(data.as_bytes()).unwrap(); 668 file.write_all(data.as_bytes()).unwrap();
669
670 } 669 }
671 670
672 // Generate src/lib_inner.rs 671 // Generate src/lib_inner.rs
@@ -727,7 +726,6 @@ pub fn gen(options: Options) {
727 726
728 // Generate build.rs 727 // Generate build.rs
729 fs::write(out_dir.join("build.rs"), include_bytes!("assets/build.rs")).unwrap(); 728 fs::write(out_dir.join("build.rs"), include_bytes!("assets/build.rs")).unwrap();
730
731} 729}
732 730
733fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option<usize> { 731fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option<usize> {
@@ -739,19 +737,40 @@ fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option<usize> {
739fn gen_memory_x(out_dir: &PathBuf, chip: &Chip) { 737fn gen_memory_x(out_dir: &PathBuf, chip: &Chip) {
740 let mut memory_x = String::new(); 738 let mut memory_x = String::new();
741 739
742 let flash_bytes = chip.flash.regions.get("BANK_1").unwrap().bytes.unwrap_or(chip.flash.bytes); 740 let flash_bytes = chip
741 .flash
742 .regions
743 .get("BANK_1")
744 .unwrap()
745 .bytes
746 .unwrap_or(chip.flash.bytes);
743 let flash_origin = chip.flash.regions.get("BANK_1").unwrap().base; 747 let flash_origin = chip.flash.regions.get("BANK_1").unwrap().base;
744 748
745 let ram_bytes = chip.ram.regions.get("SRAM").unwrap().bytes.unwrap_or(chip.ram.bytes); 749 let ram_bytes = chip
750 .ram
751 .regions
752 .get("SRAM")
753 .unwrap()
754 .bytes
755 .unwrap_or(chip.ram.bytes);
746 let ram_origin = chip.ram.regions.get("SRAM").unwrap().base; 756 let ram_origin = chip.ram.regions.get("SRAM").unwrap().base;
747 757
748 write!(memory_x, "MEMORY\n{{\n").unwrap(); 758 write!(memory_x, "MEMORY\n{{\n").unwrap();
749 write!(memory_x, " FLASH : ORIGIN = 0x{:x}, LENGTH = {}\n", flash_origin, flash_bytes).unwrap(); 759 write!(
750 write!(memory_x, " RAM : ORIGIN = 0x{:x}, LENGTH = {}\n", ram_origin, ram_bytes).unwrap(); 760 memory_x,
761 " FLASH : ORIGIN = 0x{:x}, LENGTH = {}\n",
762 flash_origin, flash_bytes
763 )
764 .unwrap();
765 write!(
766 memory_x,
767 " RAM : ORIGIN = 0x{:x}, LENGTH = {}\n",
768 ram_origin, ram_bytes
769 )
770 .unwrap();
751 write!(memory_x, "}}").unwrap(); 771 write!(memory_x, "}}").unwrap();
752 772
753 fs::create_dir_all(out_dir.join("memory_x")).unwrap(); 773 fs::create_dir_all(out_dir.join("memory_x")).unwrap();
754 let mut file = File::create(out_dir.join("memory_x").join("memory.x")).unwrap(); 774 let mut file = File::create(out_dir.join("memory_x").join("memory.x")).unwrap();
755 file.write_all(memory_x.as_bytes()).unwrap(); 775 file.write_all(memory_x.as_bytes()).unwrap();
756
757} 776}