From 156020cf01e0bb3e765dac2366168213f6653f65 Mon Sep 17 00:00:00 2001 From: blckmn Date: Tue, 8 Jul 2025 10:42:45 +1000 Subject: [PATCH 1/2] PICO: Implement debug pin --- mk/source.mk | 1 - src/platform/APM32/mk/APM32F4.mk | 3 +- src/platform/AT32/mk/AT32F4.mk | 3 +- src/platform/PICO/debug_pin.c | 84 +++++++++++++++++++ src/platform/PICO/mk/RP2350.mk | 3 +- src/platform/STM32/mk/STM32_COMMON.mk | 3 +- .../common/stm32}/debug_pin.c | 6 +- 7 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 src/platform/PICO/debug_pin.c rename src/{main/build => platform/common/stm32}/debug_pin.c (96%) diff --git a/mk/source.mk b/mk/source.mk index 90a7cda738..e8b567d041 100644 --- a/mk/source.mk +++ b/mk/source.mk @@ -53,7 +53,6 @@ PG_SRC = \ COMMON_SRC = \ build/build_config.c \ build/debug.c \ - build/debug_pin.c \ build/version.c \ main.c \ common/bitarray.c \ diff --git a/src/platform/APM32/mk/APM32F4.mk b/src/platform/APM32/mk/APM32F4.mk index 7affd8f0e5..2d7cb4b4eb 100644 --- a/src/platform/APM32/mk/APM32F4.mk +++ b/src/platform/APM32/mk/APM32F4.mk @@ -189,7 +189,8 @@ MCU_COMMON_SRC = \ common/stm32/serial_uart_pinconfig.c \ drivers/serial_escserial.c \ drivers/serial_pinconfig.c \ - APM32/system_apm32f4xx.c + APM32/system_apm32f4xx.c \ + common/stm32/debug_pin.c VCP_SRC = \ APM32/usb/vcp/usbd_cdc_descriptor.c \ diff --git a/src/platform/AT32/mk/AT32F4.mk b/src/platform/AT32/mk/AT32F4.mk index e9ab808694..834732d9f3 100644 --- a/src/platform/AT32/mk/AT32F4.mk +++ b/src/platform/AT32/mk/AT32F4.mk @@ -135,7 +135,8 @@ MCU_COMMON_SRC = \ msc/usbd_storage_emfat.c \ msc/emfat.c \ msc/emfat_file.c \ - msc/usbd_storage_sd_spi.c + msc/usbd_storage_sd_spi.c \ + common/stm32/debug_pin.c SPEED_OPTIMISED_SRC += \ common/stm32/dshot_bitbang_shared.c \ diff --git a/src/platform/PICO/debug_pin.c b/src/platform/PICO/debug_pin.c new file mode 100644 index 0000000000..6d4db50322 --- /dev/null +++ b/src/platform/PICO/debug_pin.c @@ -0,0 +1,84 @@ +/* + * This file is part of Betaflight. + * + * Betaflight is free software. You can redistribute this software + * and/or modify this software under the terms of the GNU General + * Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later + * version. + * + * Betaflight is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this software. + * + * If not, see . + */ + +#include "platform.h" + +#include "build/debug_pin.h" + +#ifdef USE_DEBUG_PIN + +#ifndef DEBUG_PIN_COUNT +#define DEBUG_PIN_COUNT 0 +#endif + +#include "drivers/io.h" +#include "drivers/io_impl.h" + +dbgPin_t dbgPins[DEBUG_PIN_COUNT] = { +#ifdef DEBUG_PIN1 + { .tag = IO_TAG(DEBUG_PIN1) }, +#endif +#ifdef DEBUG_PIN2 + { .tag = IO_TAG(DEBUG_PIN2) }, +#endif +}; +IO_t dbgPinIOs[DEBUG_PIN_COUNT] = { 0 }; +#endif + +void dbgPinInit(void) +{ +#ifdef USE_DEBUG_PIN + for (unsigned i = 0; i < ARRAYLEN(dbgPins); i++) { + const dbgPin_t *dbgPin = &dbgPins[i]; + IO_t io = IOGetByTag(dbgPin->tag); + if (!io) { + continue; + } + IOInit(io, OWNER_SYSTEM, 0); + IOConfigGPIO(io, IOCFG_OUT_PP); + dbgPinIOs[i] = io; + } +#endif +} + +void dbgPinHi(int index) +{ +#ifdef USE_DEBUG_PIN + if ((unsigned)index >= ARRAYLEN(dbgPinIOs)) { + return; + } + IOHi(dbgPinIOs[index]); +#else + UNUSED(index); +#endif +} + +void dbgPinLo(int index) +{ +#ifdef USE_DEBUG_PIN + if ((unsigned)index >= ARRAYLEN(dbgPinIOs)) { + return; + } + IOLo(dbgPinIOs[index]); +#else + UNUSED(index); +#endif +} diff --git a/src/platform/PICO/mk/RP2350.mk b/src/platform/PICO/mk/RP2350.mk index b26625e412..a6879755c1 100644 --- a/src/platform/PICO/mk/RP2350.mk +++ b/src/platform/PICO/mk/RP2350.mk @@ -408,7 +408,8 @@ MCU_COMMON_SRC = \ PICO/serial_usb_vcp_pico.c \ PICO/system.c \ PICO/usb/usb_cdc.c \ - PICO/multicore.c + PICO/multicore.c \ + PICO/debug_pin.c DEVICE_STDPERIPH_SRC := \ $(PICO_LIB_SRC) \ diff --git a/src/platform/STM32/mk/STM32_COMMON.mk b/src/platform/STM32/mk/STM32_COMMON.mk index da565fd38c..e2912d6342 100644 --- a/src/platform/STM32/mk/STM32_COMMON.mk +++ b/src/platform/STM32/mk/STM32_COMMON.mk @@ -17,7 +17,8 @@ MCU_COMMON_SRC += \ STM32/pwm_output_hw.c \ common/stm32/pwm_output_dshot_shared.c \ common/stm32/pwm_output_beeper.c \ - common/stm32/dshot_bitbang_shared.c + common/stm32/dshot_bitbang_shared.c \ + common/stm32/debug_pin.c SIZE_OPTIMISED_SRC += \ drivers/bus_spi_config.c \ diff --git a/src/main/build/debug_pin.c b/src/platform/common/stm32/debug_pin.c similarity index 96% rename from src/main/build/debug_pin.c rename to src/platform/common/stm32/debug_pin.c index eb070f369f..281ccd3c06 100644 --- a/src/main/build/debug_pin.c +++ b/src/platform/common/stm32/debug_pin.c @@ -20,10 +20,14 @@ #include "platform.h" -#include "debug_pin.h" +#include "build/debug_pin.h" #ifdef USE_DEBUG_PIN +#ifndef DEBUG_PIN_COUNT +#define DEBUG_PIN_COUNT 0 +#endif + #include "drivers/io.h" #include "drivers/io_impl.h" From 5e481d52312f516bf04968dae1ddfe69c7cbae1f Mon Sep 17 00:00:00 2001 From: blckmn Date: Tue, 8 Jul 2025 19:05:39 +1000 Subject: [PATCH 2/2] Adding validity check on pin io --- src/platform/PICO/debug_pin.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/platform/PICO/debug_pin.c b/src/platform/PICO/debug_pin.c index 6d4db50322..0cde0bccb1 100644 --- a/src/platform/PICO/debug_pin.c +++ b/src/platform/PICO/debug_pin.c @@ -62,9 +62,10 @@ void dbgPinInit(void) void dbgPinHi(int index) { #ifdef USE_DEBUG_PIN - if ((unsigned)index >= ARRAYLEN(dbgPinIOs)) { + if ((unsigned)index >= ARRAYLEN(dbgPinIOs) || !dbgPinIOs[index]) { return; } + IOHi(dbgPinIOs[index]); #else UNUSED(index); @@ -74,9 +75,10 @@ void dbgPinHi(int index) void dbgPinLo(int index) { #ifdef USE_DEBUG_PIN - if ((unsigned)index >= ARRAYLEN(dbgPinIOs)) { + if ((unsigned)index >= ARRAYLEN(dbgPinIOs) || !dbgPinIOs[index]) { return; } + IOLo(dbgPinIOs[index]); #else UNUSED(index);