Browse Source

Official STMicroelectronics Arduino Core STM32F4 HAL compatibility (#11006)

Karl Andersson 7 years ago
parent
commit
e0276d2f32

+ 8
- 9
Marlin/src/HAL/HAL_STM32F1/HAL_spi_Stm32f1.cpp View File

54
 // --------------------------------------------------------------------------
54
 // --------------------------------------------------------------------------
55
 
55
 
56
 #if ENABLED(SOFTWARE_SPI)
56
 #if ENABLED(SOFTWARE_SPI)
57
+
57
   // --------------------------------------------------------------------------
58
   // --------------------------------------------------------------------------
58
   // Software SPI
59
   // Software SPI
59
   // --------------------------------------------------------------------------
60
   // --------------------------------------------------------------------------
95
 void spiInit(uint8_t spiRate) {
96
 void spiInit(uint8_t spiRate) {
96
   uint8_t  clock;
97
   uint8_t  clock;
97
   switch (spiRate) {
98
   switch (spiRate) {
98
-  case SPI_FULL_SPEED:    clock = SPI_CLOCK_DIV2 ; break;
99
-  case SPI_HALF_SPEED:    clock = SPI_CLOCK_DIV4 ; break;
100
-  case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break;
101
-  case SPI_EIGHTH_SPEED:  clock = SPI_CLOCK_DIV16; break;
102
-  case SPI_SPEED_5:       clock = SPI_CLOCK_DIV32; break;
103
-  case SPI_SPEED_6:       clock = SPI_CLOCK_DIV64; break;
104
-  default:
105
-    clock = SPI_CLOCK_DIV2; // Default from the SPI library
99
+    case SPI_FULL_SPEED:    clock = SPI_CLOCK_DIV2 ; break;
100
+    case SPI_HALF_SPEED:    clock = SPI_CLOCK_DIV4 ; break;
101
+    case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break;
102
+    case SPI_EIGHTH_SPEED:  clock = SPI_CLOCK_DIV16; break;
103
+    case SPI_SPEED_5:       clock = SPI_CLOCK_DIV32; break;
104
+    case SPI_SPEED_6:       clock = SPI_CLOCK_DIV64; break;
105
+    default:                clock = SPI_CLOCK_DIV2; // Default from the SPI library
106
   }
106
   }
107
   spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
107
   spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
108
   SPI.begin();
108
   SPI.begin();
168
 /** Begin SPI transaction, set clock, bit order, data mode */
168
 /** Begin SPI transaction, set clock, bit order, data mode */
169
 void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
169
 void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
170
   spiConfig = SPISettings(spiClock, (BitOrder)bitOrder, dataMode);
170
   spiConfig = SPISettings(spiClock, (BitOrder)bitOrder, dataMode);
171
-
172
   SPI.beginTransaction(spiConfig);
171
   SPI.beginTransaction(spiConfig);
173
 }
172
 }
174
 
173
 

+ 2
- 2
Marlin/src/HAL/HAL_STM32F4/EEPROM_Emul/eeprom_emul.cpp View File

47
 /** @addtogroup EEPROM_Emulation
47
 /** @addtogroup EEPROM_Emulation
48
   * @{
48
   * @{
49
   */
49
   */
50
-#ifdef STM32F4
50
+#if defined(STM32F4) || defined(STM32F4xx)
51
 
51
 
52
 /* Includes ------------------------------------------------------------------*/
52
 /* Includes ------------------------------------------------------------------*/
53
 #include "eeprom_emul.h"
53
 #include "eeprom_emul.h"
562
   return FlashStatus;
562
   return FlashStatus;
563
 }
563
 }
564
 
564
 
565
-#endif // STM32F4
565
+#endif // STM32F4 || STM32F4xx
566
 
566
 
567
 /**
567
 /**
568
  * @}
568
  * @}

+ 2
- 2
Marlin/src/HAL/HAL_STM32F4/EmulatedEeprom.cpp View File

17
  *
17
  *
18
  */
18
  */
19
 
19
 
20
-#ifdef STM32F4
20
+#if defined(STM32F4) || defined(STM32F4xx)
21
 
21
 
