Allow STM32 pins to specify timers (#17805)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
J.C. Nelson 2020-04-30 20:42:40 -07:00 committed by GitHub
parent 76bc7bf7b8
commit b4aebbe78d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 86 deletions

View file

@ -21,21 +21,61 @@
*/ */
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#include "HAL.h"
#include "timers.h" #include "timers.h"
#include "../../inc/MarlinConfig.h"
// ------------------------ // ------------------------
// Local defines // Local defines
// ------------------------ // ------------------------
#define NUM_HARDWARE_TIMERS 2 #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) TIM##X
#define _TIMER_DEV(X) __TIMER_DEV(X) #define _TIMER_DEV(X) __TIMER_DEV(X)
#define STEP_TIMER_DEV _TIMER_DEV(STEP_TIMER) #define STEP_TIMER_DEV _TIMER_DEV(STEP_TIMER)
#define TEMP_TIMER_DEV _TIMER_DEV(TEMP_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 // Private Variables
// ------------------------ // ------------------------

View file

@ -33,80 +33,6 @@
#define hal_timer_t uint32_t #define hal_timer_t uint32_t
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF // Timers can be 16 or 32 bit #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 STEP_TIMER_NUM 0 // index of timer to use for stepper
#define TEMP_TIMER_NUM 1 // index of timer to use for temperature #define TEMP_TIMER_NUM 1 // index of timer to use for temperature
#define PULSE_TIMER_NUM STEP_TIMER_NUM #define PULSE_TIMER_NUM STEP_TIMER_NUM
@ -122,12 +48,6 @@
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US #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 ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_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) #define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)

View file

@ -43,8 +43,6 @@
// //
// Timers // Timers
// //
#undef STEP_TIMER
#undef TEMP_TIMER
#define STEP_TIMER 6 #define STEP_TIMER 6
#define TEMP_TIMER 7 #define TEMP_TIMER 7

View file

@ -42,8 +42,6 @@
// On STM32F103: // On STM32F103:
// PB3, PB6, PB7, and PB8 can be used with pwm, which rules out TIM2 and TIM4. // 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. // 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 STEP_TIMER 1
#define TEMP_TIMER 3 #define TEMP_TIMER 3