Skip to content
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

Feature/wch link support #2061

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

perigoso
Copy link
Contributor

Detailed description

This is the first part of #1399 which will be broken up into smaller PR's

This adds support for the WCH-Link debug probe by WCH, it's a naive implementation based on a rough reverse engineer of the protocol, which is not publicly documented

Your checklist for this pull request

Closing issues

@dragonmux dragonmux added this to the v2.1 release milestone Jan 23, 2025
@dragonmux dragonmux added the Enhancement General project improvement label Jan 23, 2025
Copy link
Member

@dragonmux dragonmux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do please update all the copyright strings across all the files to include the current year date. Eg 2023-2025 instead of just 2023.

This is only a preliminary review - we still have two files to go through, but this is looking great so far.

Comment on lines +85 to +86
libbmd_core_args += ['-DENABLE_RVSWD=1']
bmd_core_args += ['-DENABLE_RVSWD=1']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We suggest making this CONFIG_RVSWD to be consistent with the revamped macro naming style. The if just above needs checking as we think the condition is wrong - think it should be checking rvswd_support, not rtt_support.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, I noticed after pushing

if (dmi->version == RISCV_DEBUG_UNKNOWN)
return;
if (dmi->version == RISCV_DEBUG_0_11) {
DEBUG_INFO("RISC-V debug v0.11 not presently supported\n");
DEBUG_INFO("RISC-V v0.11 DMI is not presently supported\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inclusion of the term "debug" here is very intentional as the specification is the RISC-V Debug specification, not the ISA specification. For this piece of technical clarity in case we wind up needing to specify ISA specification conformance too, we would like to keep including this extra word in all messages involving the DTM, DMI, and DM versioning. Adding this is about the DMI version is good though 👍🏼

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, that does make sense, I'll reword it again

@@ -586,18 +613,21 @@ static riscv_debug_version_e riscv_dm_version(const uint32_t status)
case 0:
return RISCV_DEBUG_UNIMPL;
case 1:
DEBUG_INFO("RISC-V debug v0.11 DM\n");
DEBUG_INFO("RISC-V v0.11 Debug Module\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for these strings as above.

}

/* Reads the 96 bit unique id */
static bool ch32vx_uid_cmd(target_s *const target, const int argc, const char **const argv)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this able to use the stm32_common.c stm32_uid() function? Would be neat if it can.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, a lot of things can be shared with stm32, that's what #1642 was about, but that's a mess now, I'll look but I might push sharing stuff for later

}

if (!scan_result) {
platform_target_clk_output_enable(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line and its identical counterpart below can be lifted out together just above the check for the scan result. That reduces repetition.

Comment on lines -345 to +408
if (!scan_result)
if (!scan_result) {
gdb_out("SWD scan found no devices.\n");
#if defined(ENABLE_RVSWD) && defined(PLATFORM_HAS_RVSWD)
#if CONFIG_BMDA == 1
scan_result = bmda_rvswd_scan();
#else
scan_result = false;
#endif
if (!scan_result)
gdb_out("RVSWD scan found no devices.\n");
#endif
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given how nested this is getting, perhaps lets invert this logic by extracting the post-scan actions into their own function (this allows all scan routines to stop duplicating those same actions) so we can check if (scan_result) and then return via that post-scan routine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some ideas to help with that and make it more future proof too, but for now some minor refactor in that direction wouldn't hurt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement General project improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants