From 13a0037b186dfe355fdfae6b9f9d51cdef76a55b Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Wed, 18 Aug 2021 10:17:31 +0200 Subject: [PATCH] Debug - Separate pin config from runtime state/implementation details. --- src/main/build/debug_pin.c | 39 ++++++++++++++++++++++++--------------- src/main/build/debug_pin.h | 4 ++++ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/main/build/debug_pin.c b/src/main/build/debug_pin.c index fb8e711cb..cc05ee193 100644 --- a/src/main/build/debug_pin.c +++ b/src/main/build/debug_pin.c @@ -25,30 +25,39 @@ #include "drivers/io.h" #include "drivers/io_impl.h" -typedef struct dbgPin_s { - ioTag_t tag; +#include "debug_pin.h" + +typedef struct dbgPinState_s { GPIO_TypeDef *gpio; uint32_t setBSRR; uint32_t resetBSRR; -} dbgPin_t; +} dbgPinState_t; + +#ifndef DEBUG_PIN_COUNT +#define DEBUG_PIN_COUNT 1 +#endif -__weak dbgPin_t dbgPins[] = { +// Provide a non-weak reference in target.c or elsewhere +__weak dbgPin_t dbgPins[DEBUG_PIN_COUNT] = { { .tag = IO_TAG(NONE) }, }; +dbgPinState_t dbgPinStates[DEBUG_PIN_COUNT] = { 0 }; + void dbgPinInit(void) { for (unsigned i = 0; i < ARRAYLEN(dbgPins); i++) { dbgPin_t *dbgPin = &dbgPins[i]; + dbgPinState_t *dbgPinState = &dbgPinStates[i]; IO_t io = IOGetByTag(dbgPin->tag); if (!io) { continue; } IOConfigGPIO(io, IOCFG_OUT_PP); - dbgPin->gpio = IO_GPIO(io); + dbgPinState->gpio = IO_GPIO(io); int pinSrc = IO_GPIO_PinSource(io); - dbgPin->setBSRR = (1 << pinSrc); - dbgPin->resetBSRR = (1 << (pinSrc + 16)); + dbgPinState->setBSRR = (1 << pinSrc); + dbgPinState->resetBSRR = (1 << (pinSrc + 16)); } } @@ -58,12 +67,12 @@ void dbgPinHi(int index) return; } - dbgPin_t *dbgPin = &dbgPins[index]; - if (dbgPin->gpio) { + dbgPinState_t *dbgPinState = &dbgPinStates[index]; + if (dbgPinState->gpio) { #if defined(STM32F7) || defined(STM32H7) - dbgPin->gpio->BSRR = dbgPin->setBSRR; + dbgPinState->gpio->BSRR = dbgPinState->setBSRR; #else - dbgPin->gpio->BSRRL = dbgPin->setBSRR; + dbgPinState->gpio->BSRRL = dbgPinState->setBSRR; #endif } } @@ -74,13 +83,13 @@ void dbgPinLo(int index) return; } - dbgPin_t *dbgPin = &dbgPins[index]; + dbgPinState_t *dbgPinState = &dbgPinStates[index]; - if (dbgPin->gpio) { + if (dbgPinState->gpio) { #if defined(STM32F7) || defined(STM32H7) - dbgPin->gpio->BSRR = dbgPin->resetBSRR; + dbgPinState->gpio->BSRR = dbgPinState->resetBSRR; #else - dbgPin->gpio->BSRRL = dbgPin->resetBSRR; + dbgPinState->gpio->BSRRL = dbgPinState->resetBSRR; #endif } } diff --git a/src/main/build/debug_pin.h b/src/main/build/debug_pin.h index 36fb9663d..1d3c5ba11 100644 --- a/src/main/build/debug_pin.h +++ b/src/main/build/debug_pin.h @@ -20,6 +20,10 @@ #pragma once +typedef struct dbgPin_s { + ioTag_t tag; +} dbgPin_t; + void dbgPinInit(void); void dbgPinHi(int index); void dbgPinLo(int index); -- 2.11.4.GIT