|
@ -65,30 +65,30 @@ typedef uint16_t hal_timer_t; |
|
|
* - Otherwise it uses Timer 8 on boards with STM32_HIGH_DENSITY |
|
|
* - Otherwise it uses Timer 8 on boards with STM32_HIGH_DENSITY |
|
|
* or Timer 4 on other boards. |
|
|
* or Timer 4 on other boards. |
|
|
*/ |
|
|
*/ |
|
|
#ifndef STEP_TIMER_NUM |
|
|
#ifndef MF_TIMER_STEP |
|
|
#if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8) |
|
|
#if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8) |
|
|
#define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4
|
|
|
#define MF_TIMER_STEP 4 // For C8/CB boards, use timer 4
|
|
|
#else |
|
|
#else |
|
|
#define STEP_TIMER_NUM 5 // for other boards, five is fine.
|
|
|
#define MF_TIMER_STEP 5 // for other boards, five is fine.
|
|
|
#endif |
|
|
#endif |
|
|
#endif |
|
|
#endif |
|
|
#ifndef PULSE_TIMER_NUM |
|
|
#ifndef MF_TIMER_PULSE |
|
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM |
|
|
#define MF_TIMER_PULSE MF_TIMER_STEP |
|
|
#endif |
|
|
#endif |
|
|
#ifndef TEMP_TIMER_NUM |
|
|
#ifndef MF_TIMER_TEMP |
|
|
#define TEMP_TIMER_NUM 2 // Timer Index for Temperature
|
|
|
#define MF_TIMER_TEMP 2 // Timer Index for Temperature
|
|
|
//#define TEMP_TIMER_NUM 4 // 2->4, Timer 2 for Stepper Current PWM
|
|
|
//#define MF_TIMER_TEMP 4 // 2->4, Timer 2 for Stepper Current PWM
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#if MB(BTT_SKR_MINI_E3_V1_0, BTT_SKR_E3_DIP, BTT_SKR_MINI_E3_V1_2, MKS_ROBIN_LITE, MKS_ROBIN_E3D, MKS_ROBIN_E3) |
|
|
#if MB(BTT_SKR_MINI_E3_V1_0, BTT_SKR_E3_DIP, BTT_SKR_MINI_E3_V1_2, MKS_ROBIN_LITE, MKS_ROBIN_E3D, MKS_ROBIN_E3) |
|
|
// SKR Mini E3 boards use PA8 as FAN_PIN, so TIMER 1 is used for Fan PWM.
|
|
|
// SKR Mini E3 boards use PA8 as FAN_PIN, so TIMER 1 is used for Fan PWM.
|
|
|
#ifdef STM32_HIGH_DENSITY |
|
|
#ifdef STM32_HIGH_DENSITY |
|
|
#define SERVO0_TIMER_NUM 8 // tone.cpp uses Timer 4
|
|
|
#define MF_TIMER_SERVO0 8 // tone.cpp uses Timer 4
|
|
|
#else |
|
|
#else |
|
|
#define SERVO0_TIMER_NUM 3 // tone.cpp uses Timer 8
|
|
|
#define MF_TIMER_SERVO0 3 // tone.cpp uses Timer 8
|
|
|
#endif |
|
|
#endif |
|
|
#else |
|
|
#else |
|
|
#define SERVO0_TIMER_NUM 1 // SERVO0 or BLTOUCH
|
|
|
#define MF_TIMER_SERVO0 1 // SERVO0 or BLTOUCH
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#define STEP_TIMER_IRQ_PRIO 2 |
|
|
#define STEP_TIMER_IRQ_PRIO 2 |
|
@ -98,22 +98,22 @@ typedef uint16_t hal_timer_t; |
|
|
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
|
|
|
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
|
|
|
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
|
|
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
|
|
|
|
|
|
|
|
#define STEPPER_TIMER_PRESCALE 18 // prescaler for setting stepper timer, 4Mhz
|
|
|
#define STEPPER_TIMER_PRESCALE 18 // prescaler for setting stepper timer, 4Mhz
|
|
|
#define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer
|
|
|
#define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer
|
|
|
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
|
|
|
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
|
|
|
|
|
|
|
|
|
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
|
|
|
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
|
|
|
#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 |
|
|
|
|
|
|
|
|
timer_dev* get_timer_dev(int number); |
|
|
timer_dev* HAL_get_timer_dev(int number); |
|
|
#define TIMER_DEV(num) get_timer_dev(num) |
|
|
#define TIMER_DEV(num) HAL_get_timer_dev(num) |
|
|
#define STEP_TIMER_DEV TIMER_DEV(STEP_TIMER_NUM) |
|
|
#define STEP_TIMER_DEV TIMER_DEV(MF_TIMER_STEP) |
|
|
#define TEMP_TIMER_DEV TIMER_DEV(TEMP_TIMER_NUM) |
|
|
#define TEMP_TIMER_DEV TIMER_DEV(MF_TIMER_TEMP) |
|
|
|
|
|
|
|
|
#define ENABLE_STEPPER_DRIVER_INTERRUPT() timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN) |
|
|
#define ENABLE_STEPPER_DRIVER_INTERRUPT() timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN) |
|
|
#define DISABLE_STEPPER_DRIVER_INTERRUPT() timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN) |
|
|
#define DISABLE_STEPPER_DRIVER_INTERRUPT() timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN) |
|
|
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM) |
|
|
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(MF_TIMER_STEP) |
|
|
|
|
|
|
|
|
#define ENABLE_TEMPERATURE_INTERRUPT() timer_enable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN) |
|
|
#define ENABLE_TEMPERATURE_INTERRUPT() timer_enable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN) |
|
|
#define DISABLE_TEMPERATURE_INTERRUPT() timer_disable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN) |
|
|
#define DISABLE_TEMPERATURE_INTERRUPT() timer_disable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN) |
|
@ -138,8 +138,8 @@ extern "C" { |
|
|
// Public Variables
|
|
|
// Public Variables
|
|
|
// ------------------------
|
|
|
// ------------------------
|
|
|
|
|
|
|
|
|
//static HardwareTimer StepperTimer(STEP_TIMER_NUM);
|
|
|
//static HardwareTimer StepperTimer(MF_TIMER_STEP);
|
|
|
//static HardwareTimer TempTimer(TEMP_TIMER_NUM);
|
|
|
//static HardwareTimer TempTimer(MF_TIMER_TEMP);
|
|
|
|
|
|
|
|
|
// ------------------------
|
|
|
// ------------------------
|
|
|
// Public functions
|
|
|
// Public functions
|
|
@ -163,13 +163,13 @@ bool HAL_timer_interrupt_enabled(const uint8_t timer_num); |
|
|
|
|
|
|
|
|
FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) { |
|
|
FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) { |
|
|
switch (timer_num) { |
|
|
switch (timer_num) { |
|
|
case STEP_TIMER_NUM: |
|
|
case MF_TIMER_STEP: |
|
|
// NOTE: WE have set ARPE = 0, which means the Auto reload register is not preloaded
|
|
|
// NOTE: WE have set ARPE = 0, which means the Auto reload register is not preloaded
|
|
|
// and there is no need to use any compare, as in the timer mode used, setting ARR to the compare value
|
|
|
// and there is no need to use any compare, as in the timer mode used, setting ARR to the compare value
|
|
|
// will result in exactly the same effect, ie triggering an interrupt, and on top, set counter to 0
|
|
|
// will result in exactly the same effect, ie triggering an interrupt, and on top, set counter to 0
|
|
|
timer_set_reload(STEP_TIMER_DEV, compare); // We reload direct ARR as needed during counting up
|
|
|
timer_set_reload(STEP_TIMER_DEV, compare); // We reload direct ARR as needed during counting up
|
|
|
break; |
|
|
break; |
|
|
case TEMP_TIMER_NUM: |
|
|
case MF_TIMER_TEMP: |
|
|
timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, compare); |
|
|
timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, compare); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
@ -177,14 +177,14 @@ FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const ha |
|
|
|
|
|
|
|
|
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) { |
|
|
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) { |
|
|
switch (timer_num) { |
|
|
switch (timer_num) { |
|
|
case STEP_TIMER_NUM: |
|
|
case MF_TIMER_STEP: |
|
|
// No counter to clear
|
|
|
// No counter to clear
|
|
|
timer_generate_update(STEP_TIMER_DEV); |
|
|
timer_generate_update(STEP_TIMER_DEV); |
|
|
return; |
|
|
return; |
|
|
case TEMP_TIMER_NUM: |
|
|
case MF_TIMER_TEMP: |
|
|
timer_set_count(TEMP_TIMER_DEV, 0); |
|
|
timer_set_count(TEMP_TIMER_DEV, 0); |
|
|
timer_generate_update(TEMP_TIMER_DEV); |
|
|
timer_generate_update(TEMP_TIMER_DEV); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -196,6 +196,6 @@ FORCE_INLINE static void timer_no_ARR_preload_ARPE(timer_dev *dev) { |
|
|
bb_peri_set_bit(&(dev->regs).gen->CR1, TIMER_CR1_ARPE_BIT, 0); |
|
|
bb_peri_set_bit(&(dev->regs).gen->CR1, TIMER_CR1_ARPE_BIT, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void timer_set_interrupt_priority(uint_fast8_t timer_num, uint_fast8_t priority); |
|
|
void HAL_timer_set_interrupt_priority(uint_fast8_t timer_num, uint_fast8_t priority); |
|
|
|
|
|
|
|
|
#define TIMER_OC_NO_PRELOAD 0 // Need to disable preload also on compare registers.
|
|
|
#define TIMER_OC_NO_PRELOAD 0 // Need to disable preload also on compare registers.
|
|
|