22
 /**
22
 /**
23
  * Description: functions for I2C connected external EEPROM.
23
  * Description: functions for I2C connected external EEPROM.
139
 }
139
 }
140
 
140
 
141
 #endif // ENABLED(EEPROM_SETTINGS) && DISABLED(I2C_EEPROM) && DISABLED(SPI_EEPROM)
141
 #endif // ENABLED(EEPROM_SETTINGS) && DISABLED(I2C_EEPROM) && DISABLED(SPI_EEPROM)
142
-#endif // STM32F4
142
+#endif // STM32F4 || STM32F4xx
143
 
143
 

+ 6
- 13
Marlin/src/HAL/HAL_STM32F4/HAL.cpp View File

21
  *
21
  *
22
  */
22
  */
23
 
23
 
24
-
25
-#ifdef STM32F4
24
+#if defined(STM32F4) || defined(STM32F4xx)
26
 
25
 
27
 // --------------------------------------------------------------------------
26
 // --------------------------------------------------------------------------
28
 // Includes
27
 // Includes
81
 void HAL_clear_reset_source(void) { __HAL_RCC_CLEAR_RESET_FLAGS(); }
80
 void HAL_clear_reset_source(void) { __HAL_RCC_CLEAR_RESET_FLAGS(); }
82
 
81
 
83
 uint8_t HAL_get_reset_source (void) {
82
 uint8_t HAL_get_reset_source (void) {
84
-  if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET)
85
-    return RST_WATCHDOG;
86
-
87
-  if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET)
88
-    return RST_SOFTWARE;
89
-
90
-  if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET)
91
-    return RST_EXTERNAL;
83
+  if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET) return RST_WATCHDOG;
92
 
84
 
93
-  if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET)
94
-    return RST_POWER_ON;
85
+  if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET)  return RST_SOFTWARE;
86
+  if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET)  return RST_EXTERNAL;
87
+  if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET)  return RST_POWER_ON;
95
   return 0;
88
   return 0;
96
 }
89
 }
97
 
90
 
137
   return HAL_adc_result;
130
   return HAL_adc_result;
138
 }
131
 }
139
 
132
 
140
-#endif // STM32F4
133
+#endif // STM32F4 || STM32F4xx

+ 6
- 3
Marlin/src/HAL/HAL_STM32F4/HAL.h View File

21
  *
21
  *
22
  */
22
  */
23
 
23
 
24
-
25
-
26
 #ifndef _HAL_STM32F4_H
24
 #ifndef _HAL_STM32F4_H
27
 #define _HAL_STM32F4_H
25
 #define _HAL_STM32F4_H
28
 
26
 
41
 
39
 
42
 #include "Arduino.h"
40
 #include "Arduino.h"
43
 
41
 
42
+#ifdef USBCON
43
+  #include <USBSerial.h>
44
+#endif
45
+
44
 #include "../math_32bit.h"
46
 #include "../math_32bit.h"
45
 #include "../HAL_SPI.h"
47
 #include "../HAL_SPI.h"
46
 #include "fastio_STM32F4.h"
48
 #include "fastio_STM32F4.h"
48
 
50
 
49
 #include "HAL_timers_STM32F4.h"
51
 #include "HAL_timers_STM32F4.h"
50
 
52
 
51
-
52
 // --------------------------------------------------------------------------
53
 // --------------------------------------------------------------------------
53
 // Defines
54
 // Defines
54
 // --------------------------------------------------------------------------
55
 // --------------------------------------------------------------------------
186
 */
187
 */
187
 
188
 
188
 extern "C" char* _sbrk(int incr);
189
 extern "C" char* _sbrk(int incr);
190
+
189
 /*
191
 /*
190
 static int freeMemory() {
192
 static int freeMemory() {
191
   volatile int top;
193
   volatile int top;
193
   return top;
195
   return top;
194
 }
196
 }
195
 */
197
 */
198
+
196
 static int freeMemory() {
199
 static int freeMemory() {
197
   volatile char top;
200
   volatile char top;
198
   return &top - reinterpret_cast<char*>(_sbrk(0));
201
   return &top - reinterpret_cast<char*>(_sbrk(0));

+ 2
- 2
Marlin/src/HAL/HAL_STM32F4/HAL_Servo_STM32F4.cpp View File

21
  *
21
  *
22
  */
22
  */
23
 
23
 
24
-#ifdef STM32F4
24
+#if defined(STM32F4) || defined(STM32F4xx)
25
 
25
 
26
 #include "../../inc/MarlinConfig.h"
26
 #include "../../inc/MarlinConfig.h"
27
 
27
 
50
 }
50
 }
51
 #endif // HAS_SERVOS
51
 #endif // HAS_SERVOS
52
 
52
 
