Added test application for flashing
This commit is contained in:
parent
77eebdf795
commit
b2830a1fbc
5 changed files with 115 additions and 3 deletions
|
|
@ -19,3 +19,6 @@ tracing = "0.1.40"
|
|||
tracing-subscriber = "0.3.18"
|
||||
radomctl-protocol = { path = "../protocol" }
|
||||
postcard = {version = "1.0.10", features = ["use-std"]}
|
||||
dfu-libusb = "0.3.0"
|
||||
libusb1-sys = "0.6"
|
||||
rusb = "0.9"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
use std::time::Duration;
|
||||
use std::{
|
||||
io::{self, Seek},
|
||||
thread,
|
||||
time::{self, Duration},
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use dfu_libusb::{Dfu, DfuLibusb};
|
||||
use postcard::{from_bytes_cobs, to_stdvec_cobs};
|
||||
use radomctl_protocol::*;
|
||||
use radomctld::logger::setup_logger;
|
||||
|
||||
pub fn main() -> () {
|
||||
pub fn main() -> anyhow::Result<()> {
|
||||
let mut port = serialport::new("/dev/ttyACM0", 115_200)
|
||||
.timeout(Duration::from_millis(10))
|
||||
.open()
|
||||
|
|
@ -13,4 +19,28 @@ pub fn main() -> () {
|
|||
let host_msg = HostMessage::TriggerDFUBootloader;
|
||||
let msg_bytes = to_stdvec_cobs(&host_msg).unwrap();
|
||||
port.write_all(&msg_bytes).unwrap();
|
||||
drop(port);
|
||||
|
||||
let context = rusb::Context::new()?;
|
||||
let mut file = std::fs::File::open("../../firmware/radomctl-firmware.bin")
|
||||
.context("firmware file not found")?;
|
||||
|
||||
thread::sleep(time::Duration::from_millis(1000));
|
||||
|
||||
let file_size =
|
||||
u32::try_from(file.seek(io::SeekFrom::End(0))?).context("the firmware file is too big")?;
|
||||
file.seek(io::SeekFrom::Start(0))?;
|
||||
|
||||
let vid = 0x0483;
|
||||
let pid = 0xdf11;
|
||||
let intf = 0;
|
||||
let alt = 0;
|
||||
let mut device: Dfu<rusb::Context> =
|
||||
DfuLibusb::open(&context, vid, pid, intf, alt).context("could not open device")?;
|
||||
|
||||
device
|
||||
.download(file, file_size)
|
||||
.context("could not write firmware to the device")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue