Skip to content

Conversation

@akkako
Copy link
Contributor

@akkako akkako commented Dec 13, 2025

for hardware design, please refer to HSLink-Iso 1.2.2 hardware repo.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced hardware isolation mode variant for specialized configurations
  • Chores

    • Expanded release artifacts with multiple firmware variants (Standard and Isolated)
    • Updated bootloader and binary naming conventions for consistency
    • Enhanced build workflow to support distinct hardware configurations

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 13, 2025

Walkthrough

The PR introduces hardware isolation mode support to HSLink-Pro by adding conditional build configurations, separate binary variants (HSLink-Pro vs HSLink-Iso), and isolation-aware firmware logic spanning pin I/O, SPI transfers, and clock management.

Changes

Cohort / File(s) Summary
Build workflow
.github/workflows/HSLinkPro-build.yml
Added dual build configurations: initial isolated build followed by CONFIG_HARDWARE_ISOLATED=1 build; generated multiple merger variants (HSLink-Pro-Merger.bin, HSLink-Iso-Merger.bin); expanded release artifacts to include HSLink-Iso.uf2, HSLink-Iso.bin, and updated bootloader naming.
CMake & build configuration
projects/HSLink-Pro/src/CMakeLists.txt
Introduced conditional APP_NAME assignment (HSLink-Iso when CONFIG_HARDWARE_ISOLATED=1, else HSLink-Pro); added HSLINK_ISOLATE preprocessor definition as a compile-time flag.
DAP pin configuration
projects/HSLink-Pro/src/DAP_config.h
Added TMS_IN pin initialization in PORT_OFF; introduced isolation-aware pin reads for SWDIO/TMS inputs; guarded certain SWD I/O transitions with HSLINK_ISOLATE guards to conditionally configure TMS pin behavior.
HID communication
projects/HSLink-Pro/src/HID_COMM/hid_comm.cpp
Conditional Hello response model field: outputs "HSLink-Iso" when HSLINK_ISOLATE defined, otherwise "HSLink-Pro".
JTAG I/O & SPI
projects/HSLink-Pro/src/JTAG_DP/JTAG_DP_IO.c, projects/HSLink-Pro/src/JTAG_DP/JTAG_DP_SPI.c
Added SWDIO_DIR pin configuration with GPIO setup and PAD_CTL initialization; replaced TDO input with SWDIO_DIR as the designated input pin.
SW_DP I/O & SPI
projects/HSLink-Pro/src/SW_DP/SW_DP_IO.c, projects/HSLink-Pro/src/SW_DP/SW_DP_SPI.c
Added PIN_TMS_IN and SWDIO_DIR pin initialization; introduced HSLINK_ISOLATE-driven conditional blocks for SPI transfer format selection (0x1F08/0x0008 vs 0x1F18/0x0018) and MOSI bidirectionality control.
Clock management
projects/HSLink-Pro/src/dp_common.c
Added isolation-mode clock cap: when HSLINK_ISOLATE defined, limits input clock to 20,000,000 Hz before port/SWD/JTAG conditional logic.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

  • SW_DP/SW_DP_SPI.c: Complex conditional SPI transfer logic with multiple TRANSFMT variants requires careful verification of isolation vs. non-isolation behavior and data framing correctness.
  • JTAG_DP/JTAG_DP_IO.c & SW_DP/SW_DP_IO.c: Pin configuration changes (SWDIO_DIR, PIN_TMS_IN) need verification against hardware schematics and electrical isolation requirements.
  • .github/workflows/HSLinkPro-build.yml: Dual build flow and artifact generation changes require validation that both variants are correctly built and packaged.
  • DAP_config.h & dp_common.c: Isolation-aware conditional logic and clock capping must be verified for correctness under isolated operation.

Possibly related PRs

Suggested reviewers

  • RCSN
  • HalfSweet

Poem

🐰 A hop through the build in isolation mode,
Where pins are remapped along the code road,
SPI dances in formats, both old and new,
And clocks take a breather—capped just right, it's true!
Two binaries born from one source so keen,
The cleanest isolation code you've ever seen! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add HSLink-ISO version port' directly matches the primary objective of the PR, which is to introduce HSLink-ISO as a new variant alongside the existing HSLink-Pro implementation.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kaidegit
Copy link
Collaborator

