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

release debug pins on HC32 boards #26985

Merged

Conversation

shadow578
Copy link
Contributor

Description

On some all currently supported HC32 boards, pins normally assigned to debugging functions are re-used for other functions.
The PR implements DISABLE_DEBUG and DISABLE_JTAG in the HC32 HAL and adds the corrosponding defined to the HC32 board files.

Currently, this doesn't cause issues since the bootloader releases these pins before booting into Marlin.
However, it's probably best to not rely on a side-effect of the bootloader, in case it changes with newer board revisions (or the user changes it).

Requirements

HC32-Based Board

Benefits

Removes reliance on side-effect of the bootloader

Configurations

N/A

Related Issues

N/A

Appendix

PSPCR register overview (set by PORT_DebugPortSetting)

grafik
Except from HC32F460 Reference Manual, Section 9.4.7 Special Control Register (PSPCR)

Debug Port Pins assignments according to HC32F460 Datasheet

Pin Debug Function
PA13 JTMS / SWDIO
PA14 JTCK / SWCLK
PA15 JTDI
PB3 JTDO
PB4 NJTRST

Comment on lines 159 to 161
#define JTAGSWD_RESET() PORT_DebugPortSetting(0x1F, Enable); // enable JTDO, JTDI, NJTRST, SWDIO, SWCLK
#define JTAG_DISABLE() PORT_DebugPortSetting(0x1C, Disable); // disable JTDO, JTDI, NJTRST
#define JTAGSWD_DISABLE() PORT_DebugPortSetting(0x1F, Disable); // disable JTDO, JTDI, NJTRST, SWDIO, SWCLK
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of using the named variables here for the pins?

Suggested change
#define JTAGSWD_RESET() PORT_DebugPortSetting(0x1F, Enable); // enable JTDO, JTDI, NJTRST, SWDIO, SWCLK
#define JTAG_DISABLE() PORT_DebugPortSetting(0x1C, Disable); // disable JTDO, JTDI, NJTRST
#define JTAGSWD_DISABLE() PORT_DebugPortSetting(0x1F, Disable); // disable JTDO, JTDI, NJTRST, SWDIO, SWCLK
#define JTAGSWD_RESET() PORT_DebugPortSetting(ALL_DBG_PIN, Enable);
#define JTAG_DISABLE() PORT_DebugPortSetting(TDO_SWO | TDI | TRST, Disable);
#define JTAGSWD_DISABLE() PORT_DebugPortSetting(ALL_DBG_PIN, Disable);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks a lot more readable than using "magic" values. I'll update the PR accordingly

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the delay, I had seen your comment but didn't realize the change has been made.

Copy link
Contributor

Choose a reason for hiding this comment

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

The bit names I used in my recommendation were actually from the HC32 headers, I don't think you had to redefine them.

That said, your bit names are a little more consistent than those, so I think it is fine to go ahead and use what you've done in your most recent change.

implements DISABLE_DEBUG and DISABLE_JTAG in HAL
@shadow578 shadow578 force-pushed the add/release-debug-function branch from bc7dfe6 to 87636d4 Compare April 22, 2024 06:42
@sjasonsmith sjasonsmith merged commit a805872 into MarlinFirmware:bugfix-2.1.x Apr 28, 2024
62 checks passed
@shadow578 shadow578 deleted the add/release-debug-function branch May 12, 2024 08:40
RPGFabi pushed a commit to RPGFabi/Marlin that referenced this pull request Jun 15, 2024
implements DISABLE_DEBUG and DISABLE_JTAG in HAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants