From 3e5e4bb5ba9feb02ad20949134d986e1e7c16109 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 28 Mar 2021 13:21:15 -0700 Subject: [PATCH] Use DWT if exposed and present --- src/internal/NeoArmBitBangMethod.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/internal/NeoArmBitBangMethod.h b/src/internal/NeoArmBitBangMethod.h index 0ff0892..6a4ce56 100644 --- a/src/internal/NeoArmBitBangMethod.h +++ b/src/internal/NeoArmBitBangMethod.h @@ -169,23 +169,32 @@ public: protected: static inline uint32_t getCycleCount(void) { +#ifdef DWT + // use the general exposed access object + return DWT->CYCCNT; +#else return *((volatile uint32_t*)0xE0001004); +#endif } static inline void startCycleCount() { - // init DWT feature +#ifndef DWT + // init DWT feature since not exposed for general use (*((volatile uint32_t*)0xE000EDFC)) |= 0x01000000; // init DWT Count to zero *((volatile uint32_t*)0xE0001004) = 0; // start DWT (*(volatile uint32_t*)0xe0001000) |= 0x40000001; +#endif } static inline void stopCycleCount() { - // stop DWT +#ifndef DWT + // stop DWT since not exposed generally (*(volatile uint32_t*)0xe0001000) &= ~0x00000001; +#endif } };