Skip to content

Commit

Permalink
ravedude: Add option to print avrdude command
Browse files Browse the repository at this point in the history
In case avrdude fails, it is nice to be able to see what command was
attempted.  Give the option to display it using --debug-avrdude.
  • Loading branch information
Rahix committed Mar 5, 2024
1 parent 08e25de commit f008a5a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions ravedude/src/avrdude/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl Avrdude {
options: &AvrdudeOptions,
port: Option<impl AsRef<path::Path>>,
bin: &path::Path,
debug: bool,
) -> anyhow::Result<Self> {
let avrdude_version = Self::get_avrdude_version()?;

Expand Down Expand Up @@ -102,6 +103,19 @@ impl Avrdude {

command = command.arg("-D").arg("-U").arg(flash_instruction);

if debug {
crate::task_message!(
"Dbg.Command",
"{} {}",
command.get_program().to_string_lossy(),
command
.get_args()
.map(|s| s.to_string_lossy())
.collect::<Vec<_>>()
.join(" ")
);
}

let process = command.spawn().context("failed starting avrdude")?;

Ok(Self { config, process })
Expand Down
11 changes: 10 additions & 1 deletion ravedude/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ struct Args {
#[structopt(short = "d", long = "reset-delay")]
reset_delay: Option<u64>,

/// Print the avrdude command that is executed for flashing the binary.
#[structopt(long = "debug-avrdude")]
debug_avrdude: bool,

/// Which board to interact with.
///
/// Must be one of the known board identifiers:
Expand Down Expand Up @@ -137,7 +141,12 @@ fn ravedude() -> anyhow::Result<()> {
task_message!("Programming", "{}", bin.display(),);
}

let mut avrdude = avrdude::Avrdude::run(&board.avrdude_options(), port.as_ref(), bin)?;
let mut avrdude = avrdude::Avrdude::run(
&board.avrdude_options(),
port.as_ref(),
bin,
args.debug_avrdude,
)?;
avrdude.wait()?;

task_message!("Programmed", "{}", bin.display());
Expand Down

0 comments on commit f008a5a

Please sign in to comment.