Skip to content

Commit 5c898ac

Browse files
author
Joseph Ross
authored
Add commands reset and hold-in-reset (#644)
* Add commands `reset` and `hold-in-reset` * Fix connect call to adopt new args. * Add changelog entry * Add `hold-in-reset` and `reset` commands to `cargo-espflash` as well. * Update usage blocks in READMEs.
1 parent 086753a commit 5c898ac

File tree

6 files changed

+55
-1
lines changed

6 files changed

+55
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
- Add `hold-in-reset` and `reset` subcommands
11+
812
## [3.1.0] - 2024-05-24
913

1014
### Added

cargo-espflash/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ Commands:
7373
erase-parts Erase specified partitions
7474
erase-region Erase specified region
7575
flash Flash an application in ELF format to a target device
76+
hold-in-reset Hold the target device in reset
7677
monitor Open the serial monitor without flashing the connected target device
7778
partition-table Convert partition tables between CSV and binary format
7879
read-flash Read SPI flash content
80+
reset Reset the target device
7981
save-image Generate a binary application image and save it to a local disk
8082
checksum-md5 Calculate the MD5 checksum of the given region
8183
help Print this message or the help of the given subcommand(s)

cargo-espflash/src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ enum Commands {
8686
///
8787
/// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/app_image_format.html
8888
Flash(FlashArgs),
89+
/// Hold the target device in reset
90+
HoldInReset(ConnectArgs),
8991
/// Open the serial monitor without flashing the connected target device
9092
Monitor(MonitorArgs),
9193
/// Convert partition tables between CSV and binary format
@@ -101,6 +103,8 @@ enum Commands {
101103
PartitionTable(PartitionTableArgs),
102104
/// Read SPI flash content
103105
ReadFlash(ReadFlashArgs),
106+
/// Reset the target device
107+
Reset(ConnectArgs),
104108
/// Generate a binary application image and save it to a local disk
105109
///
106110
/// If the '--merge' option is used, then the bootloader, partition table,
@@ -216,9 +220,11 @@ fn main() -> Result<()> {
216220
Commands::EraseParts(args) => erase_parts(args, &config),
217221
Commands::EraseRegion(args) => erase_region(args, &config),
218222
Commands::Flash(args) => flash(args, &config),
223+
Commands::HoldInReset(args) => hold_in_reset(args, &config),
219224
Commands::Monitor(args) => serial_monitor(args, &config),
220225
Commands::PartitionTable(args) => partition_table(args),
221226
Commands::ReadFlash(args) => read_flash(args, &config),
227+
Commands::Reset(args) => reset(args, &config),
222228
Commands::SaveImage(args) => save_image(args, &config),
223229
Commands::ChecksumMd5(args) => checksum_md5(&args, &config),
224230
}
@@ -257,6 +263,23 @@ pub fn erase_parts(args: ErasePartsArgs, config: &Config) -> Result<()> {
257263
Ok(())
258264
}
259265

266+
fn reset(args: ConnectArgs, config: &Config) -> Result<()> {
267+
let mut args = args.clone();
268+
args.no_stub = true;
269+
let mut flash = connect(&args, config, true, true)?;
270+
info!("Resetting target device");
271+
flash.connection().reset()?;
272+
273+
Ok(())
274+
}
275+
276+
fn hold_in_reset(args: ConnectArgs, config: &Config) -> Result<()> {
277+
connect(&args, config, true, true)?;
278+
info!("Holding target device in reset");
279+
280+
Ok(())
281+
}
282+
260283
fn flash(args: FlashArgs, config: &Config) -> Result<()> {
261284
let metadata = PackageMetadata::load(&args.build_args.package)?;
262285
let cargo_config = CargoConfig::load(&metadata.workspace_root, &metadata.package_root);

espflash/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ Commands:
6868
erase-parts Erase specified partitions
6969
erase-region Erase specified region
7070
flash Flash an application in ELF format to a connected target device
71+
hold-in-reset Hold the target device in reset
7172
monitor Open the serial monitor without flashing the connected target device
7273
partition-table Convert partition tables between CSV and binary format
7374
read-flash Read SPI flash content
75+
reset Reset the target device
7476
save-image Generate a binary application image and save it to a local disk
7577
write-bin Write a binary file to a specific address in a target device's flash
7678
checksum-md5 Calculate the MD5 checksum of the given region

espflash/src/bin/espflash.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ enum Commands {
6262
///
6363
/// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/app_image_format.html
6464
Flash(FlashArgs),
65+
/// Hold the target device in reset
66+
HoldInReset(ConnectArgs),
6567
/// Open the serial monitor without flashing the connected target device
6668
Monitor(MonitorArgs),
6769
/// Convert partition tables between CSV and binary format
@@ -77,6 +79,8 @@ enum Commands {
7779
PartitionTable(PartitionTableArgs),
7880
/// Read SPI flash content
7981
ReadFlash(ReadFlashArgs),
82+
/// Reset the target device
83+
Reset(ConnectArgs),
8084
/// Generate a binary application image and save it to a local disk
8185
///
8286
/// If the '--merge' option is used, then the bootloader, partition table,
@@ -174,9 +178,11 @@ fn main() -> Result<()> {
174178
Commands::EraseParts(args) => erase_parts(args, &config),
175179
Commands::EraseRegion(args) => erase_region(args, &config),
176180
Commands::Flash(args) => flash(args, &config),
181+
Commands::HoldInReset(args) => hold_in_reset(args, &config),
177182
Commands::Monitor(args) => serial_monitor(args, &config),
178183
Commands::PartitionTable(args) => partition_table(args),
179184
Commands::ReadFlash(args) => read_flash(args, &config),
185+
Commands::Reset(args) => reset(args, &config),
180186
Commands::SaveImage(args) => save_image(args, &config),
181187
Commands::WriteBin(args) => write_bin(args, &config),
182188
Commands::ChecksumMd5(args) => checksum_md5(&args, &config),
@@ -206,6 +212,23 @@ pub fn erase_parts(args: ErasePartsArgs, config: &Config) -> Result<()> {
206212
Ok(())
207213
}
208214

215+
fn reset(args: ConnectArgs, config: &Config) -> Result<()> {
216+
let mut args = args.clone();
217+
args.no_stub = true;
218+
let mut flash = connect(&args, config, true, true)?;
219+
info!("Resetting target device");
220+
flash.connection().reset()?;
221+
222+
Ok(())
223+
}
224+
225+
fn hold_in_reset(args: ConnectArgs, config: &Config) -> Result<()> {
226+
connect(&args, config, true, true)?;
227+
info!("Holding target device in reset");
228+
229+
Ok(())
230+
}
231+
209232
fn flash(args: FlashArgs, config: &Config) -> Result<()> {
210233
let mut flasher = connect(
211234
&args.connect_args,

espflash/src/cli/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub mod monitor;
4949
mod serial;
5050

5151
/// Establish a connection with a target device
52-
#[derive(Debug, Args)]
52+
#[derive(Debug, Args, Clone)]
5353
#[non_exhaustive]
5454
pub struct ConnectArgs {
5555
/// Reset operation to perform after connecting to the target

0 commit comments

Comments
 (0)