tms也分输入输出吗?怎么有个tmsin

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.github/workflows/HSLinkPro-build.yml (1)

5-13: Workflow trigger paths do not match this file's name.

Lines 6 and 12 reference .github/workflows/HPM-build.yml, but this workflow is named HSLinkPro-build.yml. This means changes to this file won't trigger the workflow itself. If intentional, no action needed; otherwise, update the trigger paths.

   push:
     paths:
-      - '.github/workflows/HPM-build.yml'
+      - '.github/workflows/HSLinkPro-build.yml'
       - 'projects/HSLink-Pro/**'
   pull_request:
     paths:
-      - '.github/workflows/HPM-build.yml'
+      - '.github/workflows/HSLinkPro-build.yml'
       - 'projects/HSLink-Pro/**'
🧹 Nitpick comments (5)
projects/HSLink-Pro/src/DAP_config.h (1)

536-561: Re-check pin-controller “restore” choice in PIN_SWDIO_OUT_DISABLE (gpiom_soc_gpio0 vs PIN_GPIOM).
PIN_SWDIO_OUT_ENABLE() uses gpiom_configure_pin_control_setting(PIN_TMS) (→ PIN_GPIOM), but PIN_SWDIO_OUT_DISABLE() restores controller to gpiom_soc_gpio0. If downstream code assumes PIN_GPIOM ownership for fast IO, this could cause subtle behavior differences.

projects/HSLink-Pro/src/CMakeLists.txt (1)

6-11: Good: variant name + -DHSLINK_ISOLATE={0,1} wiring is straightforward.
Optional: consider STREQUAL "1" (vs EQUAL "1") since these config values often come in as strings/cached options.

Also applies to: 40-45

projects/HSLink-Pro/src/dp_common.c (1)

125-132: Clock clamp makes sense, but use unsigned literals + fix comment typos.
Minor: prefer 20000000U and fix olnyonly to avoid warnings/ambiguity.

 #if HSLINK_ISOLATE
-    // the isolator olny works below 20MHz
+    // the isolator only works below 20 MHz
     // so we set a limit avoid communication failure
-    if (clock > 20000000)
+    if (clock > 20000000U)
     {
-        clock = 20000000;
+        clock = 20000000U;
     }
 #endif
projects/HSLink-Pro/src/SW_DP/SW_DP_IO.c (1)

88-100: Good: SWD IO setup now explicitly configures PIN_TMS_IN + SWDIO_DIR.
Optional hardening: explicitly gpio_disable_pin_interrupt() for PIN_TMS_IN here as well (to avoid any unexpected IRQ configuration inherited from earlier states).

projects/HSLink-Pro/src/SW_DP/SW_DP_SPI.c (1)

239-339: Replace TRANSFMT “magic numbers” with named constants + verify bitfields.
The isolate/non-isolate framing hinges on values like 0x1F08/0x1F18 and 0x0008/0x0018. Please define them (with comments mapping to register fields) to reduce the chance of future accidental breakage—and verify against the HPM SPI TRANSFMT bit definitions for your SDK/SoC.

+// TRANSFMT presets (verify against SoC TRM / hpm_spi_drv.h bitfields)
+#define SWD_TRANSFMT_32_MOSI_BIDIR_0_LSB1 0x1F08U
+#define SWD_TRANSFMT_32_MOSI_BIDIR_1_LSB1 0x1F18U
+#define SWD_TRANSFMT_1_MOSI_BIDIR_0_LSB1  0x0008U
+#define SWD_TRANSFMT_1_MOSI_BIDIR_1_LSB1  0x0018U
...
 #if HSLINK_ISOLATE
-            SWD_SPI_BASE->TRANSFMT = 0x1F08; /* datalen = 32bit, mosibidir = 0, lsb=1 */
+            SWD_SPI_BASE->TRANSFMT = SWD_TRANSFMT_32_MOSI_BIDIR_0_LSB1;
 #else
