Repository: probe-rs/probe-rs
Pull request #2521 (2024-05-31 06:47:13)

target-gen: Import from probe-rs-target directly
This PR helps highlighting what target-gen needs from probe-rs.


Patch:
diff --git a/probe-rs-tools/src/bin/probe-rs/util/rtt.rs b/probe-rs-tools/src/bin/probe-rs/util/rtt.rs
index 8380ecd2..a8324be9 100644
--- a/probe-rs-tools/src/bin/probe-rs/util/rtt.rs
+++ b/probe-rs-tools/src/bin/probe-rs/util/rtt.rs
@@ -114,7 +114,7 @@ impl RttConfig {
 }
 
 /// The User specified configuration for each active RTT Channel.
-#[derive(Debug, Clone, Serialize, Deserialize, Default)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
 #[serde(rename_all = "camelCase")]
 pub struct RttChannelConfig {
     pub channel_number: Option<usize>,
@@ -138,6 +138,19 @@ pub struct RttChannelConfig {
     pub log_format: Option<String>,
 }
 
+impl Default for RttChannelConfig {
+    fn default() -> Self {
+        RttChannelConfig {
+            channel_number: Default::default(),
+            data_format: Default::default(),
+            mode: Default::default(),
+            show_timestamps: default_show_timestamps(),
+            show_location: Default::default(),
+            log_format: Default::default(),
+        }
+    }
+}
+
 pub enum ChannelDataFormat {
     String {
         /// UTC offset used for creating timestamps, if enabled.
diff --git a/target-gen/src/algorithm_binary.rs b/target-gen/src/algorithm_binary.rs
index 76666796..2f130e26 100644
--- a/target-gen/src/algorithm_binary.rs
+++ b/target-gen/src/algorithm_binary.rs
@@ -2,7 +2,7 @@ use goblin::{
     elf::program_header::PT_LOAD,
     elf64::section_header::{SHT_NOBITS, SHT_PROGBITS},
 };
-use probe_rs::config::MemoryRange;
+use probe_rs_target::MemoryRange;
 
 use anyhow::{anyhow, Result};
 
diff --git a/target-gen/src/commands/elf.rs b/target-gen/src/commands/elf.rs
index 1c69b4f8..103bb148 100644
--- a/target-gen/src/commands/elf.rs
+++ b/target-gen/src/commands/elf.rs
@@ -1,8 +1,7 @@
 use anyhow::{bail, Context, Result};
-use probe_rs::CoreType;
 use probe_rs_target::{
-    ArmCoreAccessOptions, Chip, ChipFamily, Core, CoreAccessOptions, MemoryRegion, NvmRegion,
-    RamRegion, TargetDescriptionSource::BuiltIn,
+    ArmCoreAccessOptions, Chip, ChipFamily, Core, CoreAccessOptions, CoreType, MemoryRegion,
+    NvmRegion, RamRegion, TargetDescriptionSource,
 };
 use std::{
     collections::HashMap,
@@ -114,7 +113,7 @@ pub fn cmd_elf(
                 default_binary_format: None,
             }],
             flash_algorithms: vec![algorithm],
-            source: BuiltIn,
+            source: TargetDescriptionSource::BuiltIn,
         };
 
         let output_yaml = serialize_to_yaml_string(&chip_family)?;
diff --git a/target-gen/src/generate.rs b/target-gen/src/generate.rs
index 293531f3..b53af92e 100644
--- a/target-gen/src/generate.rs
+++ b/target-gen/src/generate.rs
@@ -2,16 +2,11 @@ use anyhow::{anyhow, bail, Context, Error, Result};
 use cmsis_pack::pdsc::{AccessPort, Algorithm, Core, Device, Package, Processor};
 use cmsis_pack::{pack_index::PdscRef, utils::FromElem};
 use futures::StreamExt;
-use probe_rs::{
-    config::{
-        Chip, ChipFamily, Core as ProbeCore, GenericRegion, MemoryRegion, NvmRegion, RamRegion,
-        RawFlashAlgorithm,
-    },
-    flashing::FlashAlgorithm,
-    Architecture, CoreType,
-};
+use probe_rs::flashing::FlashAlgorithm;
 use probe_rs_target::{
-    ArmCoreAccessOptions, CoreAccessOptions, RiscvCoreAccessOptions, XtensaCoreAccessOptions,
+    Architecture, ArmCoreAccessOptions, Chip, ChipFamily, Core as ProbeCore, CoreAccessOptions,
+    CoreType, GenericRegion, MemoryRegion, NvmRegion, RamRegion, RawFlashAlgorithm,
+    RiscvCoreAccessOptions, TargetDescriptionSource, XtensaCoreAccessOptions,
 };
 use std::collections::HashMap;
 use std::ffi::OsStr;
@@ -113,7 +108,7 @@ where
                 pack_file_release: pack_file_release.clone(),
                 variants: Vec::new(),
                 flash_algorithms: Vec::new(),
-                source: probe_rs::config::TargetDescriptionSource::BuiltIn,
+                source: TargetDescriptionSource::BuiltIn,
             });
             // This unwrap is always safe as we insert at least one item previously.
             families.last_mut().unwrap()
