diff --git a/Marlin/src/HAL/HAL_STM32/HAL.cpp b/Marlin/src/HAL/HAL_STM32/HAL.cpp index 6776530004..1bddf77f48 100644 --- a/Marlin/src/HAL/HAL_STM32/HAL.cpp +++ b/Marlin/src/HAL/HAL_STM32/HAL.cpp @@ -78,14 +78,20 @@ uint16_t HAL_adc_result; // Public functions // -------------------------------------------------------------------------- + +// Needed for DELAY_NS() / DELAY_US() on CORTEX-M7 +#if (defined(__arm__) || defined(__thumb__)) && __CORTEX_M == 7 + // HAL pre-initialization task + // Force the preinit function to run between the premain() and main() function + // of the STM32 arduino core + __attribute__((constructor (102))) + void HAL_preinit() { + enableCycleCounter(); + } +#endif + // HAL initialization task void HAL_init(void) { - - // Needed for DELAY_NS() / DELAY_US() on CORTEX-M7 - #if (defined(__arm__) || defined(__thumb__)) && __CORTEX_M == 7 - enableCycleCounter(); - #endif - FastIO_init(); #if ENABLED(SDSUPPORT)