From 49869fa2bbdb602f97e57f5f89c0e6689ab0309b Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Wed, 18 Aug 2021 15:26:24 +0200 Subject: [PATCH] Debug - Initialise debug pins on startup, not as part of the dshot bitbang code. --- src/main/build/debug_pin.h | 2 ++ src/main/drivers/dshot_bitbang.c | 18 +++++------------- src/main/drivers/dshot_bitbang_stdperiph.c | 17 +++++------------ src/main/fc/init.c | 5 +++++ 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/main/build/debug_pin.h b/src/main/build/debug_pin.h index ce31f50cdd..bb86131930 100644 --- a/src/main/build/debug_pin.h +++ b/src/main/build/debug_pin.h @@ -20,6 +20,8 @@ #pragma once +#include + typedef struct dbgPin_s { ioTag_t tag; } dbgPin_t; diff --git a/src/main/drivers/dshot_bitbang.c b/src/main/drivers/dshot_bitbang.c index c4098a2b5c..d2fad40c06 100644 --- a/src/main/drivers/dshot_bitbang.c +++ b/src/main/drivers/dshot_bitbang.c @@ -27,6 +27,7 @@ #ifdef USE_DSHOT_BITBANG #include "build/debug.h" +#include "build/debug_pin.h" #include "drivers/io.h" #include "drivers/io_impl.h" @@ -46,14 +47,6 @@ #include "pg/motor.h" -#if defined(USE_DEBUG_PIN) -#include "build/debug_pin.h" -#else -#define dbgPinInit() -#define dbgPinHi(x) -#define dbgPinLo(x) -#endif - FAST_DATA_ZERO_INIT bbPacer_t bbPacers[MAX_MOTOR_PACERS]; // TIM1 or TIM8 FAST_DATA_ZERO_INIT int usedMotorPacers = 0; @@ -300,7 +293,7 @@ static void bbAllocDma(bbPort_t *bbPort) void bbDMAIrqHandler(dmaChannelDescriptor_t *descriptor) { - dbgPinHi(0); + DEBUG_HI(0); bbPort_t *bbPort = (bbPort_t *)descriptor->userParam; @@ -333,7 +326,7 @@ void bbDMAIrqHandler(dmaChannelDescriptor_t *descriptor) } } #endif - dbgPinLo(0); + DEBUG_LO(0); } // Setup bbPorts array elements so that they each have a TIM1 or TIM8 channel @@ -693,9 +686,8 @@ dshotBitbangStatus_e dshotBitbangGetStatus() motorDevice_t *dshotBitbangDevInit(const motorDevConfig_t *motorConfig, uint8_t count) { - dbgPinInit(); - dbgPinLo(0); - dbgPinLo(1); + DEBUG_LO(0); + DEBUG_LO(1); motorPwmProtocol = motorConfig->motorPwmProtocol; bbDevice.vTable = bbVTable; diff --git a/src/main/drivers/dshot_bitbang_stdperiph.c b/src/main/drivers/dshot_bitbang_stdperiph.c index 69e3ed7b72..cf599944a6 100644 --- a/src/main/drivers/dshot_bitbang_stdperiph.c +++ b/src/main/drivers/dshot_bitbang_stdperiph.c @@ -28,6 +28,7 @@ #include "build/atomic.h" #include "build/debug.h" +#include "build/debug_pin.h" #include "drivers/io.h" #include "drivers/io_impl.h" @@ -44,14 +45,6 @@ #include "pg/motor.h" -#if defined(USE_DEBUG_PIN) -#include "build/debug_pin.h" -#else -#define dbgPinInit() -#define dbgPinHi(x) -#define dbgPinLo(x) -#endif - void bbGpioSetup(bbMotor_t *bbMotor) { bbPort_t *bbPort = bbMotor->bbPort; @@ -142,7 +135,7 @@ static void bbSaveDMARegs(dmaResource_t *dmaResource, dmaRegCache_t *dmaRegCache void bbSwitchToOutput(bbPort_t * bbPort) { - dbgPinHi(1); + DEBUG_HI(1); // Output idle level before switching to output // Use BSRR register for this // Normal: Use BR (higher half) @@ -173,13 +166,13 @@ void bbSwitchToOutput(bbPort_t * bbPort) bbPort->direction = DSHOT_BITBANG_DIRECTION_OUTPUT; - dbgPinLo(1); + DEBUG_LO(1); } #ifdef USE_DSHOT_TELEMETRY void bbSwitchToInput(bbPort_t *bbPort) { - dbgPinHi(1); + DEBUG_HI(1); // Set GPIO to input @@ -208,7 +201,7 @@ void bbSwitchToInput(bbPort_t *bbPort) bbPort->direction = DSHOT_BITBANG_DIRECTION_INPUT; - dbgPinLo(1); + DEBUG_LO(1); } #endif diff --git a/src/main/fc/init.c b/src/main/fc/init.c index 16d48d1b82..2f08023fd6 100644 --- a/src/main/fc/init.c +++ b/src/main/fc/init.c @@ -29,6 +29,7 @@ #include "build/build_config.h" #include "build/debug.h" +#include "build/debug_pin.h" #include "cms/cms.h" #include "cms/cms_types.h" @@ -413,6 +414,10 @@ void init(void) systemState |= SYSTEM_STATE_CONFIG_LOADED; +#ifdef USE_DEBUG_PIN + dbgPinInit(); +#endif + #ifdef USE_SDCARD // Ensure the SD card is initialised before the USB MSC starts to avoid a race condition #if !defined(CONFIG_IN_SDCARD) && defined(STM32H7) && defined(USE_SDCARD_SDIO) // H7 only for now, likely should be applied to F4/F7 too