Skip to content

Commit

Permalink
Add hold-in-reset and reset commands to cargo-espflash as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnross committed May 31, 2024
1 parent 601182a commit baca115
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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 @@ -101,6 +103,8 @@ enum Commands {
PartitionTable(PartitionTableArgs),
/// Read SPI flash content
ReadFlash(ReadFlashArgs),
/// 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 @@ -216,9 +220,11 @@ 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::ReadFlash(args) => read_flash(args, &config),
Commands::Reset(args) => reset(args, &config),
Commands::SaveImage(args) => save_image(args, &config),
Commands::ChecksumMd5(args) => checksum_md5(&args, &config),
}
Expand Down Expand Up @@ -257,6 +263,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, true, true)?;
info!("Resetting target device");
flash.connection().reset()?;

Ok(())
}

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

Ok(())
}

fn flash(args: FlashArgs, config: &Config) -> Result<()> {
let metadata = PackageMetadata::load(&args.build_args.package)?;
let cargo_config = CargoConfig::load(&metadata.workspace_root, &metadata.package_root);
Expand Down

0 comments on commit baca115

Please sign in to comment.