From 4ee292ec5ed1e4f6a3d1c4de48176ecd2e832305 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Dec 2021 11:28:09 +1100 Subject: [PATCH] AP_BoardConfig: disable STLink debug pins by default this avoids leaving the debug pins in a state where they may be vulnerable to ESD issues --- libraries/AP_BoardConfig/AP_BoardConfig.cpp | 3 ++- libraries/AP_BoardConfig/AP_BoardConfig.h | 2 ++ libraries/AP_BoardConfig/board_drivers.cpp | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libraries/AP_BoardConfig/AP_BoardConfig.cpp b/libraries/AP_BoardConfig/AP_BoardConfig.cpp index 968ce7f2f6..5ee93f8ed1 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig.cpp +++ b/libraries/AP_BoardConfig/AP_BoardConfig.cpp @@ -269,7 +269,7 @@ const AP_Param::GroupInfo AP_BoardConfig::var_info[] = { // @Param: OPTIONS // @DisplayName: Board options // @Description: Board specific option flags - // @Bitmask: 0:Enable hardware watchdog, 1:Disable MAVftp, 2:Enable set of internal parameters + // @Bitmask: 0:Enable hardware watchdog, 1:Disable MAVftp, 2:Enable set of internal parameters, 3:Enable Debug Pins // @User: Advanced AP_GROUPINFO("OPTIONS", 19, AP_BoardConfig, _options, HAL_BRD_OPTIONS_DEFAULT), @@ -362,6 +362,7 @@ void AP_BoardConfig::set_default_safety_ignore_mask(uint16_t mask) void AP_BoardConfig::init_safety() { board_init_safety(); + board_init_debug(); } /* diff --git a/libraries/AP_BoardConfig/AP_BoardConfig.h b/libraries/AP_BoardConfig/AP_BoardConfig.h index b3f9f92e0d..6acf53722f 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig.h +++ b/libraries/AP_BoardConfig/AP_BoardConfig.h @@ -176,6 +176,7 @@ public: BOARD_OPTION_WATCHDOG = (1 << 0), DISABLE_FTP = (1<<1), ALLOW_SET_INTERNAL_PARM = (1<<2), + BOARD_OPTION_DEBUG_ENABLE = (1<<3), }; // return true if ftp is disabled @@ -237,6 +238,7 @@ private: #endif // AP_FEATURE_BOARD_DETECT void board_init_safety(void); + void board_init_debug(void); void board_setup_uart(void); void board_setup_sbus(void); diff --git a/libraries/AP_BoardConfig/board_drivers.cpp b/libraries/AP_BoardConfig/board_drivers.cpp index c802304713..66fa698587 100644 --- a/libraries/AP_BoardConfig/board_drivers.cpp +++ b/libraries/AP_BoardConfig/board_drivers.cpp @@ -46,6 +46,24 @@ void AP_BoardConfig::board_init_safety() #endif } +/* + init debug pins. We set debug pins as input if BRD_OPTIONS bit for debug enable is not set + this prevents possible ESD issues on the debug pins + */ +void AP_BoardConfig::board_init_debug() +{ +#ifndef HAL_BUILD_AP_PERIPH + if ((_options & BOARD_OPTION_DEBUG_ENABLE) == 0) { +#ifdef HAL_GPIO_PIN_JTCK_SWCLK + palSetLineMode(HAL_GPIO_PIN_JTCK_SWCLK, PAL_MODE_INPUT); +#endif +#ifdef HAL_GPIO_PIN_JTMS_SWDIO + palSetLineMode(HAL_GPIO_PIN_JTMS_SWDIO, PAL_MODE_INPUT); +#endif + } +#endif // HAL_BUILD_AP_PERIPH +} + #if AP_FEATURE_BOARD_DETECT