53
-#endif // STM32F4
53
+#endif // STM32F4 || STM32F4xx

+ 25
- 14
Marlin/src/HAL/HAL_STM32F4/HAL_spi_STM32F4.cpp View File

30
  * Adapted to the STM32F4 HAL
30
  * Adapted to the STM32F4 HAL
31
  */
31
  */
32
 
32
 
33
-#ifdef STM32F4
33
+#if defined(STM32F4) || defined(STM32F4xx)
34
 
34
 
35
 // --------------------------------------------------------------------------
35
 // --------------------------------------------------------------------------
36
 // Includes
36
 // Includes
54
 // --------------------------------------------------------------------------
54
 // --------------------------------------------------------------------------
55
 
55
 
56
 #if ENABLED(SOFTWARE_SPI)
56
 #if ENABLED(SOFTWARE_SPI)
57
+
57
   // --------------------------------------------------------------------------
58
   // --------------------------------------------------------------------------
58
   // Software SPI
59
   // Software SPI
59
   // --------------------------------------------------------------------------
60
   // --------------------------------------------------------------------------
81
     #error SS_PIN not defined!
82
     #error SS_PIN not defined!
82
   #endif
83
   #endif
83
 
84
 
84
-  SET_OUTPUT(SS_PIN);
85
-  WRITE(SS_PIN, HIGH);
85
+  OUT_WRITE(SS_PIN, HIGH);
86
 }
86
 }
87
 
87
 
88
 /** Configure SPI for specified SPI speed */
88
 /** Configure SPI for specified SPI speed */
90
   // Use datarates Marlin uses
90
   // Use datarates Marlin uses
91
   uint32_t clock;
91
   uint32_t clock;
92
   switch (spiRate) {
92
   switch (spiRate) {
93
-  case SPI_FULL_SPEED:    clock = 20000000; break; // 13.9mhz=20000000  6.75mhz=10000000  3.38mhz=5000000  .833mhz=1000000
94
-  case SPI_HALF_SPEED:    clock =  5000000; break;
95
-  case SPI_QUARTER_SPEED: clock =  2500000; break;
96
-  case SPI_EIGHTH_SPEED:  clock =  1250000; break;
97
-  case SPI_SPEED_5:       clock =   625000; break;
98
-  case SPI_SPEED_6:       clock =   300000; break;
99
-  default:
100
-    clock = 4000000; // Default from the SPI libarary
93
+    case SPI_FULL_SPEED:    clock = 20000000; break; // 13.9mhz=20000000  6.75mhz=10000000  3.38mhz=5000000  .833mhz=1000000
94
+    case SPI_HALF_SPEED:    clock =  5000000; break;
95
+    case SPI_QUARTER_SPEED: clock =  2500000; break;
96
+    case SPI_EIGHTH_SPEED:  clock =  1250000; break;
97
+    case SPI_SPEED_5:       clock =   625000; break;
98
+    case SPI_SPEED_6:       clock =   300000; break;
99
+    default:                clock =  4000000; // Default from the SPI libarary
101
   }
100
   }
102
   spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
101
   spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
103
   SPI.begin();
102
   SPI.begin();
128
  */
127
  */
129
 void spiRead(uint8_t* buf, uint16_t nbyte) {
128
 void spiRead(uint8_t* buf, uint16_t nbyte) {
130
   SPI.beginTransaction(spiConfig);
129
   SPI.beginTransaction(spiConfig);
131
-  SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte);
130
+
131
+  #ifdef STM32GENERIC
132
+    SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte);
133
+  #else
134
+    SPI.transfer((uint8_t*)buf, nbyte);
135
+  #endif
136
+
132
   SPI.endTransaction();
137
   SPI.endTransaction();
133
 }
138
 }
134
 
139
 
156
 void spiSendBlock(uint8_t token, const uint8_t* buf) {
161
 void spiSendBlock(uint8_t token, const uint8_t* buf) {
157
   SPI.beginTransaction(spiConfig);
162
   SPI.beginTransaction(spiConfig);
158
   SPI.transfer(token);
163
   SPI.transfer(token);
159
-  SPI.dmaSend(const_cast<uint8_t*>(buf), 512);
164
+
165
+  #ifdef STM32GENERIC
166
+    SPI.dmaSend(const_cast<uint8_t*>(buf), 512);
167
+  #else
168
+    SPI.transfer((uint8_t*)buf, (uint8_t*)0, 512);
169
+  #endif
170
+
160
   SPI.endTransaction();
171
   SPI.endTransaction();
161
 }
172
 }
