Skip to content

Instantly share code, notes, and snippets.

@a-gavin
Created January 30, 2023 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-gavin/6dc46b83012456379db597664474c125 to your computer and use it in GitHub Desktop.
Save a-gavin/6dc46b83012456379db597664474c125 to your computer and use it in GitHub Desktop.
probe-rs Simple RISC-V API Example
[package]
name = "probe_rs_example"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0.34"
probe-rs = { version = "0.15.0", features = ["ftdi"] }
use anyhow::Result;
use probe_rs::{
Probe
};
// Adapted from the probe-rs raw_dap_access.rs example
fn main() -> Result<()> {
// Get a list of all available debug probes.
let probes = Probe::list_all();
// Use the first probe found.
let mut probe = probes[0].open()?;
probe.attach_to_unspecified()?;
let mut iface = probe.try_into_riscv_interface().unwrap();
// Read and print out idcode of target
let idcode = iface.read_idcode()?;
println!("Chip idcode: {:#x}", idcode);
// Using an FTDI probe and a Longan Nano target, I get the following output:
// Chip idcode: 0x1000563d
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment