Skip to content

Commit b148386

Browse files
add --monitor option to write-bin (#783)
* changelog entry * rebase * fix * update hil test * increase timeout increase timeout even more * Fix CHANGELOG.md Co-authored-by: Sergio Gasquez Arcos <[email protected]> * play around timer.... increase timer --------- Co-authored-by: Sergio Gasquez Arcos <[email protected]>
1 parent f86b149 commit b148386

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

.github/workflows/hil.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ jobs:
113113

114114
- name: save-image/write-bin test
115115
run: |
116-
timeout 60 bash espflash/tests/scripts/save-image_write-bin.sh ${{ matrix.board.mcu }}
117-
timeout 10 bash espflash/tests/scripts/monitor.sh
116+
timeout 90 bash espflash/tests/scripts/save-image_write-bin.sh ${{ matrix.board.mcu }}
118117
119118
- name: erase-region test
120119
run: timeout 10 bash espflash/tests/scripts/erase-region.sh

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Add an environment variable to set monitoring baudrate (`MONITOR_BAUD`) (#737)
1515
- Add list-ports command to list available serial ports. (#761)
1616
- [cargo-espflash]: Add `write-bin` subcommand (#789)
17+
- Add `--monitor` option to `write-bin`. (#783)
1718

1819
### Changed
1920

espflash/src/cli/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ pub struct WriteBinArgs {
326326
/// Connection configuration
327327
#[clap(flatten)]
328328
connect_args: ConnectArgs,
329+
/// Open a serial monitor after writing
330+
#[arg(short = 'M', long)]
331+
pub monitor: bool,
332+
/// Serial monitor configuration
333+
#[clap(flatten)]
334+
pub monitor_args: MonitorConfigArgs,
329335
}
330336

331337
/// Parses an integer, in base-10 or hexadecimal format, into a [u32]
@@ -996,6 +1002,10 @@ pub fn write_bin(args: WriteBinArgs, config: &Config) -> Result<()> {
9961002
let mut flasher = connect(&args.connect_args, config, false, false)?;
9971003
print_board_info(&mut flasher)?;
9981004

1005+
let chip = flasher.chip();
1006+
let target = chip.into_target();
1007+
let target_xtal_freq = target.crystal_freq(flasher.connection())?;
1008+
9991009
let mut f = File::open(&args.file).into_diagnostic()?;
10001010

10011011
// If the file size is not divisible by 4, we need to pad `FF` bytes to the end
@@ -1014,6 +1024,21 @@ pub fn write_bin(args: WriteBinArgs, config: &Config) -> Result<()> {
10141024
Some(&mut EspflashProgress::default()),
10151025
)?;
10161026

1027+
if args.monitor {
1028+
let pid = flasher.usb_pid();
1029+
let mut monitor_args = args.monitor_args;
1030+
1031+
if chip == Chip::Esp32c2
1032+
&& target_xtal_freq == XtalFrequency::_26Mhz
1033+
&& monitor_args.monitor_baud == 115_200
1034+
{
1035+
// 115_200 * 26 MHz / 40 MHz = 74_880
1036+
monitor_args.monitor_baud = 74_880;
1037+
}
1038+
1039+
monitor(flasher.into_serial(), None, pid, monitor_args)?;
1040+
}
1041+
10171042
Ok(())
10181043
}
10191044

espflash/tests/scripts/save-image_write-bin.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ if [[ ! $result =~ "Image successfully saved!" ]]; then
1212
exit 1
1313
fi
1414
echo "Writing binary"
15-
result=$(espflash write-bin 0x0 app.bin 2>&1)
15+
result=$(timeout 45 espflash write-bin --monitor 0x0 app.bin --non-interactive 2>&1)
1616
echo "$result"
1717
if [[ ! $result =~ "Binary successfully written to flash!" ]]; then
1818
exit 1
1919
fi
20+
21+
if ! echo "$result" | grep -q "Hello world!"; then
22+
exit 1
23+
fi

0 commit comments

Comments
 (0)