162
 
173
 
163
 #endif // SOFTWARE_SPI
174
 #endif // SOFTWARE_SPI
164
 
175
 
165
-#endif // STM32F4
176
+#endif // STM32F4 || STM32F4xx

+ 65
- 67
Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.cpp View File

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-#ifdef STM32F4
23
+#if defined(STM32F4) || defined(STM32F4xx)
24
 
24
 
25
 // --------------------------------------------------------------------------
25
 // --------------------------------------------------------------------------
26
 // Includes
26
 // Includes
39
 // --------------------------------------------------------------------------
39
 // --------------------------------------------------------------------------
40
 
40
 
41
 #define NUM_HARDWARE_TIMERS 2
41
 #define NUM_HARDWARE_TIMERS 2
42
+#define STEP_TIMER_IRQ_ID TIM5_IRQn
43
+#define TEMP_TIMER_IRQ_ID TIM7_IRQn
42
 
44
 
43
 //#define PRESCALER 1
45
 //#define PRESCALER 1
44
 // --------------------------------------------------------------------------
46
 // --------------------------------------------------------------------------
53
 // Private Variables
55
 // Private Variables
54
 // --------------------------------------------------------------------------
56
 // --------------------------------------------------------------------------
55
 
57
 
56
-tTimerConfig timerConfig[NUM_HARDWARE_TIMERS];
58
+stm32f4_timer_t TimerHandle[NUM_HARDWARE_TIMERS];
57
 
59
 
58
 // --------------------------------------------------------------------------
60
 // --------------------------------------------------------------------------
59
 // Function prototypes
61
 // Function prototypes
72
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
74
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
73
 
75
 
74
   if (!timers_initialised[timer_num]) {
76
   if (!timers_initialised[timer_num]) {
77
+    constexpr uint32_t step_prescaler = STEPPER_TIMER_PRESCALE - 1,
78
+                       temp_prescaler = TEMP_TIMER_PRESCALE - 1;
75
     switch (timer_num) {
79
     switch (timer_num) {
76
-    case STEP_TIMER_NUM:
77
-      //STEPPER TIMER TIM5 //use a 32bit timer
78
-      __HAL_RCC_TIM5_CLK_ENABLE();
79
-      timerConfig[0].timerdef.Instance            = TIM5;
80
-      timerConfig[0].timerdef.Init.Prescaler      = (STEPPER_TIMER_PRESCALE);
81
-      timerConfig[0].timerdef.Init.CounterMode    = TIM_COUNTERMODE_UP;
82
-      timerConfig[0].timerdef.Init.ClockDivision  = TIM_CLOCKDIVISION_DIV1;
83
-      timerConfig[0].IRQ_Id = TIM5_IRQn;
84
-      timerConfig[0].callback = (uint32_t)TC5_Handler;
85
-      HAL_NVIC_SetPriority(timerConfig[0].IRQ_Id, 1, 0);
86
-      break;
87
-    case TEMP_TIMER_NUM:
88
-      //TEMP TIMER TIM7 // any available 16bit Timer (1 already used for PWM)
89
-      __HAL_RCC_TIM7_CLK_ENABLE();
90
-      timerConfig[1].timerdef.Instance            = TIM7;
91
-      timerConfig[1].timerdef.Init.Prescaler      = (TEMP_TIMER_PRESCALE);
92
-      timerConfig[1].timerdef.Init.CounterMode    = TIM_COUNTERMODE_UP;
93
-      timerConfig[1].timerdef.Init.ClockDivision  = TIM_CLOCKDIVISION_DIV1;
94
-      timerConfig[1].IRQ_Id = TIM7_IRQn;
95
-      timerConfig[1].callback = (uint32_t)TC7_Handler;
96
-      HAL_NVIC_SetPriority(timerConfig[1].IRQ_Id, 2, 0);
97
-      break;
80
+      case STEP_TIMER_NUM:
81
+        // STEPPER TIMER TIM5 - use a 32bit timer
82
+        #ifdef STM32GENERIC
83
+          __HAL_RCC_TIM5_CLK_ENABLE();
84
+          TimerHandle[timer_num].handle.Instance            = TIM5;
85
+          TimerHandle[timer_num].handle.Init.Prescaler      = step_prescaler;
86
+          TimerHandle[timer_num].handle.Init.CounterMode    = TIM_COUNTERMODE_UP;
87
+          TimerHandle[timer_num].handle.Init.ClockDivision  = TIM_CLOCKDIVISION_DIV1;
88
+          TimerHandle[timer_num].callback = (uint32_t)TC5_Handler;
89
+        #else
90
+          TimerHandle[timer_num].timer = TIM5;
91
+          TimerHandle[timer_num].irqHandle = TC5_Handler;
92
+          TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / step_prescaler) / frequency) - 1, step_prescaler);
93
+        #endif
94
+        HAL_NVIC_SetPriority(STEP_TIMER_IRQ_ID, 6, 0);
95
+        break;
96
+
97
+      case TEMP_TIMER_NUM:
98
+        // TEMP TIMER TIM7 - any available 16bit Timer (1 already used for PWM)
99
+        #ifdef STM32GENERIC
100
+          __HAL_RCC_TIM7_CLK_ENABLE();
101
+          TimerHandle[timer_num].handle.Instance            = TIM7;
102
+          TimerHandle[timer_num].handle.Init.Prescaler      = temp_prescaler;
103
+          TimerHandle[timer_num].handle.Init.CounterMode    = TIM_COUNTERMODE_UP;
104
+          TimerHandle[timer_num].handle.Init.ClockDivision  = TIM_CLOCKDIVISION_DIV1;
105
+          TimerHandle[timer_num].callback = (uint32_t)TC7_Handler;
106
+        #else
107
+          TimerHandle[timer_num].timer = TIM7;
108
+          TimerHandle[timer_num].irqHandle = TC7_Handler;
109
+          TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / temp_prescaler) / frequency) - 1, temp_prescaler);
110
+        #endif
111
+        HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_ID, 2, 0);
112
+        break;
98
     }