diff --git a/target-gen/src/main.rs b/target-gen/src/main.rs
index 4f6bab74..0cd1637e 100644
--- a/target-gen/src/main.rs
+++ b/target-gen/src/main.rs
@@ -7,7 +7,7 @@ pub mod parser;
 
 use anyhow::{ensure, Context, Result};
 use clap::Parser;
-use probe_rs::config::ChipFamily;
+use probe_rs_target::ChipFamily;
 use std::{
     env::current_dir,
     fs::create_dir,
diff --git a/target-gen/src/parser.rs b/target-gen/src/parser.rs
index c9389bba..0face14b 100644
--- a/target-gen/src/parser.rs
+++ b/target-gen/src/parser.rs
@@ -1,7 +1,6 @@
 use crate::flash_device::FlashDevice;
 use anyhow::{anyhow, Context, Result};
-use probe_rs::config::{FlashProperties, RawFlashAlgorithm, SectorDescription};
-use probe_rs_target::MemoryRange;
+use probe_rs_target::{FlashProperties, MemoryRange, RawFlashAlgorithm, SectorDescription};
 
 /// Extract a chunk of data from an ELF binary.
 ///


Test patch:
diff --git a/target-gen/src/commands/test.rs b/target-gen/src/commands/test.rs
index 9aa681c9..86212f5e 100644
--- a/target-gen/src/commands/test.rs
+++ b/target-gen/src/commands/test.rs
@@ -6,11 +6,11 @@ use std::time::Instant;
 
 use anyhow::{anyhow, Context, Result};
 use colored::Colorize;
-use probe_rs::flashing::erase_all;
-use probe_rs::MemoryInterface;
 use probe_rs::{
-    flashing::{erase_sectors, DownloadOptions, FlashLoader, FlashProgress},
-    Permissions, Session,
+    flashing::{
+        erase_all, erase_sectors, DownloadOptions, FlashLoader, FlashProgress, ProgressEvent,
+    },
+    MemoryInterface, Permissions, Session,
 };
 use probe_rs_target::{ChipFamily, RawFlashAlgorithm};
 use xshell::{cmd, Shell};
@@ -73,39 +73,36 @@ pub fn cmd_test(
 
             // Register callback to update the progress.
             let t = Rc::new(RefCell::new(Instant::now()));
-            let progress = FlashProgress::new(move |event| {
-                use probe_rs::flashing::ProgressEvent;
-                match event {
-                    ProgressEvent::StartedProgramming { .. } => {
-                        let mut t = t.borrow_mut();
-                        *t = Instant::now();
-                    }
-                    ProgressEvent::StartedErasing => {
-                        let mut t = t.borrow_mut();
-                        *t = Instant::now();
-                    }
-                    ProgressEvent::FailedErasing => {
-                        println!("Failed erasing in {:?}", t.borrow().elapsed());
-                    }
-                    ProgressEvent::FinishedErasing => {
-                        println!("Finished erasing in {:?}", t.borrow().elapsed());
-                    }
-                    ProgressEvent::FailedProgramming => {
-                        println!("Failed programming in {:?}", t.borrow().elapsed());
-                    }
-                    ProgressEvent::FinishedProgramming => {
-                        println!("Finished programming in {:?}", t.borrow().elapsed());
-                    }
-                    ProgressEvent::DiagnosticMessage { message } => {
-                        let prefix = "Message".yellow();
-                        if message.ends_with('\n') {
-                            print!("{prefix}: {message}");
-                        } else {
-                            println!("{prefix}: {message}");
-                        }
+            let progress = FlashProgress::new(move |event| match event {
+                ProgressEvent::StartedProgramming { .. } => {
+                    let mut t = t.borrow_mut();
+                    *t = Instant::now();
+                }
+                ProgressEvent::StartedErasing => {
+                    let mut t = t.borrow_mut();
+                    *t = Instant::now();
+                }
+                ProgressEvent::FailedErasing => {
+                    println!("Failed erasing in {:?}", t.borrow().elapsed());
+                }
+                ProgressEvent::FinishedErasing => {
+                    println!("Finished erasing in {:?}", t.borrow().elapsed());
+                }
+                ProgressEvent::FailedProgramming => {
+                    println!("Failed programming in {:?}", t.borrow().elapsed());
+                }
+                ProgressEvent::FinishedProgramming => {
+                    println!("Finished programming in {:?}", t.borrow().elapsed());
+                }
+                ProgressEvent::DiagnosticMessage { message } => {
+                    let prefix = "Message".yellow();
+                    if message.ends_with('\n') {
+                        print!("{prefix}: {message}");
+                    } else {
+                        println!("{prefix}: {message}");
                     }
-                    _ => (),
                 }
+                _ => (),
             });
 
             let flash_algorithm = if let Some(test_start_sector_address) = test_start_sector_address