-
-
Notifications
You must be signed in to change notification settings - Fork 841
RFC: Native implementation of WCH two wire procotol #2172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
4d803d0 to
235fcaf
Compare
|
Hi @mean00. I've checked out this PR as
I don't currently have my WCH-LinkW pair to test with. BMDA needs BMP-remote protocol extended to talk to this new code. Swindle 0.3 (2024-08-20) running on GD32F303CC seems to discover both boards, but it's much more complicated code than BMF. When I dump Flashing a GD32F103CB to swlink and connecting to PA5, PA6 allows me to detect, attach, read/compare and step/stepi the firmware. So clearly it's working, and at 31 KiB/s no less (at max freq via BMF standard target_clk_divider). |
|
Thank you for checking this. It could be because the reverse engineering is approximate and missed some timing information. The only thing i noticed is it barfs above about 1.6 Mb/s, but that's the speed the wch-link is working if my memory is correct. Could it be because the blackpill is much more agressive regarding i/o and/or the code lacks barrier to avoid edge jitters ? I'm not familiar with the F4 line but i had some issues of that kind with the SWD protocol on ESP32S3 chips acting as probe. ( On a separate topic, the CH32V203 is confusing gdb because it has not hw breakpoint and the BMP logic thinks there is one) |
Yes, STM32F4 has proper AHB-attached GPIO, which can toggle (change state) every AHB cycle (96 MHz for F411) thanks to Cortex-M4F pipelined writes and a write buffer. STM32F1 only had APB-attached GPIO, and even though APB2 is same 72 MHz as it's AHB, datasheet says Then I reused a busy delay function from my PR1688 and appended it to IO_ON(), IO_OFF() macros, even though CLK_ON/OFF should be enough (swapped its loops, too). But thus modified firmware displayed better resuts, initial IDCODE started matching, and then I can attach to that chip, step/stepi, break/resume, and WCH : found 0x20310500 device
RISC-V debug v0.13 DM
Hart has 2 data registers and 8 progbuf registers
Attempting 64-bit read on misa
CSR access failed: 2
CSR access failed: 2
CSR access failed: 2
CSR access failed: 2
Attempting 32-bit read on misa
Hart 0: 32-bit RISC-V (arch = dc68d882), rv32imac ISA (exts = 00901105), vendor = 0, impl = dc688001
Hart has 1 trigger slots available
-> riscv32_probeand then either depending on whether I remember to rebuild with One problem remains -- no-scan after DEBUG_TARGET() log from modified BMF |
|
Nice job ! So it can work on the F4 with a bit of love and the time of very qualified people. ( Hart has 1 trigger slots available, no it doesn't :) ) |
|
Compare with top commit of https://github.com/ALTracer/blackmagic/tree/feature/wch_two_wire_protocol (like so mean00/blackmagic@wch_two_wire_protocol...ALTracer:blackmagic:feature/wch_two_wire_protocol ) if you intend to make it compatible with more in-tree probe platforms, at least it fixes it for F4 by making it slower than necessary. Ignore ch32v.c edits, a full flash driver will be needed later anyway. Works (without my local extra speedup edits) with CH32V203 (stepping, no breakpoints) and CH32V307V (hw breakpoints!). You're probably missing a microsecond delay somewhere, and APB handshaking is long enough to mask it. |
Hi, finally had a bit of time:
This is a request for comment regarding the native support of the two wire protocol / rvswdp as used on WCH chips
(at least CH32V1xx/CH32V2xx/CH32V3XX). As far as i could tell it's not present in the current bmp codebase.
I've been using another flavor of that implementaion for a couple of years and afaik without major issues.
It is piggybacking a bit on the SWD implementation by reusing the SWDIO and SWCLK pins.
To avoid duplication a swdptap_common.h file contain the small common part .
I'm fairly sure the integration with the build system and meson setup is not complete.
I've also created a new target for testing cross/swlink-riscv.ini
In short, it implements the rvswd_scan command in native mode, on top of the work done by @perigoso for the wch-link.
Known Limitation/ things that will be reverted when everything else is okay :
1- the CH32 chips will work up to ~ 1.6Mbit/s only.
2- the errors are not necessarily managed correctly, but it seems "good enough"
4- I added temporarily a nop in the loop clock_on/clock_off macro for debug purpose . Those macros are there for readibility sake, i know they are not necessarily loved.
5- i had to change a bit the swlink platform temporarily to suit my test env, please ignore these changes
6- the implementation is very straightforward and use partially reverse engineered information , probably incomplete
Tested with a CH32V307, output is :
Explain the details for making this change.
Your checklist for this pull request
Closing issues