113
     }
99
     timers_initialised[timer_num] = true;
114
     timers_initialised[timer_num] = true;
100
   }
115
   }
101
 
116
 
102
-  timerConfig[timer_num].timerdef.Init.Period = (((HAL_TIMER_RATE) / timerConfig[timer_num].timerdef.Init.Prescaler) / frequency) - 1;
103
-
104
-  if (HAL_TIM_Base_Init(&timerConfig[timer_num].timerdef) == HAL_OK)
105
-    HAL_TIM_Base_Start_IT(&timerConfig[timer_num].timerdef);
117
+  #ifdef STM32GENERIC
118
+    TimerHandle[timer_num].handle.Init.Period = (((HAL_TIMER_RATE) / TimerHandle[timer_num].handle.Init.Prescaler) / frequency) - 1;
119
+    if (HAL_TIM_Base_Init(&TimerHandle[timer_num].handle) == HAL_OK)
120
+      HAL_TIM_Base_Start_IT(&TimerHandle[timer_num].handle);
121
+  #endif
106
 }
122
 }
107
 
123
 
108
-//forward the interrupt
109
-extern "C" void TIM5_IRQHandler() {
110
-  ((void(*)(void))timerConfig[0].callback)();
111
-}
112
-extern "C" void TIM7_IRQHandler() {
113
-  ((void(*)(void))timerConfig[1].callback)();
114
-}
115
-
116
-void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
117
-  __HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, compare);
118
-}
124
+#ifdef STM32GENERIC
125
+  extern "C" void TIM5_IRQHandler() {
126
+    ((void(*)(void))TimerHandle[0].callback)();
127
+  }
128
+  extern "C" void TIM7_IRQHandler() {
129
+    ((void(*)(void))TimerHandle[1].callback)();
130
+  }
131
+#endif
119
 
132
 
120
 void HAL_timer_enable_interrupt(const uint8_t timer_num) {
133
 void HAL_timer_enable_interrupt(const uint8_t timer_num) {
121
-  HAL_NVIC_EnableIRQ(timerConfig[timer_num].IRQ_Id);
134
+  switch (timer_num) {
135
+    case STEP_TIMER_NUM: HAL_NVIC_EnableIRQ(STEP_TIMER_IRQ_ID); break;
136
+    case TEMP_TIMER_NUM: HAL_NVIC_EnableIRQ(TEMP_TIMER_IRQ_ID); break;
137
+  }
122
 }
138
 }
123
 
139
 
