Browse Source

Fix access to the DWT peripheral for STM32 HAL (#12434)

Access to the DWT peripheral for the `CYCCNT` register needs to happen before `main()`. The code needs to be called after the setup of the system clocks, so the right place is between the `premain()` and `main()` function of the STM32 Arduino core.

This patch moves the DWT access code to a new function, which is then placed between `premain()` and `main()`.
Nils Hasenbanck 6 years ago
parent
commit
5a4fd8e0a6
1 changed files with 11 additions and 5 deletions
  1. 11
    5
      Marlin/src/HAL/HAL_STM32/HAL.cpp

+ 11
- 5
Marlin/src/HAL/HAL_STM32/HAL.cpp View File

78
 // Public functions
78
 // Public functions
79
 // --------------------------------------------------------------------------
79
 // --------------------------------------------------------------------------
80
 
80
 
81
-// HAL initialization task
82
-void HAL_init(void) {
83
 
81
 
84
-  // Needed for DELAY_NS() / DELAY_US() on CORTEX-M7
85
-  #if (defined(__arm__) || defined(__thumb__)) && __CORTEX_M == 7
82
+// Needed for DELAY_NS() / DELAY_US() on CORTEX-M7
83
+#if (defined(__arm__) || defined(__thumb__)) && __CORTEX_M == 7
84
+  // HAL pre-initialization task
85
+  // Force the preinit function to run between the premain() and main() function
86
+  // of the STM32 arduino core
87
+  __attribute__((constructor (102)))
88
+  void HAL_preinit() {
86
     enableCycleCounter();
89
     enableCycleCounter();
87
-  #endif
90
+  }
91
+#endif
88
 
92
 
93
+// HAL initialization task
94
+void HAL_init(void) {
89
   FastIO_init();
95
   FastIO_init();
90
 
96
 
91
   #if ENABLED(SDSUPPORT)
97
   #if ENABLED(SDSUPPORT)

Loading…
Cancel
Save