Преглед на файлове

Get STM32 clock rates from framework (#19978)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Jason Smith преди 4 години
родител
ревизия
4a39c8cd53
No account linked to committer's email address
променени са 3 файла, в които са добавени 11 реда и са изтрити 7 реда
  1. 9
    5
      Marlin/src/HAL/STM32/timers.cpp
  2. 2
    1
      Marlin/src/HAL/STM32/timers.h
  3. 0
    1
      Marlin/src/pins/stm32f4/pins_RUMBA32_common.h

+ 9
- 5
Marlin/src/HAL/STM32/timers.cpp Целия файл

@@ -68,26 +68,23 @@
68 68
 #endif
69 69
 
70 70
 #ifdef STM32F0xx
71
-  #define MCU_TIMER_RATE (F_CPU)      // Frequency of timer peripherals
72 71
   #define MCU_STEP_TIMER 16
73 72
   #define MCU_TEMP_TIMER 17
74 73
 #elif defined(STM32F1xx)
75
-  #define MCU_TIMER_RATE (F_CPU)
76 74
   #define MCU_STEP_TIMER  4
77 75
   #define MCU_TEMP_TIMER  2
78 76
 #elif defined(STM32F401xC) || defined(STM32F401xE)
79
-  #define MCU_TIMER_RATE (F_CPU / 2)
80 77
   #define MCU_STEP_TIMER  9
81 78
   #define MCU_TEMP_TIMER 10
82 79
 #elif defined(STM32F4xx) || defined(STM32F7xx)
83
-  #define MCU_TIMER_RATE (F_CPU / 2)
84 80
   #define MCU_STEP_TIMER  6           // STM32F401 has no TIM6, TIM7, or TIM8
85 81
   #define MCU_TEMP_TIMER 14           // TIM7 is consumed by Software Serial if used.
86 82
 #endif
87 83
 
88 84
 #ifndef HAL_TIMER_RATE
89
-  #define HAL_TIMER_RATE MCU_TIMER_RATE
85
+  #define HAL_TIMER_RATE GetStepperTimerClkFreq()
90 86
 #endif
87
+
91 88
 #ifndef STEP_TIMER
92 89
   #define STEP_TIMER MCU_STEP_TIMER
93 90
 #endif
@@ -115,6 +112,13 @@ HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { nullptr };
115 112
 // Public functions
116 113
 // ------------------------
117 114
 
115
+uint32_t GetStepperTimerClkFreq() {
116
+  // Timer input clocks vary between devices, and in some cases between timers on the same device.
117
+  // Retrieve at runtime to ensure device compatibility. Cache result to avoid repeated overhead.
118
+  static uint32_t clkfreq = timer_instance[STEP_TIMER_NUM]->getTimerClkFreq();
119
+  return clkfreq;
120
+}
121
+
118 122
 // frequency is in Hertz
119 123
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
120 124
   if (!HAL_timer_initialized(timer_num)) {

+ 2
- 1
Marlin/src/HAL/STM32/timers.h Целия файл

@@ -57,7 +57,8 @@
57 57
 
58 58
 // TODO: get rid of manual rate/prescale/ticks/cycles taken for procedures in stepper.cpp
59 59
 #define STEPPER_TIMER_RATE 2000000 // 2 Mhz
60
-#define STEPPER_TIMER_PRESCALE ((HAL_TIMER_RATE)/(STEPPER_TIMER_RATE))
60
+extern uint32_t GetStepperTimerClkFreq();
61
+#define STEPPER_TIMER_PRESCALE (GetStepperTimerClkFreq() / (STEPPER_TIMER_RATE))
61 62
 #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
62 63
 
63 64
 #define PULSE_TIMER_RATE STEPPER_TIMER_RATE

+ 0
- 1
Marlin/src/pins/stm32f4/pins_RUMBA32_common.h Целия файл

@@ -47,7 +47,6 @@
47 47
 
48 48
 #define STEP_TIMER 10
49 49
 #define TEMP_TIMER 14
50
-#define HAL_TIMER_RATE                     F_CPU
51 50
 
52 51
 //
53 52
 // Limit Switches

Loading…
Отказ
Запис