124
 void HAL_timer_disable_interrupt(const uint8_t timer_num) {
140
 void HAL_timer_disable_interrupt(const uint8_t timer_num) {
125
-  HAL_NVIC_DisableIRQ(timerConfig[timer_num].IRQ_Id);
126
-
141
+  switch (timer_num) {
142
+    case STEP_TIMER_NUM: HAL_NVIC_DisableIRQ(STEP_TIMER_IRQ_ID); break;
143
+    case TEMP_TIMER_NUM: HAL_NVIC_DisableIRQ(TEMP_TIMER_IRQ_ID); break;
144
+  }
127
   // We NEED memory barriers to ensure Interrupts are actually disabled!
145
   // We NEED memory barriers to ensure Interrupts are actually disabled!
128
   // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
146
   // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
129
   __DSB();
147
   __DSB();
130
   __ISB();
148
   __ISB();
131
 }
149
 }
132
 
150
 
133
-hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
134
-  return __HAL_TIM_GetAutoreload(&timerConfig[timer_num].timerdef);
135
-}
136
-
137
-uint32_t HAL_timer_get_count(const uint8_t timer_num) {
138
-  return __HAL_TIM_GetCounter(&timerConfig[timer_num].timerdef);
139
-}
140
-
141
-void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
142
-  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
143
-  if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
144
-}
145
-
146
-void HAL_timer_isr_prologue(const uint8_t timer_num) {
147
-  if (__HAL_TIM_GET_FLAG(&timerConfig[timer_num].timerdef, TIM_FLAG_UPDATE) == SET) {
148
-    __HAL_TIM_CLEAR_FLAG(&timerConfig[timer_num].timerdef, TIM_FLAG_UPDATE);
149
-  }
150
-}
151
-
152
 bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
151
 bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
153
-  if (NVIC->ISER[(uint32_t)((int32_t)timerConfig[timer_num].IRQ_Id) >> 5] & (uint32_t)(1 << ((uint32_t)((int32_t)timerConfig[timer_num].IRQ_Id) & (uint32_t)0x1F))) {
154
-    return true;
155
-  }
156
-  else {
157
-    return false;
152
+  switch (timer_num) {
153
+    case STEP_TIMER_NUM: return NVIC->ISER[(uint32_t)((int32_t)STEP_TIMER_IRQ_ID) >> 5] & (uint32_t)(1 << ((uint32_t)((int32_t)STEP_TIMER_IRQ_ID) & (uint32_t)0x1F));
154
+    case TEMP_TIMER_NUM: return NVIC->ISER[(uint32_t)((int32_t)TEMP_TIMER_IRQ_ID) >> 5] & (uint32_t)(1 << ((uint32_t)((int32_t)TEMP_TIMER_IRQ_ID) & (uint32_t)0x1F));
158
   }
155
   }
156
+  return false;
159
 }
157
 }
160
 
158
 
161
-#endif // STM32F4
159
+#endif // STM32F4 || STM32F4xx

+ 49
- 15
Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.h View File

63
 
63
 
64
 // TODO change this
64
 // TODO change this
65
 
65
 
66
+#ifdef STM32GENERIC
67
+  extern void TC5_Handler();
68
+  extern void TC7_Handler();
69
+  #define HAL_STEP_TIMER_ISR void TC5_Handler()
70
+  #define HAL_TEMP_TIMER_ISR void TC7_Handler()
71
+#else
72
+  extern void TC5_Handler(stimer_t *htim);
73
+  extern void TC7_Handler(stimer_t *htim);
74
+  #define HAL_STEP_TIMER_ISR void TC5_Handler(stimer_t *htim)
75
+  #define HAL_TEMP_TIMER_ISR void TC7_Handler(stimer_t *htim)
76
+#endif
66
 
77
 
67
-extern void TC5_Handler();
68
-extern void TC7_Handler();
69
-#define HAL_STEP_TIMER_ISR  void TC5_Handler()
70
-#define HAL_TEMP_TIMER_ISR  void TC7_Handler()
71
 
78
 
72
 // --------------------------------------------------------------------------
79
 // --------------------------------------------------------------------------
73
 // Types
80
 // Types
74
 // --------------------------------------------------------------------------
81
 // --------------------------------------------------------------------------
75
 
82
 
76
-typedef struct {
77
-  TIM_HandleTypeDef timerdef;
78
-  IRQn_Type   IRQ_Id;
79
-  uint32_t callback;
80
-} tTimerConfig;
83
+#ifdef STM32GENERIC
84
+  typedef struct {
85
+    TIM_HandleTypeDef handle;
86
+    uint32_t callback;
87
+  } tTimerConfig;
88
+  typedef tTimerConfig stm32f4_timer_t;
89
+#else
90
+  typedef stimer_t stm32f4_timer_t;
91
+#endif
81
 
