ciniml / rust-dap

CMSIS-DAP Rust implementation
Apache License 2.0
88 stars 10 forks source link

SWJ Clock command does not affect SWD bus frequency #24

Closed 9names closed 2 years ago

9names commented 2 years ago

Firmware accepts SWD clock speed command, but does not use the requested value: https://github.com/ciniml/rust-dap/blob/c202096dbfe46edd18bf184ac1b74241179d3cfb/rust-dap/src/cmsis_dap.rs#L378

This is a problem if the physical SWD link can not work correctly at maximum probe speed. Now that firmware is using PIO, this frequency is higher and may cause signal problems.

SWD frequency can be changed by setting clock divider on PIO StateMachine, so fixing this should be easier with PIO than it would be with the bitbang driver.

elfmimi commented 2 years ago

I believe that is kind of by design.

  1. Current setting should achieve reasonably stable operation.
  2. It works nicely performant with no configuration.
  3. There is not much benefit to increase clock rate because throughput is limited by the speed of full-speed USB.
9names commented 2 years ago

1: Operation is stable only if debug target has a fast clock. A target running at 8Mhz will not understand a 16Mhz SWD signal.

3: I am requesting slower speeds

elfmimi commented 2 years ago

I'm rather curious what particular target you have in mind?

9names commented 2 years ago

I was being a bit hypothetical - I am planning to run something slow as a co-processor for badger2040 (which chip will depend on what can be bought). There are other probes that I can use for slow devices or my boards with very bad routing that do not work with high speed SWD.

I was hoping to be able to recommend this firmware for raspberry pi pico users - so they can run it fast if they have good connectors, but we can ask them to run slower if they have bad soldering, cheap wires, connections on breadboards and are having problems.

If this is something you are not interested in supporting, that is okay. Thank you for taking the time to reply.

ciniml commented 2 years ago

I see.

The current implementation of frequency setting is just for a proof-of-concept of Rust implementation.

I will implement the function correctly for both bitbang and PIO.

ciniml commented 2 years ago

Now the rust-dap version which has swj_clock implementation has been merged to the main branch.

You can try the implementation by building rpi_pico firmware with the command line below:

cd boards/rpi_pico
cargo build --release --features=swd,set_clock

If you don't wan't to use PIO, you can specify bitbang feature to disable it.

cd boards/rpi_pico
cargo build --release --features=swd,set_clock,bitbang
9names commented 2 years ago

This works, thank you very much! To test this feature, I used probe-rs-cli to plot SRAM read performance. I hope you like it. rust-dap-perf