Skip to content

Commit

Permalink
Add commands reset and hold-in-reset (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnross authored and mykmelez committed May 20, 2024
1 parent 652740e commit 118e132
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions espflash/src/bin/espflash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ enum Commands {
///
/// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/app_image_format.html
Flash(FlashArgs),
/// Hold the target device in reset
HoldInReset(ConnectArgs),
/// Open the serial monitor without flashing the connected target device
Monitor(MonitorArgs),
/// Convert partition tables between CSV and binary format
Expand All @@ -74,6 +76,8 @@ enum Commands {
/// '--to-binary' options, plus the ability to print a partition table
/// in tabular format.
PartitionTable(PartitionTableArgs),
/// Reset the target device
Reset(ConnectArgs),
/// Generate a binary application image and save it to a local disk
///
/// If the '--merge' option is used, then the bootloader, partition table,
Expand Down Expand Up @@ -170,8 +174,10 @@ fn main() -> Result<()> {
Commands::EraseParts(args) => erase_parts(args, &config),
Commands::EraseRegion(args) => erase_region(args, &config),
Commands::Flash(args) => flash(args, &config),
Commands::HoldInReset(args) => hold_in_reset(args, &config),
Commands::Monitor(args) => serial_monitor(args, &config),
Commands::PartitionTable(args) => partition_table(args),
Commands::Reset(args) => reset(args, &config),
Commands::SaveImage(args) => save_image(args),
Commands::WriteBin(args) => write_bin(args, &config),
}
Expand All @@ -195,6 +201,23 @@ pub fn erase_parts(args: ErasePartsArgs, config: &Config) -> Result<()> {
Ok(())
}

fn reset(args: ConnectArgs, config: &Config) -> Result<()> {
let mut args = args.clone();
args.no_stub = true;
let mut flash = connect(&args, config)?;
info!("Resetting target device");
flash.connection().reset()?;

Ok(())
}

fn hold_in_reset(args: ConnectArgs, config: &Config) -> Result<()> {
connect(&args, config)?;
info!("Holding target device in reset");

Ok(())
}

fn flash(args: FlashArgs, config: &Config) -> Result<()> {
let mut flasher = connect(&args.connect_args, config)?;

Expand Down
2 changes: 1 addition & 1 deletion espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub mod monitor;
mod serial;

/// Establish a connection with a target device
#[derive(Debug, Args)]
#[derive(Debug, Args, Clone)]
pub struct ConnectArgs {
/// Baud rate at which to communicate with target device
#[arg(short = 'b', long, env = "ESPFLASH_BAUD")]
Expand Down

0 comments on commit 118e132

Please sign in to comment.