92
 
82
 // --------------------------------------------------------------------------
93
 // --------------------------------------------------------------------------
83
 // Public Variables
94
 // Public Variables
84
 // --------------------------------------------------------------------------
95
 // --------------------------------------------------------------------------
85
 
96
 
86
-//extern const tTimerConfig timerConfig[];
97
+extern stm32f4_timer_t TimerHandle[];
87
 
98
 
88
 // --------------------------------------------------------------------------
99
 // --------------------------------------------------------------------------
89
 // Public functions
100
 // Public functions
94
 void HAL_timer_disable_interrupt(const uint8_t timer_num);
105
 void HAL_timer_disable_interrupt(const uint8_t timer_num);
95
 bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
106
 bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
96
 
107
 
97
-void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare);
98
-hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
99
-uint32_t HAL_timer_get_count(const uint8_t timer_num);
100
-void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks);
108
+FORCE_INLINE static uint32_t HAL_timer_get_count(const uint8_t timer_num) {
109
+  return __HAL_TIM_GET_COUNTER(&TimerHandle[timer_num].handle);
110
+}
111
+
112
+FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
113
+  __HAL_TIM_SET_AUTORELOAD(&TimerHandle[timer_num].handle, compare);
114
+  if (HAL_timer_get_count(timer_num) >= compare)
115
+    TimerHandle[timer_num].handle.Instance->EGR |= TIM_EGR_UG; // Generate an immediate update interrupt
116
+}
117
+
118
+FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
119
+  return __HAL_TIM_GET_AUTORELOAD(&TimerHandle[timer_num].handle);
120
+}
121
+
122
+FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
123
+  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
124
+  if (HAL_timer_get_compare(timer_num) < mincmp)
125
+    HAL_timer_set_compare(timer_num, mincmp);
126
+}
127
+
128
+#ifdef STM32GENERIC
129
+  FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
130
+    if (__HAL_TIM_GET_FLAG(&TimerHandle[timer_num].handle, TIM_FLAG_UPDATE) == SET)
131
+      __HAL_TIM_CLEAR_FLAG(&TimerHandle[timer_num].handle, TIM_FLAG_UPDATE);
132
+  }
133
+#else
134
+  #define HAL_timer_isr_prologue(TIMER_NUM)
135
+#endif
101
 
136
 
102
-void HAL_timer_isr_prologue(const uint8_t timer_num);
103
 #define HAL_timer_isr_epilogue(TIMER_NUM)
137
 #define HAL_timer_isr_epilogue(TIMER_NUM)
104
 
138
 
105
 #endif // _HAL_TIMERS_STM32F4_H
139
 #endif // _HAL_TIMERS_STM32F4_H

+ 2
- 2
Marlin/src/HAL/HAL_STM32F4/persistent_store_impl.cpp View File

21
  *
21
  *
22
  */
22
  */
23
 
23
 
24
-#ifdef STM32F4
24
+#if defined(STM32F4) || defined(STM32F4xx)
25
 
25
 
26
 #include "../persistent_store_api.h"
26
 #include "../persistent_store_api.h"
27
 
27
 
72
 } // HAL
72
 } // HAL
73
 
73
 
74
 #endif // EEPROM_SETTINGS
74
 #endif // EEPROM_SETTINGS
75
-#endif // STM32F4
75
+#endif // STM32F4 || STM32F4xx

+ 2
- 2
Marlin/src/HAL/HAL_STM32F4/watchdog_STM32F4.cpp View File

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-#ifdef STM32F4
23
+#if defined(STM32F4) || defined(STM32F4xx)
24
 
24
 
25
 #include "../../inc/MarlinConfig.h"
25
 #include "../../inc/MarlinConfig.h"
26
 
26
 
54
 
54
 
55
 #endif // USE_WATCHDOG
55
 #endif // USE_WATCHDOG
56
 
56
 
57
-#endif // STM32F4
57
+#endif // STM32F4 || STM32F4xx

+ 1
- 1
Marlin/src/HAL/backtrace/unwmemaccess.cpp View File

62
 #define END_FLASH_ADDR    0x00080000
62
 #define END_FLASH_ADDR    0x00080000
63
 #endif
63
 #endif
64
 
64
 
65
-#ifdef STM32F4
65
+#if defined(STM32F4) || defined(STM32F4xx)
66
 // For STM32F407VET
66
 // For STM32F407VET
67
 //  SRAM  (0x20000000 - 0x20030000) (192kb)
