From b445971365ab104feaac6c1aa3f15fc8188d5d28 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Dec 2021 11:13:21 +1100 Subject: [PATCH] AP_BoardConfig: disable STLink debug pins by default (4.0 version) 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 | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libraries/AP_BoardConfig/AP_BoardConfig.cpp b/libraries/AP_BoardConfig/AP_BoardConfig.cpp index e258616254..71067f9979 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig.cpp +++ b/libraries/AP_BoardConfig/AP_BoardConfig.cpp @@ -244,7 +244,7 @@ const AP_Param::GroupInfo AP_BoardConfig::var_info[] = { // @Param: OPTIONS // @DisplayName: Board options // @Description: Board specific option flags - // @Bitmask: 0:Enable hardware watchdog + // @Bitmask: 0:Enable hardware watchdog, 3:Enable Debug Pins // @User: Advanced AP_GROUPINFO("OPTIONS", 19, AP_BoardConfig, _options, HAL_BRD_OPTIONS_DEFAULT), @@ -337,6 +337,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 33c7f114ae..3d7231d0d0 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig.h +++ b/libraries/AP_BoardConfig/AP_BoardConfig.h @@ -164,6 +164,7 @@ public: enum board_options { BOARD_OPTION_WATCHDOG = (1 << 0), + BOARD_OPTION_DEBUG_ENABLE = (1 << 3), }; // return true if watchdog enabled @@ -210,6 +211,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 c331618980..8b30b88ce2 100644 --- a/libraries/AP_BoardConfig/board_drivers.cpp +++ b/libraries/AP_BoardConfig/board_drivers.cpp @@ -47,6 +47,22 @@ void AP_BoardConfig::board_init_safety() } +/* + 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() +{ + 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 + } +} + #if AP_FEATURE_BOARD_DETECT AP_BoardConfig::px4_board_type AP_BoardConfig::px4_configured_board;