Skip to content

Commit 13104ba

Browse files
jonathanherbstgrapplekorken89
authored andcommitted
failed attempt to get swd sequence working
1 parent cf3c508 commit 13104ba

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ embedded-hal-02 = { package = "embedded-hal", version = "0.2.7", features = ["un
1919
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
2020
replace_with = { version = "0.1.7", default-features = false, features = ["panic_abort"] }
2121
usbd-serial = "0.2.0"
22-
dap-rs = { git = "https://github.com/probe-rs/dap-rs.git", branch = "master", features = ["defmt"] }
22+
dap-rs = { git = "https://github.com/Grapple-Systems/dap-rs.git", branch = "add-swd-sequence", features = ["defmt"] }
2323
git-version = "0.3.5"
2424
pio-proc = "0.2.1"
2525
pio = "0.2.1"

src/dap.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,37 @@ impl swd::Swd<Context> for Swd {
326326
Ok(())
327327
}
328328

329+
fn write_sequence(&mut self, mut num_bits: usize, data: &[u8]) -> swd::Result<()> {
330+
self.0.swdio_to_output();
331+
let mut last = self.0.delay.get_current();
332+
333+
for b in data {
334+
let bit_count = core::cmp::min(num_bits, 8);
335+
for i in 0..bit_count {
336+
self.write_bit((b >> i) & 0x1, &mut last);
337+
}
338+
num_bits -= bit_count;
339+
}
340+
341+
Ok(())
342+
}
343+
344+
fn read_sequence(&mut self, mut num_bits: usize, data: &mut [u8]) -> swd::Result<()> {
345+
self.0.swdio_to_input();
346+
let mut last = self.0.delay.get_current();
347+
348+
for b in data {
349+
let bit_count = core::cmp::min(num_bits, 8);
350+
for i in 0..bit_count {
351+
let bit = self.read_bit(&mut last);
352+
*b |= bit << i;
353+
}
354+
num_bits -= bit_count;
355+
}
356+
357+
Ok(())
358+
}
359+
329360
fn set_clock(&mut self, max_frequency: u32) -> bool {
330361
trace!("SWD set clock: freq = {}", max_frequency);
331362
self.0.process_swj_clock(max_frequency)

0 commit comments

Comments
 (0)