-            SWD_SPI_BASE->TRANSFMT = 0x1F18; /* datalen = 32bit, mosibidir = 1, lsb=1 */
+            SWD_SPI_BASE->TRANSFMT = SWD_TRANSFMT_32_MOSI_BIDIR_1_LSB1;
 #endif
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee67639 and c815c95.

📒 Files selected for processing (9)
  • .github/workflows/HSLinkPro-build.yml (1 hunks)
  • projects/HSLink-Pro/src/CMakeLists.txt (2 hunks)
  • projects/HSLink-Pro/src/DAP_config.h (6 hunks)
  • projects/HSLink-Pro/src/HID_COMM/hid_comm.cpp (1 hunks)
  • projects/HSLink-Pro/src/JTAG_DP/JTAG_DP_IO.c (2 hunks)
  • projects/HSLink-Pro/src/JTAG_DP/JTAG_DP_SPI.c (1 hunks)
  • projects/HSLink-Pro/src/SW_DP/SW_DP_IO.c (1 hunks)
  • projects/HSLink-Pro/src/SW_DP/SW_DP_SPI.c (9 hunks)
  • projects/HSLink-Pro/src/dp_common.c (1 hunks)
🔇 Additional comments (9)
.github/workflows/HSLinkPro-build.yml (2)

68-85: Artifact copying assumes both build outputs exist.

The merge and copy steps assume both HSLink-Pro.bin and HSLink-Iso.bin are present after the build phase. If the shared build directory (discussed above) causes the first build's output to be lost, these steps will fail silently or copy incorrect/missing files.

Ensure the build directory separation issue is resolved before these steps can reliably execute.


63-66: Build configuration properly differentiates output binaries via APP_NAME variable.

The concern about shared build directory is mitigated: CMakeLists.txt correctly sets APP_NAME to either "HSLink-Iso" or "HSLink-Pro" based on the CONFIG_HARDWARE_ISOLATED flag (lines 6–10), ensuring output binaries are named distinctly and coexist in the same src/build/output/ directory. No separate build directories are needed.

projects/HSLink-Pro/src/HID_COMM/hid_comm.cpp (1)

136-141: Isolation-aware “model” field looks correct (HSLink-Iso vs HSLink-Pro).
Nice, low-risk way to surface the build variant without changing the rest of the payload.

projects/HSLink-Pro/src/DAP_config.h (2)

384-424: Good: PORT_OFF now fully tri-states/configures PIN_TMS_IN too.
This reduces the chance of leaving the extra input pin floating in an unintended mode.


480-521: Ensure PIN_TMS_IN is always correctly muxed before isolate-mode reads.
You now read SWDIO/TMS from PIN_TMS_IN under HSLINK_ISOLATE; that’s fine, but it increases sensitivity to pad FUNC_CTL / pinmux defaults in every SWD/JTAG setup path (not just PORT_OFF).

projects/HSLink-Pro/src/JTAG_DP/JTAG_DP_SPI.c (1)

68-80: Good: SWDIO_DIR pad FUNC_CTL initialized alongside other pads.
Helps avoid relying on reset defaults for a direction-control pin.

projects/HSLink-Pro/src/SW_DP/SW_DP_SPI.c (2)

426-435: Good: mosi_bidir matches isolate vs non-isolate behavior.
Tying format_config.common_config.mosi_bidir to the isolate mode aligns with the TRANSFMT switching in the transfer path.


40-47: No action needed — PIN_TMS_IN pinmux is properly configured.

The FUNC_CTL for PIN_TMS_IN (PA28) is correctly set to SPI1_MISO in board_init_spi_pins() called at line 42. The PAD_CTL configuration at line 46 for ISOLATE mode sets electrical properties (slew rate, speed, pull-enable, pull-select) and is the appropriate place for these settings.

projects/HSLink-Pro/src/JTAG_DP/JTAG_DP_IO.c (1)

265-316: Good: SWDIO_DIR is now explicitly initialized/controlled in JTAG IO setup.
Optional: add a short comment near the PAD_CTL/FUNC_CTL block explaining SWDIO_DIR’s electrical role (direction/isolator control) to prevent future regressions.

@akkako
Copy link
Contributor Author

akkako commented Dec 13, 2025

tms也分输入输出吗?怎么有个tmsin

