Skip to content

Commit 7b0b649

Browse files
[fpga-boss] add command to reset FPGA from FTDI chip (#2426)
* [fpga-boss] fix comment Signed-off-by: Tim Trippel <ttrippel@google.com> * [fpga-boss] make `sdwire` and `usbsdmux` nonmandatory args Not all subcommands require these args to be set. Refactor the code such that only subcommands that use these args require them. Signed-off-by: Tim Trippel <ttrippel@google.com> * [fpga-boss] add command to reset FPGA from FTDI chip Currently the only way to reset the FPGA board was to also toggle the SD card mux which, as a byproduct, also toggled the FPGA reset. This adds a dedicated FPGA reset command to fpga-boss. Signed-off-by: Tim Trippel <ttrippel@google.com> --------- Signed-off-by: Tim Trippel <ttrippel@google.com>
1 parent 15071c1 commit 7b0b649

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

ci-tools/fpga-boss/src/fpga_jtag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl FpgaJtag {
3333
// Set PS_POR_B high, PS_SRST_B low
3434
self.ftdi.write_all_data(&[0x8d])?;
3535

36-
// wait a bi
36+
// wait a bit
3737
std::thread::sleep(Duration::from_millis(1));
3838

3939
// Set PS_POR_B and PS_SRST_B pins high

ci-tools/fpga-boss/src/main.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ fn cli() -> clap::Command<'static> {
5555
.arg(arg!(<IMAGE_FILENAME>).value_parser(value_parser!(PathBuf))))
5656
.subcommand(clap::Command::new("console")
5757
.about("Tail the UART output from zcu104"))
58+
.subcommand(clap::Command::new("reset_fpga")
59+
.about("Reset FPGA SoC using FTDI on zcu104 by toggle POR_B reset."))
5860
.subcommand(clap::Command::new("reset_ftdi")
5961
.about("Reset FTDI chip on zcu104"))
6062
.subcommand(clap::Command::new("serve")
@@ -235,6 +237,21 @@ fn log_uart_until_helper<R: BufRead>(
235237
Err(Error::new(ErrorKind::UnexpectedEof, "unexpected EOF"))
236238
}
237239

240+
fn get_sd_mux(
241+
sdwire: Option<&OsString>,
242+
usbsdmux: Option<&OsString>,
243+
) -> anyhow::Result<Box<dyn SdMux>> {
244+
match (sdwire, usbsdmux) {
245+
(Some(sdwire), None) => {
246+
Ok(Box::new(SDWire::open(String::from(sdwire.to_str().unwrap()))?) as Box<dyn SdMux>)
247+
}
248+
(None, Some(usbsdmux)) => Ok(Box::new(UsbsdMux::open(String::from(
249+
usbsdmux.to_str().unwrap(),
250+
))?) as Box<dyn SdMux>),
251+
_ => Err(anyhow!("One of --sdwire or --usbsdmux required")),
252+
}
253+
}
254+
238255
fn main_impl() -> anyhow::Result<()> {
239256
let matches = cli().get_matches();
240257
let sdwire = matches.get_one::<OsString>("sdwire");
@@ -259,19 +276,10 @@ fn main_impl() -> anyhow::Result<()> {
259276
.cloned()
260277
};
261278

262-
let mut sd_mux: Box<dyn SdMux> = match (sdwire, usbsdmux) {
263-
(Some(sdwire), None) => {
264-
Box::new(SDWire::open(String::from(sdwire.to_str().unwrap()))?) as Box<dyn SdMux>
265-
}
266-
(None, Some(usbsdmux)) => {
267-
Box::new(UsbsdMux::open(String::from(usbsdmux.to_str().unwrap()))?) as Box<dyn SdMux>
268-
}
269-
_ => return Err(anyhow!("One of --sdwire or --usbsdmux required")),
270-
};
271-
272279
let get_fpga_ftdi = || FpgaJtag::open(get_zcu104_path()?);
273280
match matches.subcommand() {
274281
Some(("mode", sub_matches)) => {
282+
let mut sd_mux = get_sd_mux(sdwire, usbsdmux)?;
275283
let mut fpga = get_fpga_ftdi();
276284
match sub_matches.get_one::<SdMuxTarget>("MODE").unwrap() {
277285
SdMuxTarget::Dut => {
@@ -292,6 +300,16 @@ fn main_impl() -> anyhow::Result<()> {
292300
}
293301
}
294302
}
303+
Some(("reset_fpga", _)) => {
304+
let mut fpga = get_fpga_ftdi();
305+
if let Ok(fpga) = &mut fpga {
306+
fpga.set_reset(FpgaReset::Reset)?;
307+
std::thread::sleep(Duration::from_millis(1));
308+
fpga.set_reset(FpgaReset::Run)?;
309+
} else {
310+
return Err(anyhow!("Error: failed to connect to FTDI chip."));
311+
}
312+
}
295313
Some(("reset_ftdi", _)) => {
296314
let mut fpga = get_fpga_ftdi()?;
297315
fpga.ftdi.reset()?;
@@ -334,6 +352,7 @@ fn main_impl() -> anyhow::Result<()> {
334352
println!();
335353
}
336354
Some(("flash", sub_matches)) => {
355+
let mut sd_mux = get_sd_mux(sdwire, usbsdmux)?;
337356
let mut fpga = get_fpga_ftdi();
338357
let sd_dev_path = sd_mux.get_sd_dev_path()?;
339358
if let Ok(fpga) = &mut fpga {
@@ -363,6 +382,7 @@ fn main_impl() -> anyhow::Result<()> {
363382
}
364383

365384
Some(("serve", sub_matches)) => {
385+
let mut sd_mux = get_sd_mux(sdwire, usbsdmux)?;
366386
// Reuse the previous token if we never connect to GitHub.
367387
// This avoids creating a bunch of offline runners if the FPGA fails to establish a
368388
// connection.

0 commit comments

Comments
 (0)