Browse Source

Cortex M3-M7 can use DWT->CYCCNT (#15762)

Suggested by Alex Kenis at https://youtu.be/ZfyPcdhQnAA?t=502
Scott Lahteine 5 years ago
parent
commit
f0d952d33a
No account linked to committer's email address
2 changed files with 6 additions and 5 deletions
  1. 1
    1
      Marlin/src/HAL/HAL_STM32/HAL.cpp
  2. 5
    4
      Marlin/src/HAL/shared/Delay.h

+ 1
- 1
Marlin/src/HAL/HAL_STM32/HAL.cpp View File

@@ -49,7 +49,7 @@ uint16_t HAL_adc_result;
49 49
 // ------------------------
50 50
 
51 51
 // Needed for DELAY_NS() / DELAY_US() on CORTEX-M7
52
-#if (defined(__arm__) || defined(__thumb__)) && __CORTEX_M == 7
52
+#if (defined(__arm__) || defined(__thumb__)) && WITHIN(__CORTEX_M, 3, 7)
53 53
   // HAL pre-initialization task
54 54
   // Force the preinit function to run between the premain() and main() function
55 55
   // of the STM32 arduino core

+ 5
- 4
Marlin/src/HAL/shared/Delay.h View File

@@ -34,16 +34,17 @@
34 34
 
35 35
 #if defined(__arm__) || defined(__thumb__)
36 36
 
37
-  #if __CORTEX_M == 7
37
+  #if WITHIN(__CORTEX_M, 3, 7)
38 38
 
39
-    // Cortex-M7 can use the cycle counter of the DWT unit
39
+    // Cortex-M3 through M7 can use the cycle counter of the DWT unit
40 40
     // http://www.anthonyvh.com/2017/05/18/cortex_m-cycle_counter/
41 41
 
42 42
     FORCE_INLINE static void enableCycleCounter() {
43 43
       CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
44 44
 
45
-      // Unlock DWT.
46
-      DWT->LAR = 0xC5ACCE55;
45
+      #if __CORTEX_M == 7
46
+        DWT->LAR = 0xC5ACCE55; // Unlock DWT on the M7
47
+      #endif
47 48
 
48 49
       DWT->CYCCNT = 0;
49 50
       DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;

Loading…
Cancel
Save