67
 //  SRAM  (0x20000000 - 0x20030000) (192kb)
68
 //  FLASH (0x08000000 - 0x08080000) (512kb)
68
 //  FLASH (0x08000000 - 0x08080000) (512kb)

+ 1
- 1
Marlin/src/HAL/platforms.h View File

13
   #define HAL_PLATFORM HAL_LPC1768
13
   #define HAL_PLATFORM HAL_LPC1768
14
 #elif defined(__STM32F1__) || defined(TARGET_STM32F1)
14
 #elif defined(__STM32F1__) || defined(TARGET_STM32F1)
15
   #define HAL_PLATFORM HAL_STM32F1
15
   #define HAL_PLATFORM HAL_STM32F1
16
-#elif defined(STM32F4)
16
+#elif defined(STM32F4) || defined(STM32F4xx)
17
   #define HAL_PLATFORM HAL_STM32F4
17
   #define HAL_PLATFORM HAL_STM32F4
18
 #elif defined(STM32F7)
18
 #elif defined(STM32F7)
19
   #define HAL_PLATFORM HAL_STM32F7
19
   #define HAL_PLATFORM HAL_STM32F7

+ 1
- 1
Marlin/src/HAL/servo.cpp View File

53
 
53
 
54
 #include "../inc/MarlinConfig.h"
54
 #include "../inc/MarlinConfig.h"
55
 
55
 
56
-#if HAS_SERVOS && !(IS_32BIT_TEENSY || defined(TARGET_LPC1768) || defined(STM32F4))
56
+#if HAS_SERVOS && !(IS_32BIT_TEENSY || defined(TARGET_LPC1768) || defined(STM32F4) || defined(STM32F4xx))
57
 
57
 
58
 //#include <Arduino.h>
58
 //#include <Arduino.h>
59
 #include "servo.h"
59
 #include "servo.h"

+ 1
- 1
Marlin/src/HAL/servo.h View File

74
 
74
 
75
 #elif defined(TARGET_LPC1768)
75
 #elif defined(TARGET_LPC1768)
76
   #include "HAL_LPC1768/LPC1768_Servo.h"
76
   #include "HAL_LPC1768/LPC1768_Servo.h"
77
-#elif defined(STM32F4)
77
+#elif defined(STM32F4) || defined(STM32F4xx)
78
   #include "HAL_STM32F4/HAL_Servo_STM32F4.h"
78
   #include "HAL_STM32F4/HAL_Servo_STM32F4.h"
79
 #else
79
 #else
80
   #include <stdint.h>
80
   #include <stdint.h>

+ 1
- 1
Marlin/src/gcode/calibrate/G28.cpp View File

181
     #endif
181
     #endif
182
     return;
182
     return;
183
   }
183
   }
184
-  
184
+
185
   // Wait for planner moves to finish!
185
   // Wait for planner moves to finish!
186
   planner.synchronize();
186
   planner.synchronize();
187
 
187
 

+ 1
- 1
Marlin/src/pins/pins_STM32F4.h View File

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-#if !defined(STM32F4)
23
+#if !defined(STM32F4) && !defined(STM32F4xx)
24
   #error "Oops!  Make sure you have an STM32F4 board selected from the 'Tools -> Boards' menu."
24
   #error "Oops!  Make sure you have an STM32F4 board selected from the 'Tools -> Boards' menu."
25
 #endif
25
 #endif
26
 
26
 

+ 1
- 1
platformio.ini View File

265
 platform      = ststm32
265
 platform      = ststm32
266
 framework     = arduino
266
 framework     = arduino
267
 board         = disco_f407vg
267
 board         = disco_f407vg
268
-build_flags   = ${common.build_flags} -DUSE_STM32GENERIC -DMENU_USB_SERIAL -DMENU_SERIAL=SerialUSB
268
+build_flags   = ${common.build_flags} -DUSE_STM32GENERIC -DSTM32GENERIC -DMENU_USB_SERIAL -DMENU_SERIAL=SerialUSB
269
 lib_deps      = ${common.lib_deps}
269
 lib_deps      = ${common.lib_deps}
270
 lib_ignore    = Adafruit NeoPixel, c1921b4, TMC2130Stepper
270
 lib_ignore    = Adafruit NeoPixel, c1921b4, TMC2130Stepper
271
 src_filter    = ${common.default_src_filter}
271
 src_filter    = ${common.default_src_filter}

Loading…
Cancel
Save