mirror of
https://github.com/gnxlxnxx/cargo-dfu.git
synced 2026-07-27 15:23:02 +02:00
Compare commits
19
Commits
v0.0.4
...
1bded1ebca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bded1ebca
|
||
|
|
8a56445e6b
|
||
|
|
aed0c2fb0b | ||
|
|
cf19afbb7f | ||
|
|
8e6556699d | ||
|
|
d7daa0fd3d
|
||
|
|
31e5205683
|
||
|
|
2523cc8503
|
||
|
|
0108a54d8f | ||
|
|
59c74f921e
|
||
|
|
8800b22edf
|
||
|
|
bca314c152 | ||
|
|
14ddda22d9
|
||
|
|
3f2a0b3a7a | ||
|
|
be0b991e66
|
||
|
|
fa2b286f6b
|
||
|
|
a6e389c29d
|
||
|
|
6b79d67ff8 | ||
|
|
504ae4e4f0
|
Generated
+114
-121
@@ -26,15 +26,6 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
@@ -73,19 +64,25 @@ version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
|
||||
|
||||
[[package]]
|
||||
name = "cargo-dfu"
|
||||
version = "0.0.4"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"cargo-project",
|
||||
"clap",
|
||||
"colored",
|
||||
"dfu",
|
||||
"dfu-libusb",
|
||||
"goblin",
|
||||
"log",
|
||||
"maplit",
|
||||
"pretty_env_logger",
|
||||
"rusb",
|
||||
"structopt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -130,17 +127,32 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "2.33.3"
|
||||
version = "3.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
|
||||
checksum = "7a30c3bf9ff12dfe5dae53f0a96e0febcd18420d1c0e7fad77796d9d5c4b5375"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"atty",
|
||||
"bitflags",
|
||||
"clap_derive",
|
||||
"indexmap",
|
||||
"lazy_static",
|
||||
"os_str_bytes",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
"textwrap",
|
||||
"unicode-width",
|
||||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "3.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "517358c28fcef6607bf6f76108e02afad7e82297d132a6b846dcc1fc3efcd153"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -155,15 +167,39 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dfu"
|
||||
name = "dfu-core"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb1d1eb7e47b3cba338775698712a8cb285aa15d45e58329c59411a55fbc1b98"
|
||||
checksum = "6c3fb34e94bedc8bbd76dfc9f6774896fadbbedac6108fa8a3c46a0125bde188"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"displaydoc",
|
||||
"log",
|
||||
"nix",
|
||||
"serde",
|
||||
"usbapi",
|
||||
"pretty-hex",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dfu-libusb"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00b4d756e08681e12abb006bbcf557b45c89c189c32e08193cb773b9177f837e"
|
||||
dependencies = [
|
||||
"dfu-core",
|
||||
"libusb1-sys",
|
||||
"rusb",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "displaydoc"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3bf95dc3f046b9da4f2d51833c0d3547d8564ef6910f5c1ed130306a75b92886"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -225,13 +261,16 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.3"
|
||||
name = "hashbrown"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
@@ -251,6 +290,16 @@ dependencies = [
|
||||
"quick-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
@@ -296,15 +345,6 @@ version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.4.4"
|
||||
@@ -315,19 +355,6 @@ dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5e06129fb611568ef4e868c14b326274959aa70ff7776e9d55323531c374945"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"memoffset",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.44"
|
||||
@@ -356,6 +383,15 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.22"
|
||||
@@ -368,6 +404,12 @@ version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
|
||||
|
||||
[[package]]
|
||||
name = "pretty-hex"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c6fa0831dd7cc608c38a5e323422a0077678fa5744aa2be4ad91c4ece8eec8d5"
|
||||
|
||||
[[package]]
|
||||
name = "pretty_env_logger"
|
||||
version = "0.3.1"
|
||||
@@ -494,9 +536,6 @@ name = "serde"
|
||||
version = "1.0.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
@@ -511,33 +550,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.8.0"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
|
||||
[[package]]
|
||||
name = "structopt"
|
||||
version = "0.3.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"lazy_static",
|
||||
"structopt-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "structopt-derive"
|
||||
version = "0.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
@@ -562,15 +577,6 @@ dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sysfs-serde"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95eb4a78bc7d9d0bbc4a4cd2f5d2756e67e27a4d11bb52df6406508dae15066a"
|
||||
dependencies = [
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.2"
|
||||
@@ -582,11 +588,28 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.11.0"
|
||||
version = "0.14.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -609,48 +632,18 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
|
||||
[[package]]
|
||||
name = "usbapi"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc33ce833e969eaf16937f8ec81bd10e52428159e4d45dd3d70b0c0f6558e416"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"nix",
|
||||
"sysfs-serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.3"
|
||||
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "cargo-dfu"
|
||||
authors = ["Roman Kretschmer <roman@kretschmer.email>"]
|
||||
version = "0.0.4"
|
||||
version = "0.1.2"
|
||||
edition = "2021"
|
||||
description = "cargo extension for flashing embedded rust programs via dfu"
|
||||
license = "MIT"
|
||||
homepage = "https://github.com/gnxlxnxx/cargo-dfu"
|
||||
repository = "https://github.com/gnxlxnxx/cargo-dfu.git"
|
||||
homepage = "https://github.com/dfu-rs/cargo-dfu"
|
||||
repository = "https://github.com/dfu-rs/cargo-dfu.git"
|
||||
categories = ["embedded", "hardware-support"]
|
||||
keywords = ["dfu", "flashing", "embedded"]
|
||||
readme = "Readme.md"
|
||||
@@ -18,8 +18,8 @@ goblin = "0.2.3"
|
||||
colored = "2.0.0"
|
||||
rusb = "0.9.0"
|
||||
pretty_env_logger = "0.3.0"
|
||||
cargo-project = "0.2.4"
|
||||
structopt = "0.3.2"
|
||||
cargo-project = "0.2.7"
|
||||
clap = {version = "3.0.10", features=["derive"]}
|
||||
maplit = "1.0.2"
|
||||
log = "0.4.6"
|
||||
dfu = "0.4"
|
||||
dfu-libusb = "0.3.0"
|
||||
|
||||
@@ -30,7 +30,7 @@ cargo dfu
|
||||
#### specifying the chip
|
||||
|
||||
```bash
|
||||
cargo dfu --chip stm32f4
|
||||
cargo dfu --chip stm32
|
||||
```
|
||||
|
||||
#### specifying the vid and pid
|
||||
@@ -49,5 +49,4 @@ sudo cp udev.rules /etc/udev/rules.d/cargo-dfu.rules
|
||||
```
|
||||
|
||||
## Roadmap
|
||||
- [ ] make this crate multi-platform (PR to either the dfu crate to use rusb or the usbapi to add platform support)
|
||||
- [ ] check if multiple chips are connected
|
||||
|
||||
+23
-22
@@ -4,10 +4,11 @@ use crate::utils::{elf_to_bin, flash_bin, vendor_map};
|
||||
use colored::*;
|
||||
use rusb::{open_device_with_vid_pid, GlobalContext};
|
||||
|
||||
use clap::Parser;
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::time::Instant;
|
||||
use structopt::StructOpt;
|
||||
// use structopt::StructOpt;
|
||||
|
||||
fn main() {
|
||||
// Initialize the logging backend.
|
||||
@@ -15,7 +16,7 @@ fn main() {
|
||||
|
||||
// Get commandline options.
|
||||
// Skip the first arg which is the calling application name.
|
||||
let opt = Opt::from_iter(std::env::args().skip(1));
|
||||
let opt = Opt::parse_from(std::env::args().skip(1));
|
||||
|
||||
if opt.list_chips {
|
||||
for vendor in vendor_map() {
|
||||
@@ -48,7 +49,9 @@ fn main() {
|
||||
.path(
|
||||
artifact,
|
||||
profile,
|
||||
opt.target.as_deref(),
|
||||
opt.target
|
||||
.as_deref()
|
||||
.map(|target| target.trim_end_matches(".json")),
|
||||
"x86_64-unknown-linux-gnu",
|
||||
)
|
||||
.expect("Couldn't find the build result");
|
||||
@@ -137,14 +140,12 @@ fn main() {
|
||||
|
||||
println!(" {} {:?}", "Flashing".green().bold(), path);
|
||||
|
||||
let (binary, address) = elf_to_bin(path).unwrap();
|
||||
let (binary, _) = elf_to_bin(path).unwrap();
|
||||
|
||||
// Start timer.
|
||||
let instant = Instant::now();
|
||||
|
||||
// let bininfo = hf2::bin_info(&d).expect("bin_info failed");
|
||||
// log::debug!("{:?}", bininfo);
|
||||
flash_bin(&binary, address, &d.device()).unwrap();
|
||||
flash_bin(&binary, &d.device()).unwrap();
|
||||
|
||||
// Stop timer.
|
||||
let elapsed = instant.elapsed();
|
||||
@@ -176,36 +177,36 @@ fn parse_hex_16(input: &str) -> Result<u16, std::num::ParseIntError> {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(author, version, about, long_about = None)]
|
||||
struct Opt {
|
||||
// `cargo build` arguments
|
||||
#[structopt(name = "binary", long = "bin")]
|
||||
#[clap(name = "binary", long = "bin")]
|
||||
bin: Option<String>,
|
||||
#[structopt(name = "example", long = "example")]
|
||||
#[clap(name = "example", long = "example")]
|
||||
example: Option<String>,
|
||||
#[structopt(name = "package", short = "p", long = "package")]
|
||||
#[clap(name = "package", short = 'p', long = "package")]
|
||||
package: Option<String>,
|
||||
#[structopt(name = "release", long = "release")]
|
||||
#[clap(name = "release", long = "release")]
|
||||
release: bool,
|
||||
#[structopt(name = "target", long = "target")]
|
||||
#[clap(name = "target", long = "target")]
|
||||
target: Option<String>,
|
||||
#[structopt(name = "PATH", long = "manifest-path", parse(from_os_str))]
|
||||
#[clap(name = "PATH", long = "manifest-path", parse(from_os_str))]
|
||||
manifest_path: Option<PathBuf>,
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
no_default_features: bool,
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
all_features: bool,
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
features: Vec<String>,
|
||||
|
||||
#[structopt(name = "pid", long = "pid", parse(try_from_str = parse_hex_16))]
|
||||
#[clap(name = "pid", long = "pid", parse(try_from_str = parse_hex_16))]
|
||||
pid: Option<u16>,
|
||||
#[structopt(name = "vid", long = "vid", parse(try_from_str = parse_hex_16))]
|
||||
#[clap(name = "vid", long = "vid", parse(try_from_str = parse_hex_16))]
|
||||
vid: Option<u16>,
|
||||
|
||||
#[structopt(name = "chip", long = "chip")]
|
||||
#[clap(name = "chip", long = "chip")]
|
||||
chip: Option<String>,
|
||||
#[structopt(name = "list-chips", long = "list-chips")]
|
||||
#[clap(name = "list-chips", long = "list-chips")]
|
||||
list_chips: bool,
|
||||
}
|
||||
|
||||
+12
-26
@@ -7,7 +7,7 @@ use std::{fs::File, io::Read};
|
||||
#[derive(Debug)]
|
||||
pub enum UtilError {
|
||||
Elf(goblin::error::Error),
|
||||
Dfu(dfu::error::Error),
|
||||
Dfu(dfu_libusb::Error),
|
||||
File(std::io::Error),
|
||||
}
|
||||
|
||||
@@ -54,37 +54,23 @@ pub fn elf_to_bin(path: PathBuf) -> Result<(Vec<u8>, u32), UtilError> {
|
||||
Ok((data, start_address as u32))
|
||||
}
|
||||
|
||||
pub fn flash_bin(
|
||||
binary: &[u8],
|
||||
address: u32,
|
||||
d: &rusb::Device<GlobalContext>,
|
||||
) -> Result<(), UtilError> {
|
||||
let mut dfu = dfu::Dfu::from_bus_device(d.bus_number(), d.address(), 0_u32, 0_u32)
|
||||
.map_err(|e| UtilError::Dfu(e))?;
|
||||
if binary.len() < 2048 {
|
||||
dfu.write_flash_from_slice(address, binary)
|
||||
.map_err(|e| UtilError::Dfu(e))?;
|
||||
} else {
|
||||
// hacky bug workaround
|
||||
std::fs::write("target/out.bin", binary).map_err(|e| UtilError::File(e))?;
|
||||
dfu.download_raw(
|
||||
&mut std::fs::OpenOptions::new()
|
||||
.read(true)
|
||||
.open("target/out.bin")
|
||||
.map_err(|e| UtilError::File(e))?,
|
||||
address,
|
||||
None,
|
||||
)
|
||||
.map_err(|e| UtilError::Dfu(e))?;
|
||||
std::fs::remove_file("target/out.bin").map_err(|e| UtilError::File(e))?;
|
||||
}
|
||||
pub fn flash_bin(binary: &[u8], d: &rusb::Device<GlobalContext>) -> Result<(), UtilError> {
|
||||
let mut dfu = dfu_libusb::DfuLibusb::open(
|
||||
&rusb::Context::new().unwrap(),
|
||||
d.device_descriptor().unwrap().vendor_id(),
|
||||
d.device_descriptor().unwrap().product_id(),
|
||||
0,
|
||||
0,
|
||||
)
|
||||
.map_err(|e| UtilError::Dfu(e))?;
|
||||
|
||||
dfu.download_from_slice(binary).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn vendor_map() -> std::collections::HashMap<String, Vec<(u16, u16)>> {
|
||||
maplit::hashmap! {
|
||||
"stm32f4".to_string() => vec![(0x0483, 0xdf11)],
|
||||
"stm32".to_string() => vec![(0x0483, 0xdf11)],
|
||||
"gd32vf103".to_string() => vec![(0x28e9, 0x0189)],
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user