From b4aebbe78d67ec16e63bcc5240aa50c351519012 Mon Sep 17 00:00:00 2001 From: "J.C. Nelson" <32139633+xC0000005@users.noreply.github.com> Date: Thu, 30 Apr 2020 20:42:40 -0700 Subject: [PATCH] Allow STM32 pins to specify timers (#17805) Co-authored-by: Scott Lahteine --- Marlin/src/HAL/STM32/timers.cpp | 44 +++++++++++- Marlin/src/HAL/STM32/timers.h | 80 ---------------------- Marlin/src/pins/stm32f0/pins_MALYAN_M300.h | 2 - Marlin/src/pins/stm32f1/pins_MALYAN_M200.h | 2 - 4 files changed, 42 insertions(+), 86 deletions(-) diff --git a/Marlin/src/HAL/STM32/timers.cpp b/Marlin/src/HAL/STM32/timers.cpp index ad46e34b7..3bbef2c60 100644 --- a/Marlin/src/HAL/STM32/timers.cpp +++ b/Marlin/src/HAL/STM32/timers.cpp @@ -21,21 +21,61 @@ */ #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) -#include "HAL.h" - #include "timers.h" +#include "../../inc/MarlinConfig.h" + // ------------------------ // Local defines // ------------------------ #define NUM_HARDWARE_TIMERS 2 +#ifndef SWSERIAL_TIMER_IRQ_PRIO + #define SWSERIAL_TIMER_IRQ_PRIO 1 +#endif +#ifndef STEP_TIMER_IRQ_PRIO + #define STEP_TIMER_IRQ_PRIO 2 +#endif +#ifndef TEMP_TIMER_IRQ_PRIO + #define TEMP_TIMER_IRQ_PRIO 14 // 14 = after hardware ISRs +#endif + +#ifdef STM32F0xx + #define HAL_TIMER_RATE (F_CPU) // Frequency of timer peripherals + #define MCU_STEP_TIMER 16 + #define MCU_TEMP_TIMER 17 +#elif defined(STM32F1xx) + #define HAL_TIMER_RATE (F_CPU) + #define MCU_STEP_TIMER 4 + #define MCU_TEMP_TIMER 2 +#elif defined(STM32F401xC) || defined(STM32F401xE) + #define HAL_TIMER_RATE (F_CPU / 2) + #define MCU_STEP_TIMER 9 + #define MCU_TEMP_TIMER 10 +#elif defined(STM32F4xx) || defined(STM32F7xx) + #define HAL_TIMER_RATE (F_CPU / 2) + #define MCU_STEP_TIMER 6 // STM32F401 has no TIM6, TIM7, or TIM8 + #define MCU_TEMP_TIMER 14 // TIM7 is consumed by Software Serial if used. +#endif + +#ifndef STEP_TIMER + #define STEP_TIMER MCU_STEP_TIMER +#endif +#ifndef TEMP_TIMER + #define TEMP_TIMER MCU_TEMP_TIMER +#endif + #define __TIMER_DEV(X) TIM##X #define _TIMER_DEV(X) __TIMER_DEV(X) #define STEP_TIMER_DEV _TIMER_DEV(STEP_TIMER) #define TEMP_TIMER_DEV _TIMER_DEV(TEMP_TIMER) +#define __TIMER_IRQ_NAME(X) TIM##X##_IRQn +#define _TIMER_IRQ_NAME(X) __TIMER_IRQ_NAME(X) +#define STEP_TIMER_IRQ_NAME _TIMER_IRQ_NAME(STEP_TIMER) +#define TEMP_TIMER_IRQ_NAME _TIMER_IRQ_NAME(TEMP_TIMER) + // ------------------------ // Private Variables // ------------------------ diff --git a/Marlin/src/HAL/STM32/timers.h b/Marlin/src/HAL/STM32/timers.h index 8a0950a4d..6a04359c2 100644 --- a/Marlin/src/HAL/STM32/timers.h +++ b/Marlin/src/HAL/STM32/timers.h @@ -33,80 +33,6 @@ #define hal_timer_t uint32_t #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF // Timers can be 16 or 32 bit -#ifdef STM32F0xx - - #define HAL_TIMER_RATE (F_CPU) // frequency of timer peripherals - - #ifndef STEP_TIMER - #define STEP_TIMER 16 - #endif - - #ifndef TEMP_TIMER - #define TEMP_TIMER 17 - #endif - -#elif defined(STM32F1xx) - - #define HAL_TIMER_RATE (F_CPU) // frequency of timer peripherals - - #ifndef STEP_TIMER - #define STEP_TIMER 4 - #endif - - #ifndef TEMP_TIMER - #define TEMP_TIMER 2 - #endif - -#elif defined(STM32F401xC) || defined(STM32F401xE) - - #define HAL_TIMER_RATE (F_CPU / 2) // frequency of timer peripherals - - #ifndef STEP_TIMER - #define STEP_TIMER 9 - #endif - - #ifndef TEMP_TIMER - #define TEMP_TIMER 10 - #endif - -#elif defined(STM32F4xx) - - #define HAL_TIMER_RATE (F_CPU / 2) // frequency of timer peripherals - - #ifndef STEP_TIMER - #define STEP_TIMER 6 // STM32F401 has no TIM6, TIM7, or TIM8 - #endif - - #ifndef TEMP_TIMER - #define TEMP_TIMER 14 // TIM7 is consumed by Software Serial if used. - #endif - -#elif defined(STM32F7xx) - - #define HAL_TIMER_RATE (F_CPU / 2) // frequency of timer peripherals - - #ifndef STEP_TIMER - #define STEP_TIMER 6 // the RIGHT timer! - #endif - - #ifndef TEMP_TIMER - #define TEMP_TIMER 14 - #endif - -#endif - -#ifndef SWSERIAL_TIMER_IRQ_PRIO - #define SWSERIAL_TIMER_IRQ_PRIO 1 -#endif - -#ifndef STEP_TIMER_IRQ_PRIO - #define STEP_TIMER_IRQ_PRIO 2 -#endif - -#ifndef TEMP_TIMER_IRQ_PRIO - #define TEMP_TIMER_IRQ_PRIO 14 // 14 = after hardware ISRs -#endif - #define STEP_TIMER_NUM 0 // index of timer to use for stepper #define TEMP_TIMER_NUM 1 // index of timer to use for temperature #define PULSE_TIMER_NUM STEP_TIMER_NUM @@ -122,12 +48,6 @@ #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE #define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US -#define __TIMER_IRQ_NAME(X) TIM##X##_IRQn -#define _TIMER_IRQ_NAME(X) __TIMER_IRQ_NAME(X) - -#define STEP_TIMER_IRQ_NAME _TIMER_IRQ_NAME(STEP_TIMER) -#define TEMP_TIMER_IRQ_NAME _TIMER_IRQ_NAME(TEMP_TIMER) - #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM) #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM) #define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM) diff --git a/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h b/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h index 129a3175b..88604496d 100644 --- a/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h +++ b/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h @@ -43,8 +43,6 @@ // // Timers // -#undef STEP_TIMER -#undef TEMP_TIMER #define STEP_TIMER 6 #define TEMP_TIMER 7 diff --git a/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h b/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h index 00dd2e118..87f323dfa 100644 --- a/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h +++ b/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h @@ -42,8 +42,6 @@ // On STM32F103: // PB3, PB6, PB7, and PB8 can be used with pwm, which rules out TIM2 and TIM4. // On STM32F070, 16 and 17 are in use, but 1 and 3 are available. -#undef STEP_TIMER -#undef TEMP_TIMER #define STEP_TIMER 1 #define TEMP_TIMER 3