From 2ecfda80aceb76d2ef774393b24c26f54794fa81 Mon Sep 17 00:00:00 2001 From: Alexander Amelkin Date: Sun, 30 Sep 2018 03:00:49 +0300 Subject: [PATCH] Improve support for JTAG/SWD pins reuse (#11963) STM32 can reuse JTAG and SWD pins separately. Add `DISABLE_DEBUG` option to disable both interfaces and retain `DISABLE_JTAG` to disable JTAG only. --- Marlin/src/HAL/HAL_STM32F1/HAL.h | 3 ++- Marlin/src/HAL/HAL_STM32F4/HAL.h | 3 ++- Marlin/src/Marlin.cpp | 11 ++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL.h b/Marlin/src/HAL/HAL_STM32F1/HAL.h index dcb9b260e0..81d08d5278 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL.h +++ b/Marlin/src/HAL/HAL_STM32F1/HAL.h @@ -249,6 +249,7 @@ void HAL_enable_AdcFreerun(void); #define GET_PIN_MAP_INDEX(pin) pin #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval) -#define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE) +#define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY) +#define JTAGSWD_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE) #endif // _HAL_STM32F1_H diff --git a/Marlin/src/HAL/HAL_STM32F4/HAL.h b/Marlin/src/HAL/HAL_STM32F4/HAL.h index 6d51f6e776..20d9e05999 100644 --- a/Marlin/src/HAL/HAL_STM32F4/HAL.h +++ b/Marlin/src/HAL/HAL_STM32F4/HAL.h @@ -248,6 +248,7 @@ void HAL_enable_AdcFreerun(void); #define GET_PIN_MAP_INDEX(pin) pin #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval) -#define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE) +#define JTAG_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY) +#define JTAGSWD_DISABLE() afio_cfg_debug_ports(AFIO_DEBUG_NONE) #endif // _HAL_STM32F4_H diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index 6d787fac48..4bb1a1fb92 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -686,7 +686,16 @@ void setup() { max7219.init(); #endif - #if ENABLED(DISABLE_JTAG) + #if ENABLED(DISABLE_DEBUG) + // Disable any hardware debug to free up pins for IO + #ifdef JTAGSWD_DISABLE + JTAGSWD_DISABLE(); + #elif defined(JTAG_DISABLE) + JTAG_DISABLE(); + #else + #error "DISABLE_DEBUG is not supported for the selected MCU/Board" + #endif + #elif ENABLED(DISABLE_JTAG) // Disable JTAG to free up pins for IO #ifdef JTAG_DISABLE JTAG_DISABLE();