Skip to content

Commit

Permalink
Merge pull request #22 from forged-org/feature/probe-rs-update
Browse files Browse the repository at this point in the history
Updating probe-rs
  • Loading branch information
ryan-summers authored Feb 8, 2024
2 parents 4f57b61 + 1200009 commit 1ba5724
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 85 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/gen-release.yml

This file was deleted.

2 changes: 1 addition & 1 deletion forged-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## 0.4.0 - 2024-02-08

### Added
* `forged-cli download` can now be used to program a device without an active run.
Expand Down
8 changes: 4 additions & 4 deletions forged-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "forged-cli"
version = "0.1.0"
version = "0.4.0"
edition = "2021"
license = "MIT"
authors = [
Expand All @@ -25,13 +25,13 @@ eula = false
[dependencies]
cynic = { version = "2", features = ["http-reqwest"] }
tokio = { version = "1.15", features = ["macros", "rt-multi-thread"] }
forged = { path = "../forged-rs" }
forged = { version = "0.4", path = "../forged-rs" }
serde_json = "1.0.75"
clap = { version = "3.0.13", features = ["derive"] }
probe-rs = "0.13.0"
indicatif = "0.17"
probe-rs = "0.22.0"
log = "0.4.14"
anyhow = "1.0.53"
probe-rs-cli-util = "0.13.0"
thiserror = "1.0.30"
dotenv = "0.15"
uuid = { version = "1", features = ["serde"] }
Expand Down
117 changes: 75 additions & 42 deletions forged-cli/src/functions/download.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
use std::{io::Cursor, path::Path};
use indicatif::ProgressBar;
use std::io::Cursor;

use anyhow::anyhow;
use cynic::QueryBuilder;
use probe_rs::{
flashing::{BinOptions, FlashLoader},
Probe,
};
use probe_rs::flashing::{BinOptions, FlashLoader};

use crate::Error;
use probe_rs_cli_util::{
common_options::{CargoOptions, FlashOptions},
flash,
};

use crate::{
queries::{Binary, Chip, Chips},
Result,
Expand Down Expand Up @@ -118,10 +111,12 @@ async fn run_flash_download(
chip: &Chip,
binary: &Binary,
) -> Result<()> {
let probe = Probe::list_all()
let lister = probe_rs::Lister::new();
let probe = lister
.list_all()
.get(0)
.ok_or_else(|| anyhow!("No probe found"))?
.open()
.open(&lister)
.map_err(probe_rs::Error::Probe)?;
{
let protocol_speed = probe.speed_khz();
Expand All @@ -139,18 +134,18 @@ async fn run_flash_download(

let n_parts = binary.parts.len();
for (index, part) in binary.parts.clone().into_iter().enumerate() {
let binary = client
.binary_part(chip.id, binary.id, part.id, None)
.await?;

println!(
"📦 Flashing part {}/{n_parts}{}",
"📦 Downloading part {}/{n_parts}{}",
index + 1,
part.analysis
.map(|analysis| format!(" ({} bytes)", analysis.nvm_size))
.unwrap_or_default()
);

let binary = client
.binary_part(chip.id, binary.id, part.id, None)
.await?;

match part.kind {
crate::queries::BinaryKind::Elf => loader
.load_elf_data(&mut Cursor::new(binary))
Expand All @@ -170,30 +165,68 @@ async fn run_flash_download(
}
}

let flash_options = FlashOptions {
disable_double_buffering: false,
version: false,
list_chips: false,
list_probes: false,
disable_progressbars: false,
reset_halt: false,
log: None,
restore_unwritten: true,
flash_layout_output_path: None,
elf: None,
work_dir: None,
cargo_options: CargoOptions::default(),
probe_options: probe_rs_cli_util::common_options::ProbeOptions {
allow_erase_all: true,
chip: None,
chip_description_path: None,
protocol: None,
probe_selector: None,
connect_under_reset: false,
speed: None,
dry_run: false,
},
};
flash::run_flash_download(&mut session, Path::new(""), &flash_options, loader, false)?;
let style = indicatif::ProgressStyle::default_bar()
.tick_chars("⠁⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈⠈✔")
.progress_chars("--")
.template("{msg:.green.bold} {spinner} [{elapsed_precise}] [{wide_bar}] {bytes:>8}/{total_bytes:>8} @ {bytes_per_sec:>10} (eta {eta:3})").expect("Error in progress bar creation. This is a bug, please report it.");

let multi_progress = indicatif::MultiProgress::new();
let erase_bar = multi_progress.add(
ProgressBar::new(0)
.with_style(style.clone())
.with_message(" Erasing"),
);
let program_bar = multi_progress.add(
ProgressBar::new(0)
.with_style(style.clone())
.with_message("Programming"),
);

let progress = probe_rs::flashing::FlashProgress::new(move |event| {
use probe_rs::flashing::ProgressEvent;
match event {
ProgressEvent::Initialized { flash_layout } => {
erase_bar.set_length(flash_layout.sectors().iter().map(|s| s.size() as u64).sum());
program_bar.set_length(flash_layout.pages().iter().map(|s| s.size() as u64).sum());
}
ProgressEvent::StartedErasing => {
let style = program_bar.style().progress_chars("##-");
erase_bar.set_style(style);
erase_bar.reset_elapsed();
}
ProgressEvent::StartedProgramming { length } => {
program_bar.set_length(length);
let style = program_bar.style().progress_chars("##-");
program_bar.set_style(style);
program_bar.reset_elapsed();
}
ProgressEvent::PageProgrammed { size, .. } => program_bar.inc(size as u64),
ProgressEvent::SectorErased { size, .. } => erase_bar.inc(size),
ProgressEvent::FinishedErasing => {
erase_bar.finish();
}
ProgressEvent::FailedProgramming => {
program_bar.abandon();
}
ProgressEvent::FailedErasing => {
erase_bar.abandon();
}
ProgressEvent::FinishedProgramming => {
program_bar.finish();
}
_ => {}
}
});

let mut options = probe_rs::flashing::DownloadOptions::default();
options.disable_double_buffering = false;
options.verify = true;
options.keep_unwritten_bytes = true;
options.dry_run = false;
options.progress = Some(progress);
options.skip_erase = false;

loader.commit(&mut session, options)?;

Ok(())
}
2 changes: 1 addition & 1 deletion forged-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub type Result<T> = std::result::Result<T, Error>;
pub enum Error {
Client(#[from] forged::Error),
Probe(#[from] probe_rs::Error),
FlashOperation(#[from] probe_rs_cli_util::common_options::OperationError),
FlashOperation(#[from] probe_rs::flashing::FlashError),
Other(#[from] anyhow::Error),
Semver(#[from] semver::Error),
}
Expand Down
2 changes: 2 additions & 0 deletions forged-rs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## 0.4.0 - 2024-02-08

### Added
* Added a new `Client::binary_part()` API to download binary parts to the local machine and get
their contents
Expand Down
2 changes: 1 addition & 1 deletion forged-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "forged"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
license = "MIT"
authors = [
Expand Down

0 comments on commit 1ba5724

Please sign in to comment.