image

对于HSLink-Iso是需要区分输入和输出的,因为隔离器只能过单向信号,因此输入和输出做了拆分

image

HSLink-Pro的输入输出并联了,原始设计是通过TMS脚单线半双工复用,将TMS_IN设置为输入模式就好

(实际上这种设计在GPIO模拟模式下不仅需要手动切换DIR引脚方向电平,以控制外部电平转换电路方向,还需要手动切换TMS方向,因此速度更慢一些

@kaidegit
Copy link
Collaborator

哦这一会SWDIO DIR一会TMS的让我以为TMS是时钟了。。。

@kaidegit
Copy link
Collaborator

感觉还行,虽然SWDIO_DIR这个命名不是很统一,但是bt写的本来就这样。。。(hslinkpro留了个dir在这里但是不用是什么妙妙操作)

@kaidegit kaidegit requested a review from HalfSweet December 13, 2025 13:50
@akkako
Copy link
Contributor Author

akkako commented Dec 13, 2025

感觉还行,虽然SWDIO_DIR这个命名不是很统一,但是bt写的本来就这样。。。(hslinkpro留了个dir在这里但是不用是什么妙妙操作)

实际用了,这玩意接的是1T45的方向控制

image

if (DAP_Data.swd_conf.data_phase && ((request & DAP_TRANSFER_RnW) == 0U)) {
gpio_write_pin(PIN_GPIO, GPIO_GET_PORT_INDEX(SWDIO_DIR), GPIO_GET_PIN_INDEX(SWDIO_DIR), 1);
SWD_SPI_BASE->TRANSCTRL = 0x01000000; /* only write mode*/
#if HSLINK_ISOLATE
Copy link
Collaborator

Choose a reason for hiding this comment

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

#if 的风格还是要统一一下,跑一下仓库里面的.clang-format格式化吧

gpio_write_pin(PIN_GPIO, GPIO_GET_PORT_INDEX(SWDIO_DIR), GPIO_GET_PIN_INDEX(SWDIO_DIR), 0);
SWD_SPI_BASE->TRANSCTRL = 0x02000000; /* only read mode*/
#if HSLINK_ISOLATE
SWD_SPI_BASE->TRANSFMT = 0x0008; /* datalen = 1bit, mosibidir = 0, lsb=1 */
Copy link
Collaborator

Choose a reason for hiding this comment

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

为什么ISO版本不需要开启MOSIBIDIR呢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

看原理图,ISO版本是双线双向,Pro版是单线双向(硬件22r电阻太小了,没法双线驱动)

gpiom_configure_pin_control_setting(PIN_TCK);
gpiom_configure_pin_control_setting(PIN_TMS);
gpiom_configure_pin_control_setting(PIN_TDI);
gpiom_configure_pin_control_setting(PIN_TDO);
Copy link
Collaborator

Choose a reason for hiding this comment

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

TDO不初始化不会影响到其他版本吗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TDO初始化放到上面去了


writer.Key("model");
#if HSLINK_ISOLATE
writer.String("HSLink-Iso");
Copy link
Collaborator

Choose a reason for hiding this comment

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

ISO保持全大写吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个不和Pro的大小写统一嘛?

@HalfSweet
Copy link
Collaborator

@kaidegit 目前compat板子是用的动态读取版本号,ISO用的是静态的方式加上宏定义控制特性,这两者你觉得有必要统一一下吗

@kaidegit
Copy link
Collaborator

目前compat板子是用的动态读取版本号,ISO用的是静态的方式加上宏定义控制特性,这两者你觉得有必要统一一下吗

因为我看不同的地方蛮多的就觉得宏或许更明确?当然我肯定觉得一个固件做完最好。。。。只是我也感觉有点奇怪怎么有这么多不同的。。。

@HalfSweet
Copy link
Collaborator

我也觉得用一个固件能搞定最好,要不然ISO固件刷到普通板上也可能会有奇怪的反应

@sakumisu
Copy link
Contributor

不考虑增加这么多其他版本的patch,只保留hslink pro。其次,改动太多,比如swdio dir不是main里面配了吗,为什么又重新配,tdo为什么去掉,tms in又是哪来的?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants