From 0751756e91b6fa1a5b7ccaf68984a530fc9e616f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 15 Nov 2019 15:03:33 +1100 Subject: [PATCH] HAL_ChibiOS: retain OPENDRAIN if set on a pin this allows OPENDRAIN when set on a pin to be retained when set with a pinMode(). This fixes a partially lit B/E LED on the Pixhawk4 --- libraries/AP_HAL_ChibiOS/GPIO.cpp | 10 ++++++++++ libraries/AP_HAL_ChibiOS/hwdef/fmuv5/hwdef.dat | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_ChibiOS/GPIO.cpp b/libraries/AP_HAL_ChibiOS/GPIO.cpp index 554982db6c..a9b927c942 100644 --- a/libraries/AP_HAL_ChibiOS/GPIO.cpp +++ b/libraries/AP_HAL_ChibiOS/GPIO.cpp @@ -17,6 +17,7 @@ #include "GPIO.h" #include +#include "hwdef/common/stm32_util.h" using namespace ChibiOS; @@ -79,6 +80,15 @@ void GPIO::pinMode(uint8_t pin, uint8_t output) return; } g->mode = output?PAL_MODE_OUTPUT_PUSHPULL:PAL_MODE_INPUT; +#if defined(STM32F7) || defined(STM32H7) || defined(STM32F4) + if (g->mode == PAL_MODE_OUTPUT_PUSHPULL) { + // retain OPENDRAIN if already set + iomode_t old_mode = palReadLineMode(g->pal_line); + if ((old_mode & PAL_MODE_OUTPUT_OPENDRAIN) == PAL_MODE_OUTPUT_OPENDRAIN) { + g->mode = PAL_MODE_OUTPUT_OPENDRAIN; + } + } +#endif palSetLineMode(g->pal_line, g->mode); g->is_input = !output; } diff --git a/libraries/AP_HAL_ChibiOS/hwdef/fmuv5/hwdef.dat b/libraries/AP_HAL_ChibiOS/hwdef/fmuv5/hwdef.dat index c6892fe10c..80a5956964 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/fmuv5/hwdef.dat +++ b/libraries/AP_HAL_ChibiOS/hwdef/fmuv5/hwdef.dat @@ -290,7 +290,7 @@ PC12 SDMMC_CK SDMMC1 PD2 SDMMC_CMD SDMMC1 # red LED marked as B/E -PB1 LED_RED OUTPUT GPIO(90) +PB1 LED_RED OUTPUT OPENDRAIN GPIO(90) # green LED marked as PWR. We leave this solid on, but allow # for it to be controlled as a relay if needed