소스 검색

Cleanups for STM32F7

Scott Lahteine 7 년 전
부모
커밋
42933c804a

+ 1
- 1
Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.h 파일 보기

@@ -109,7 +109,7 @@
109 109
   #define analogInputToDigitalPin(p) (p)
110 110
 #endif
111 111
 
112
-#define CRITICAL_SECTION_START	noInterrupts();
112
+#define CRITICAL_SECTION_START  noInterrupts();
113 113
 #define CRITICAL_SECTION_END    interrupts();
114 114
 
115 115
 // On AVR this is in math.h?

+ 4
- 4
Marlin/src/HAL/HAL_STM32F1/fastio_Stm32f1.h 파일 보기

@@ -26,8 +26,8 @@
26 26
  * These use GPIO functions instead of Direct Port Manipulation, as on AVR.
27 27
  */
28 28
 
29
-#ifndef	_FASTIO_STM32F1_H
30
-#define	_FASTIO_STM32F1_H
29
+#ifndef _FASTIO_STM32F1_H
30
+#define _FASTIO_STM32F1_H
31 31
 
32 32
 #include <libmaple/gpio.h>
33 33
 
@@ -49,9 +49,9 @@
49 49
 #define GET_TIMER(IO)         (PIN_MAP[IO].timer_device != NULL)
50 50
 
51 51
 #define OUT_WRITE(IO, v)      { _SET_OUTPUT(IO); WRITE(IO, v); }
52
-/*
52
+/**
53 53
  * TODO: Write a macro to test if PIN is PWM or not.
54 54
  */
55 55
 #define PWM_PIN(p)            true
56 56
 
57
-#endif	/* _FASTIO_STM32F1_H */
57
+#endif // _FASTIO_STM32F1_H

+ 147
- 318
Marlin/src/HAL/HAL_STM32F7/EEPROM_Emul/eeprom_emul.cpp 파일 보기

@@ -78,8 +78,7 @@ static uint16_t EE_VerifyPageFullyErased(uint32_t Address);
78 78
   * @retval - Flash error code: on write Flash error
79 79
   *         - FLASH_COMPLETE: on success
80 80
   */
81
-uint16_t EE_Initialise(void)
82
-{
81
+uint16_t EE_Initialise(void) {
83 82
   uint16_t PageStatus0 = 6, PageStatus1 = 6;
84 83
   uint16_t VarIdx = 0;
85 84
   uint16_t EepromStatus = 0, ReadStatus = 0;
@@ -100,209 +99,141 @@ uint16_t EE_Initialise(void)
100 99
   pEraseInit.VoltageRange = VOLTAGE_RANGE;
101 100
 
102 101
   /* Check for invalid header states and repair if necessary */
103
-  switch (PageStatus0)
104
-  {
102
+  switch (PageStatus0) {
105 103
     case ERASED:
106
-      if (PageStatus1 == VALID_PAGE) /* Page0 erased, Page1 valid */
107
-      {
104
+      if (PageStatus1 == VALID_PAGE) { /* Page0 erased, Page1 valid */
108 105
           /* Erase Page0 */
109
-        if(!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS))
110
-        {
106
+        if(!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS)) {
111 107
           FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
112 108
           /* If erase operation was failed, a Flash error code is returned */
113
-          if (FlashStatus != HAL_OK)
114
-          {
109
+          if (FlashStatus != HAL_OK) {
115 110
             return FlashStatus;
116 111
           }
117 112
         }
118 113
       }
119
-      else if (PageStatus1 == RECEIVE_DATA) /* Page0 erased, Page1 receive */
120
-      {
114
+      else if (PageStatus1 == RECEIVE_DATA) { /* Page0 erased, Page1 receive */
121 115
         /* Erase Page0 */
122
-        if(!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS))
123
-        {
116
+        if (!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS)) {
124 117
           FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
125 118
           /* If erase operation was failed, a Flash error code is returned */
126
-          if (FlashStatus != HAL_OK)
127
-          {
128
-            return FlashStatus;
129
-          }
119
+          if (FlashStatus != HAL_OK) return FlashStatus;
130 120
         }
131 121
         /* Mark Page1 as valid */
132 122
         FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE1_BASE_ADDRESS, VALID_PAGE);
133 123
         /* If program operation was failed, a Flash error code is returned */
134
-        if (FlashStatus != HAL_OK)
135
-        {
136
-          return FlashStatus;
137
-        }
124
+        if (FlashStatus != HAL_OK) return FlashStatus;
138 125
       }
139
-      else /* First EEPROM access (Page0&1 are erased) or invalid state -> format EEPROM */
140
-      {
126
+      else { /* First EEPROM access (Page0&1 are erased) or invalid state -> format EEPROM */
141 127
         /* Erase both Page0 and Page1 and set Page0 as valid page */
142 128
         FlashStatus = EE_Format();
143 129
         /* If erase/program operation was failed, a Flash error code is returned */
144
-        if (FlashStatus != HAL_OK)
145
-        {
146
-          return FlashStatus;
147
-        }
130
+        if (FlashStatus != HAL_OK) return FlashStatus;
148 131
       }
149 132
       break;
150 133
 
151 134
     case RECEIVE_DATA:
152
-      if (PageStatus1 == VALID_PAGE) /* Page0 receive, Page1 valid */
153
-      {
135
+      if (PageStatus1 == VALID_PAGE) { /* Page0 receive, Page1 valid */
154 136
         /* Transfer data from Page1 to Page0 */
155
-        for (VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++)
156
-        {
137
+        for (VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++) {
157 138
           if (( *(__IO uint16_t*)(PAGE0_BASE_ADDRESS + 6)) == VirtAddVarTab[VarIdx])
158
-          {
159 139
             x = VarIdx;
160
-          }
161
-          if (VarIdx != x)
162
-          {
140
+          if (VarIdx != x) {
163 141
             /* Read the last variables' updates */
164 142
             ReadStatus = EE_ReadVariable(VirtAddVarTab[VarIdx], &DataVar);
165 143
             /* In case variable corresponding to the virtual address was found */
166
-            if (ReadStatus != 0x1)
167
-            {
144
+            if (ReadStatus != 0x1) {
168 145
               /* Transfer the variable to the Page0 */
169 146
               EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddVarTab[VarIdx], DataVar);
170 147
               /* If program operation was failed, a Flash error code is returned */
171
-              if (EepromStatus != HAL_OK)
172
-              {
173
-                return EepromStatus;
174
-              }
148
+              if (EepromStatus != HAL_OK) return EepromStatus;
175 149
             }
176 150
           }
177 151
         }
178 152
         /* Mark Page0 as valid */
179 153
         FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE0_BASE_ADDRESS, VALID_PAGE);
180 154
         /* If program operation was failed, a Flash error code is returned */
181
-        if (FlashStatus != HAL_OK)
182
-        {
183
-          return FlashStatus;
184
-        }
155
+        if (FlashStatus != HAL_OK) return FlashStatus;
185 156
         pEraseInit.Sector = PAGE1_ID;
186 157
         pEraseInit.NbSectors = 1;
187 158
         pEraseInit.VoltageRange = VOLTAGE_RANGE;
188 159
         /* Erase Page1 */
189
-        if(!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS))
190
-        {
160
+        if (!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS)) {
191 161
           FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
192 162
           /* If erase operation was failed, a Flash error code is returned */
193
-          if (FlashStatus != HAL_OK)
194
-          {
195
-            return FlashStatus;
196
-          }
163
+          if (FlashStatus != HAL_OK) return FlashStatus;
197 164
         }
198 165
       }
199
-      else if (PageStatus1 == ERASED) /* Page0 receive, Page1 erased */
200
-      {
166
+      else if (PageStatus1 == ERASED) { /* Page0 receive, Page1 erased */
201 167
         pEraseInit.Sector = PAGE1_ID;
202 168
         pEraseInit.NbSectors = 1;
203 169
         pEraseInit.VoltageRange = VOLTAGE_RANGE;
204 170
         /* Erase Page1 */
205
-        if(!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS))
206
-        {
171
+        if (!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS)) {
207 172
           FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
208 173
           /* If erase operation was failed, a Flash error code is returned */
209
-          if (FlashStatus != HAL_OK)
210
-          {
211
-            return FlashStatus;
212
-          }
174
+          if (FlashStatus != HAL_OK) return FlashStatus;
213 175
         }
214 176
         /* Mark Page0 as valid */
215 177
         FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE0_BASE_ADDRESS, VALID_PAGE);
216 178
         /* If program operation was failed, a Flash error code is returned */
217
-        if (FlashStatus != HAL_OK)
218
-        {
219
-          return FlashStatus;
220
-        }
179
+        if (FlashStatus != HAL_OK) return FlashStatus;
221 180
       }
222
-      else /* Invalid state -> format eeprom */
223
-      {
181
+      else { /* Invalid state -> format eeprom */
224 182
         /* Erase both Page0 and Page1 and set Page0 as valid page */
225 183
         FlashStatus = EE_Format();
226 184
         /* If erase/program operation was failed, a Flash error code is returned */
227
-        if (FlashStatus != HAL_OK)
228
-        {
229
-          return FlashStatus;
230
-        }
185
+        if (FlashStatus != HAL_OK) return FlashStatus;
231 186
       }
232 187
       break;
233 188
 
234 189
     case VALID_PAGE:
235
-      if (PageStatus1 == VALID_PAGE) /* Invalid state -> format eeprom */
236
-      {
190
+      if (PageStatus1 == VALID_PAGE) { /* Invalid state -> format eeprom */
237 191
         /* Erase both Page0 and Page1 and set Page0 as valid page */
238 192
         FlashStatus = EE_Format();
239 193
         /* If erase/program operation was failed, a Flash error code is returned */
240
-        if (FlashStatus != HAL_OK)
241
-        {
242
-          return FlashStatus;
243
-        }
194
+        if (FlashStatus != HAL_OK) return FlashStatus;
244 195
       }
245
-      else if (PageStatus1 == ERASED) /* Page0 valid, Page1 erased */
246
-      {
196
+      else if (PageStatus1 == ERASED) { /* Page0 valid, Page1 erased */
247 197
         pEraseInit.Sector = PAGE1_ID;
248 198
         pEraseInit.NbSectors = 1;
249 199
         pEraseInit.VoltageRange = VOLTAGE_RANGE;
250 200
         /* Erase Page1 */
251
-        if(!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS))
252
-        {
201
+        if (!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS)) {
253 202
           FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
254 203
           /* If erase operation was failed, a Flash error code is returned */
255
-          if (FlashStatus != HAL_OK)
256
-          {
257
-            return FlashStatus;
258
-          }
204
+          if (FlashStatus != HAL_OK) return FlashStatus;
259 205
         }
260 206
       }
261
-      else /* Page0 valid, Page1 receive */
262
-      {
207
+      else { /* Page0 valid, Page1 receive */
263 208
         /* Transfer data from Page0 to Page1 */
264
-        for (VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++)
265
-        {
209
+        for (VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++) {
266 210
           if ((*(__IO uint16_t*)(PAGE1_BASE_ADDRESS + 6)) == VirtAddVarTab[VarIdx])
267
-          {
268 211
             x = VarIdx;
269
-          }
270
-          if (VarIdx != x)
271
-          {
212
+
213
+          if (VarIdx != x) {
272 214
             /* Read the last variables' updates */
273 215
             ReadStatus = EE_ReadVariable(VirtAddVarTab[VarIdx], &DataVar);
274 216
             /* In case variable corresponding to the virtual address was found */
275
-            if (ReadStatus != 0x1)
276
-            {
217
+            if (ReadStatus != 0x1) {
277 218
               /* Transfer the variable to the Page1 */
278 219
               EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddVarTab[VarIdx], DataVar);
279 220
               /* If program operation was failed, a Flash error code is returned */
280
-              if (EepromStatus != HAL_OK)
281
-              {
282
-                return EepromStatus;
283
-              }
221
+              if (EepromStatus != HAL_OK) return EepromStatus;
284 222
             }
285 223
           }
286 224
         }
287 225
         /* Mark Page1 as valid */
288 226
         FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE1_BASE_ADDRESS, VALID_PAGE);
289 227
         /* If program operation was failed, a Flash error code is returned */
290
-        if (FlashStatus != HAL_OK)
291
-        {
292
-          return FlashStatus;
293
-        }
228
+        if (FlashStatus != HAL_OK) return FlashStatus;
294 229
         pEraseInit.Sector = PAGE0_ID;
295 230
         pEraseInit.NbSectors = 1;
296 231
         pEraseInit.VoltageRange = VOLTAGE_RANGE;
297 232
         /* Erase Page0 */
298
-        if(!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS))
299
-        {
233
+        if (!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS)) {
300 234
           FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
301 235
           /* If erase operation was failed, a Flash error code is returned */
302
-          if (FlashStatus != HAL_OK)
303
-          {
304
-            return FlashStatus;
305
-          }
236
+          if (FlashStatus != HAL_OK) return FlashStatus;
306 237
         }
307 238
       }
308 239
       break;
@@ -311,10 +242,7 @@ uint16_t EE_Initialise(void)
311 242
       /* Erase both Page0 and Page1 and set Page0 as valid page */
312 243
       FlashStatus = EE_Format();
313 244
       /* If erase/program operation was failed, a Flash error code is returned */
314
-      if (FlashStatus != HAL_OK)
315
-      {
316
-        return FlashStatus;
317
-      }
245
+      if (FlashStatus != HAL_OK) return FlashStatus;
318 246
       break;
319 247
   }
320 248
 
@@ -322,55 +250,46 @@ uint16_t EE_Initialise(void)
322 250
 }
323 251
 
324 252
 /**
325
-  * @brief  Verify if specified page is fully erased.
326
-  * @param  Address: page address
327
-  *   This parameter can be one of the following values:
328
-  *     @arg PAGE0_BASE_ADDRESS: Page0 base address
329
-  *     @arg PAGE1_BASE_ADDRESS: Page1 base address
330
-  * @retval page fully erased status:
331
-  *           - 0: if Page not erased
332
-  *           - 1: if Page erased
333
-  */
334
-uint16_t EE_VerifyPageFullyErased(uint32_t Address)
335
-{
253
+ * @brief  Verify if specified page is fully erased.
254
+ * @param  Address: page address
255
+ *   This parameter can be one of the following values:
256
+ *     @arg PAGE0_BASE_ADDRESS: Page0 base address
257
+ *     @arg PAGE1_BASE_ADDRESS: Page1 base address
258
+ * @retval page fully erased status:
259
+ *           - 0: if Page not erased
260
+ *           - 1: if Page erased
261
+ */
262
+uint16_t EE_VerifyPageFullyErased(uint32_t Address) {
336 263
   uint32_t ReadStatus = 1;
337 264
   uint16_t AddressValue = 0x5555;
338
-
339 265
   /* Check each active page address starting from end */
340
-  while (Address <= PAGE0_END_ADDRESS)
341
-  {
266
+  while (Address <= PAGE0_END_ADDRESS) {
342 267
     /* Get the current location content to be compared with virtual address */
343 268
     AddressValue = (*(__IO uint16_t*)Address);
344
-
345 269
     /* Compare the read address with the virtual address */
346
-    if (AddressValue != ERASED)
347
-    {
348
-
270
+    if (AddressValue != ERASED) {
349 271
       /* In case variable value is read, reset ReadStatus flag */
350 272
       ReadStatus = 0;
351
-
352 273
       break;
353 274
     }
354 275
     /* Next address location */
355
-    Address = Address + 4;
276
+    Address += 4;
356 277
   }
357
-
358 278
   /* Return ReadStatus value: (0: Page not erased, 1: Sector erased) */
359 279
   return ReadStatus;
360 280
 }
361 281
 
362 282
 /**
363
-  * @brief  Returns the last stored variable data, if found, which correspond to
364
-  *   the passed virtual address
365
-  * @param  VirtAddress: Variable virtual address
366
-  * @param  Data: Global variable contains the read variable value
367
-  * @retval Success or error status:
368
-  *           - 0: if variable was found
369
-  *           - 1: if the variable was not found
370
-  *           - NO_VALID_PAGE: if no valid page was found.
371
-  */
372
-uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data)
373
-{
283
+ * @brief  Returns the last stored variable data, if found, which correspond to
284
+ *   the passed virtual address
285
+ * @param  VirtAddress: Variable virtual address
286
+ * @param  Data: Global variable contains the read variable value
287
+ * @retval Success or error status:
288
+ *           - 0: if variable was found
289
+ *           - 1: if the variable was not found
290
+ *           - NO_VALID_PAGE: if no valid page was found.
291
+ */
292
+uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data) {
374 293
   uint16_t ValidPage = PAGE0;
375 294
   uint16_t AddressValue = 0x5555, ReadStatus = 1;
376 295
   uint32_t Address = EEPROM_START_ADDRESS, PageStartAddress = EEPROM_START_ADDRESS;
@@ -379,10 +298,7 @@ uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data)
379 298
   ValidPage = EE_FindValidPage(READ_FROM_VALID_PAGE);
380 299
 
381 300
   /* Check if there is no valid page */
382
-  if (ValidPage == NO_VALID_PAGE)
383
-  {
384
-    return  NO_VALID_PAGE;
385
-  }
301
+  if (ValidPage == NO_VALID_PAGE) return NO_VALID_PAGE;
386 302
 
387 303
   /* Get the valid Page start Address */
388 304
   PageStartAddress = (uint32_t)(EEPROM_START_ADDRESS + (uint32_t)(ValidPage * PAGE_SIZE));
@@ -391,69 +307,54 @@ uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data)
391 307
   Address = (uint32_t)((EEPROM_START_ADDRESS - 2) + (uint32_t)((1 + ValidPage) * PAGE_SIZE));
392 308
 
393 309
   /* Check each active page address starting from end */
394
-  while (Address > (PageStartAddress + 2))
395
-  {
310
+  while (Address > (PageStartAddress + 2)) {
396 311
     /* Get the current location content to be compared with virtual address */
397 312
     AddressValue = (*(__IO uint16_t*)Address);
398 313
 
399 314
     /* Compare the read address with the virtual address */
400
-    if (AddressValue == VirtAddress)
401
-    {
315
+    if (AddressValue == VirtAddress) {
402 316
       /* Get content of Address-2 which is variable value */
403 317
       *Data = (*(__IO uint16_t*)(Address - 2));
404
-
405 318
       /* In case variable value is read, reset ReadStatus flag */
406 319
       ReadStatus = 0;
407
-
408 320
       break;
409 321
     }
410
-    else
411
-    {
412
-      /* Next address location */
413
-      Address = Address - 4;
414
-    }
322
+    else /* Next address location */
323
+      Address -= 4;
415 324
   }
416
-
417 325
   /* Return ReadStatus value: (0: variable exist, 1: variable doesn't exist) */
418 326
   return ReadStatus;
419 327
 }
420 328
 
421 329
 /**
422
-  * @brief  Writes/upadtes variable data in EEPROM.
423
-  * @param  VirtAddress: Variable virtual address
424
-  * @param  Data: 16 bit data to be written
425
-  * @retval Success or error status:
426
-  *           - FLASH_COMPLETE: on success
427
-  *           - PAGE_FULL: if valid page is full
428
-  *           - NO_VALID_PAGE: if no valid page was found
429
-  *           - Flash error code: on write Flash error
430
-  */
431
-uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data)
432
-{
433
-  uint16_t Status = 0;
434
-
330
+ * @brief  Writes/upadtes variable data in EEPROM.
331
+ * @param  VirtAddress: Variable virtual address
332
+ * @param  Data: 16 bit data to be written
333
+ * @retval Success or error status:
334
+ *           - FLASH_COMPLETE: on success
335
+ *           - PAGE_FULL: if valid page is full
336
+ *           - NO_VALID_PAGE: if no valid page was found
337
+ *           - Flash error code: on write Flash error
338
+ */
339
+uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data) {
435 340
   /* Write the variable virtual address and value in the EEPROM */
436
-  Status = EE_VerifyPageFullWriteVariable(VirtAddress, Data);
341
+  uint16_t Status = EE_VerifyPageFullWriteVariable(VirtAddress, Data);
437 342
 
438 343
   /* In case the EEPROM active page is full */
439
-  if (Status == PAGE_FULL)
440
-  {
441
-    /* Perform Page transfer */
344
+  if (Status == PAGE_FULL) /* Perform Page transfer */
442 345
     Status = EE_PageTransfer(VirtAddress, Data);
443
-  }
444 346
 
445 347
   /* Return last operation status */
446 348
   return Status;
447 349
 }
448 350
 
449 351
 /**
450
-  * @brief  Erases PAGE and PAGE1 and writes VALID_PAGE header to PAGE
451
-  * @param  None
452
-  * @retval Status of the last operation (Flash write or erase) done during
453
-  *         EEPROM formating
454
-  */
455
-static HAL_StatusTypeDef EE_Format(void)
456
-{
352
+ * @brief  Erases PAGE and PAGE1 and writes VALID_PAGE header to PAGE
353
+ * @param  None
354
+ * @retval Status of the last operation (Flash write or erase) done during
355
+ *         EEPROM formating
356
+ */
357
+static HAL_StatusTypeDef EE_Format(void) {
457 358
   HAL_StatusTypeDef FlashStatus = HAL_OK;
458 359
   uint32_t SectorError = 0;
459 360
   FLASH_EraseInitTypeDef pEraseInit;
@@ -463,49 +364,37 @@ static HAL_StatusTypeDef EE_Format(void)
463 364
   pEraseInit.NbSectors = 1;
464 365
   pEraseInit.VoltageRange = VOLTAGE_RANGE;
465 366
   /* Erase Page0 */
466
-  if(!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS))
467
-  {
367
+  if (!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS)) {
468 368
     FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
469 369
     /* If erase operation was failed, a Flash error code is returned */
470
-    if (FlashStatus != HAL_OK)
471
-    {
472
-      return FlashStatus;
473
-    }
370
+    if (FlashStatus != HAL_OK) return FlashStatus;
474 371
   }
475 372
   /* Set Page0 as valid page: Write VALID_PAGE at Page0 base address */
476 373
   FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, PAGE0_BASE_ADDRESS, VALID_PAGE);
477 374
   /* If program operation was failed, a Flash error code is returned */
478
-  if (FlashStatus != HAL_OK)
479
-  {
480
-    return FlashStatus;
481
-  }
375
+  if (FlashStatus != HAL_OK) return FlashStatus;
482 376
 
483 377
   pEraseInit.Sector = PAGE1_ID;
484 378
   /* Erase Page1 */
485
-  if(!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS))
486
-  {
379
+  if (!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS)) {
487 380
     FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
488 381
     /* If erase operation was failed, a Flash error code is returned */
489
-    if (FlashStatus != HAL_OK)
490
-    {
491
-      return FlashStatus;
492
-    }
382
+    if (FlashStatus != HAL_OK) return FlashStatus;
493 383
   }
494 384
 
495 385
   return HAL_OK;
496 386
 }
497 387
 
498 388
 /**
499
-  * @brief  Find valid Page for write or read operation
500
-  * @param  Operation: operation to achieve on the valid page.
501
-  *   This parameter can be one of the following values:
502
-  *     @arg READ_FROM_VALID_PAGE: read operation from valid page
503
-  *     @arg WRITE_IN_VALID_PAGE: write operation from valid page
504
-  * @retval Valid page number (PAGE or PAGE1) or NO_VALID_PAGE in case
505
-  *   of no valid page was found
506
-  */
507
-static uint16_t EE_FindValidPage(uint8_t Operation)
508
-{
389
+ * @brief  Find valid Page for write or read operation
390
+ * @param  Operation: operation to achieve on the valid page.
391
+ *   This parameter can be one of the following values:
392
+ *     @arg READ_FROM_VALID_PAGE: read operation from valid page
393
+ *     @arg WRITE_IN_VALID_PAGE: write operation from valid page
394
+ * @retval Valid page number (PAGE or PAGE1) or NO_VALID_PAGE in case
395
+ *   of no valid page was found
396
+ */
397
+static uint16_t EE_FindValidPage(uint8_t Operation) {
509 398
   uint16_t PageStatus0 = 6, PageStatus1 = 6;
510 399
 
511 400
   /* Get Page0 actual status */
@@ -515,51 +404,28 @@ static uint16_t EE_FindValidPage(uint8_t Operation)
515 404
   PageStatus1 = (*(__IO uint16_t*)PAGE1_BASE_ADDRESS);
516 405
 
517 406
   /* Write or read operation */
518
-  switch (Operation)
519
-  {
407
+  switch (Operation) {
520 408
     case WRITE_IN_VALID_PAGE:   /* ---- Write operation ---- */
521
-      if (PageStatus1 == VALID_PAGE)
522
-      {
409
+      if (PageStatus1 == VALID_PAGE) {
523 410
         /* Page0 receiving data */
524
-        if (PageStatus0 == RECEIVE_DATA)
525
-        {
526
-          return PAGE0;         /* Page0 valid */
527
-        }
528
-        else
529
-        {
530
-          return PAGE1;         /* Page1 valid */
531
-        }
411
+        if (PageStatus0 == RECEIVE_DATA) return PAGE0;         /* Page0 valid */
412
+        else                             return PAGE1;         /* Page1 valid */
532 413
       }
533
-      else if (PageStatus0 == VALID_PAGE)
534
-      {
414
+      else if (PageStatus0 == VALID_PAGE) {
535 415
         /* Page1 receiving data */
536
-        if (PageStatus1 == RECEIVE_DATA)
537
-        {
538
-          return PAGE1;         /* Page1 valid */
539
-        }
540
-        else
541
-        {
542
-          return PAGE0;         /* Page0 valid */
543
-        }
416
+        if (PageStatus1 == RECEIVE_DATA) return PAGE1;         /* Page1 valid */
417
+        else                             return PAGE0;         /* Page0 valid */
544 418
       }
545 419
       else
546
-      {
547 420
         return NO_VALID_PAGE;   /* No valid Page */
548
-      }
549 421
 
550 422
     case READ_FROM_VALID_PAGE:  /* ---- Read operation ---- */
551 423
       if (PageStatus0 == VALID_PAGE)
552
-      {
553 424
         return PAGE0;           /* Page0 valid */
554
-      }
555 425
       else if (PageStatus1 == VALID_PAGE)
556
-      {
557 426
         return PAGE1;           /* Page1 valid */
558
-      }
559 427
       else
560
-      {
561
-        return NO_VALID_PAGE ;  /* No valid Page */
562
-      }
428
+        return NO_VALID_PAGE;   /* No valid Page */
563 429
 
564 430
     default:
565 431
       return PAGE0;             /* Page0 valid */
@@ -567,17 +433,16 @@ static uint16_t EE_FindValidPage(uint8_t Operation)
567 433
 }
568 434
 
569 435
 /**
570
-  * @brief  Verify if active page is full and Writes variable in EEPROM.
571
-  * @param  VirtAddress: 16 bit virtual address of the variable
572
-  * @param  Data: 16 bit data to be written as variable value
573
-  * @retval Success or error status:
574
-  *           - FLASH_COMPLETE: on success
575
-  *           - PAGE_FULL: if valid page is full
576
-  *           - NO_VALID_PAGE: if no valid page was found
577
-  *           - Flash error code: on write Flash error
578
-  */
579
-static uint16_t EE_VerifyPageFullWriteVariable(uint16_t VirtAddress, uint16_t Data)
580
-{
436
+ * @brief  Verify if active page is full and Writes variable in EEPROM.
437
+ * @param  VirtAddress: 16 bit virtual address of the variable
438
+ * @param  Data: 16 bit data to be written as variable value
439
+ * @retval Success or error status:
440
+ *           - FLASH_COMPLETE: on success
441
+ *           - PAGE_FULL: if valid page is full
442
+ *           - NO_VALID_PAGE: if no valid page was found
443
+ *           - Flash error code: on write Flash error
444
+ */
445
+static uint16_t EE_VerifyPageFullWriteVariable(uint16_t VirtAddress, uint16_t Data) {
581 446
   HAL_StatusTypeDef FlashStatus = HAL_OK;
582 447
   uint16_t ValidPage = PAGE0;
583 448
   uint32_t Address = EEPROM_START_ADDRESS, PageEndAddress = EEPROM_START_ADDRESS+PAGE_SIZE;
@@ -586,10 +451,7 @@ static uint16_t EE_VerifyPageFullWriteVariable(uint16_t VirtAddress, uint16_t Da
586 451
   ValidPage = EE_FindValidPage(WRITE_IN_VALID_PAGE);
587 452
 
588 453
   /* Check if there is no valid page */
589
-  if (ValidPage == NO_VALID_PAGE)
590
-  {
591
-    return  NO_VALID_PAGE;
592
-  }
454
+  if (ValidPage == NO_VALID_PAGE) return NO_VALID_PAGE;
593 455
 
594 456
   /* Get the valid Page start Address */
595 457
   Address = (uint32_t)(EEPROM_START_ADDRESS + (uint32_t)(ValidPage * PAGE_SIZE));
@@ -598,28 +460,20 @@ static uint16_t EE_VerifyPageFullWriteVariable(uint16_t VirtAddress, uint16_t Da
598 460
   PageEndAddress = (uint32_t)((EEPROM_START_ADDRESS - 1) + (uint32_t)((ValidPage + 1) * PAGE_SIZE));
599 461
 
600 462
   /* Check each active page address starting from begining */
601
-  while (Address < PageEndAddress)
602
-  {
463
+  while (Address < PageEndAddress) {
603 464
     /* Verify if Address and Address+2 contents are 0xFFFFFFFF */
604
-    if ((*(__IO uint32_t*)Address) == 0xFFFFFFFF)
605
-    {
465
+    if ((*(__IO uint32_t*)Address) == 0xFFFFFFFF) {
606 466
       /* Set variable data */
607 467
       FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, Address, Data);
608 468
       /* If program operation was failed, a Flash error code is returned */
609
-      if (FlashStatus != HAL_OK)
610
-      {
611
-        return FlashStatus;
612
-      }
469
+      if (FlashStatus != HAL_OK) return FlashStatus;
613 470
       /* Set variable virtual address */
614 471
       FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, Address + 2, VirtAddress);
615 472
       /* Return program operation status */
616 473
       return FlashStatus;
617 474
     }
618
-    else
619
-    {
620
-      /* Next address location */
621
-      Address = Address + 4;
622
-    }
475
+    else /* Next address location */
476
+      Address += 4;
623 477
   }
624 478
 
625 479
   /* Return PAGE_FULL in case the valid page is full */
@@ -627,18 +481,17 @@ static uint16_t EE_VerifyPageFullWriteVariable(uint16_t VirtAddress, uint16_t Da
627 481
 }
628 482
 
629 483
 /**
630
-  * @brief  Transfers last updated variables data from the full Page to
631
-  *   an empty one.
632
-  * @param  VirtAddress: 16 bit virtual address of the variable
633
-  * @param  Data: 16 bit data to be written as variable value
634
-  * @retval Success or error status:
635
-  *           - FLASH_COMPLETE: on success
636
-  *           - PAGE_FULL: if valid page is full
637
-  *           - NO_VALID_PAGE: if no valid page was found
638
-  *           - Flash error code: on write Flash error
639
-  */
640
-static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data)
641
-{
484
+ * @brief  Transfers last updated variables data from the full Page to
485
+ *   an empty one.
486
+ * @param  VirtAddress: 16 bit virtual address of the variable
487
+ * @param  Data: 16 bit data to be written as variable value
488
+ * @retval Success or error status:
489
+ *           - FLASH_COMPLETE: on success
490
+ *           - PAGE_FULL: if valid page is full
491
+ *           - NO_VALID_PAGE: if no valid page was found
492
+ *           - Flash error code: on write Flash error
493
+ */
494
+static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data) {
642 495
   HAL_StatusTypeDef FlashStatus = HAL_OK;
643 496
   uint32_t NewPageAddress = EEPROM_START_ADDRESS;
644 497
   uint16_t OldPageId=0;
@@ -650,60 +503,42 @@ static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data)
650 503
   /* Get active Page for read operation */
651 504
   ValidPage = EE_FindValidPage(READ_FROM_VALID_PAGE);
652 505
 
653
-  if (ValidPage == PAGE1)       /* Page1 valid */
654
-  {
506
+  if (ValidPage == PAGE1) {     /* Page1 valid */
655 507
     /* New page address where variable will be moved to */
656 508
     NewPageAddress = PAGE0_BASE_ADDRESS;
657
-
658 509
     /* Old page ID where variable will be taken from */
659 510
     OldPageId = PAGE1_ID;
660 511
   }
661
-  else if (ValidPage == PAGE0)  /* Page0 valid */
662
-  {
512
+  else if (ValidPage == PAGE0) { /* Page0 valid */
663 513
     /* New page address  where variable will be moved to */
664 514
     NewPageAddress = PAGE1_BASE_ADDRESS;
665
-
666 515
     /* Old page ID where variable will be taken from */
667 516
     OldPageId = PAGE0_ID;
668 517
   }
669 518
   else
670
-  {
671 519
     return NO_VALID_PAGE;       /* No valid Page */
672
-  }
673 520
 
674 521
   /* Set the new Page status to RECEIVE_DATA status */
675 522
   FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, NewPageAddress, RECEIVE_DATA);
676 523
   /* If program operation was failed, a Flash error code is returned */
677
-  if (FlashStatus != HAL_OK)
678
-  {
679
-    return FlashStatus;
680
-  }
524
+  if (FlashStatus != HAL_OK) return FlashStatus;
681 525
 
682 526
   /* Write the variable passed as parameter in the new active page */
683 527
   EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddress, Data);
684 528
   /* If program operation was failed, a Flash error code is returned */
685
-  if (EepromStatus != HAL_OK)
686
-  {
687
-    return EepromStatus;
688
-  }
529
+  if (EepromStatus != HAL_OK) return EepromStatus;
689 530
 
690 531
   /* Transfer process: transfer variables from old to the new active page */
691
-  for (VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++)
692
-  {
693
-    if (VirtAddVarTab[VarIdx] != VirtAddress)  /* Check each variable except the one passed as parameter */
694
-    {
532
+  for (VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++) {
533
+    if (VirtAddVarTab[VarIdx] != VirtAddress) { /* Check each variable except the one passed as parameter */
695 534
       /* Read the other last variable updates */
696 535
       ReadStatus = EE_ReadVariable(VirtAddVarTab[VarIdx], &DataVar);
697 536
       /* In case variable corresponding to the virtual address was found */
698
-      if (ReadStatus != 0x1)
699
-      {
537
+      if (ReadStatus != 0x1) {
700 538
         /* Transfer the variable to the new active page */
701 539
         EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddVarTab[VarIdx], DataVar);
702 540
         /* If program operation was failed, a Flash error code is returned */
703
-        if (EepromStatus != HAL_OK)
704
-        {
705
-          return EepromStatus;
706
-        }
541
+        if (EepromStatus != HAL_OK) return EepromStatus;
707 542
       }
708 543
     }
709 544
   }
@@ -716,18 +551,12 @@ static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data)
716 551
   /* Erase the old Page: Set old Page status to ERASED status */
717 552
   FlashStatus = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
718 553
   /* If erase operation was failed, a Flash error code is returned */
719
-  if (FlashStatus != HAL_OK)
720
-  {
721
-    return FlashStatus;
722
-  }
554
+  if (FlashStatus != HAL_OK) return FlashStatus;
723 555
 
724 556
   /* Set new Page status to VALID_PAGE status */
725 557
   FlashStatus = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, NewPageAddress, VALID_PAGE);
726 558
   /* If program operation was failed, a Flash error code is returned */
727
-  if (FlashStatus != HAL_OK)
728
-  {
729
-    return FlashStatus;
730
-  }
559
+  if (FlashStatus != HAL_OK) return FlashStatus;
731 560
 
732 561
   /* Return last operation flash status */
733 562
   return FlashStatus;
@@ -736,7 +565,7 @@ static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data)
736 565
 #endif // STM32F7
737 566
 
738 567
 /**
739
-  * @}
740
-  */
568
+ * @}
569
+ */
741 570
 
742 571
 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

+ 1
- 1
Marlin/src/HAL/HAL_STM32F7/EmulatedEeprom.cpp 파일 보기

@@ -18,7 +18,7 @@
18 18
  */
19 19
 
20 20
 #ifdef STM32F7
21
- 
21
+
22 22
 /**
23 23
  * Description: functions for I2C connected external EEPROM.
24 24
  * Not platform dependent.

+ 8
- 11
Marlin/src/HAL/HAL_STM32F7/HAL_STM32F7.cpp 파일 보기

@@ -81,18 +81,17 @@ void sei(void) { interrupts(); }
81 81
 void HAL_clear_reset_source(void) { __HAL_RCC_CLEAR_RESET_FLAGS(); }
82 82
 
83 83
 uint8_t HAL_get_reset_source (void) {
84
- if(__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET)
85
-  return RST_WATCHDOG;
84
+  if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET)
85
+    return RST_WATCHDOG;
86 86
 
87
- if(__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET)
88
-   return RST_SOFTWARE;
87
+  if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET)
88
+    return RST_SOFTWARE;
89 89
 
90
- if(__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET)
91
-   return RST_EXTERNAL;
90
+  if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET)
91
+    return RST_EXTERNAL;
92 92
 
93
- if(__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET)
94
-   return RST_POWER_ON;
95
-  
93
+  if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET)
94
+    return RST_POWER_ON;
96 95
   return 0;
97 96
 }
98 97
 
@@ -102,8 +101,6 @@ extern "C" {
102 101
   extern unsigned int _ebss; // end of bss section
103 102
 }
104 103
 
105
-
106
-
107 104
 // return free memory between end of heap (or end bss) and whatever is current
108 105
 
109 106
 /*

+ 4
- 4
Marlin/src/HAL/HAL_STM32F7/HAL_STM32F7.h 파일 보기

@@ -57,7 +57,7 @@
57 57
   #error "SERIAL_PORT must be from -1 to 6"
58 58
 #endif
59 59
 #if SERIAL_PORT == -1
60
-  #define MYSERIAL0 SerialUSB	
60
+  #define MYSERIAL0 SerialUSB
61 61
 #elif SERIAL_PORT == 1
62 62
   #define MYSERIAL0 SerialUART1
63 63
 #elif SERIAL_PORT == 2
@@ -79,7 +79,7 @@
79 79
     #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
80 80
   #endif
81 81
   #define NUM_SERIAL 2
82
-  #if SERIAL_PORT_2 == -1 
82
+  #if SERIAL_PORT_2 == -1
83 83
     #define MYSERIAL1 SerialUSB
84 84
   #elif SERIAL_PORT_2 == 1
85 85
     #define MYSERIAL1 SerialUART1
@@ -98,7 +98,7 @@
98 98
   #define NUM_SERIAL 1
99 99
 #endif
100 100
 
101
-#define _BV(bit) 	(1 << (bit))
101
+#define _BV(bit) (1 << (bit))
102 102
 
103 103
 /**
104 104
  * TODO: review this to return 1 for pins that are not analog input
@@ -107,7 +107,7 @@
107 107
   #define analogInputToDigitalPin(p) (p)
108 108
 #endif
109 109
 
110
-#define CRITICAL_SECTION_START	noInterrupts();
110
+#define CRITICAL_SECTION_START  noInterrupts();
111 111
 #define CRITICAL_SECTION_END    interrupts();
112 112
 
113 113
 // On AVR this is in math.h?

+ 2
- 13
Marlin/src/HAL/HAL_STM32F7/HAL_spi_STM32F7.cpp 파일 보기

@@ -82,20 +82,17 @@ void spiBegin(void) {
82 82
   #if !PIN_EXISTS(SS)
83 83
     #error SS_PIN not defined!
84 84
   #endif
85
- 
85
+
86 86
   SET_OUTPUT(SS_PIN);
87 87
   WRITE(SS_PIN, HIGH);
88
-  
89 88
 }
90 89
 
91
-
92
-
93 90
 /** Configure SPI for specified SPI speed */
94 91
 void spiInit(uint8_t spiRate) {
95 92
   // Use datarates Marlin uses
96 93
   uint32_t clock;
97 94
   switch (spiRate) {
98
-  case SPI_FULL_SPEED:    clock = 20000000; break;	//13.9mhz=20000000	6.75mhz=10000000	3.38mhz=5000000	.833mhz=1000000
95
+  case SPI_FULL_SPEED:    clock = 20000000; break; // 13.9mhz=20000000  6.75mhz=10000000  3.38mhz=5000000  .833mhz=1000000
99 96
   case SPI_HALF_SPEED:    clock =  5000000; break;
100 97
   case SPI_QUARTER_SPEED: clock =  2500000; break;
101 98
   case SPI_EIGHTH_SPEED:  clock =  1250000; break;
@@ -108,8 +105,6 @@ void spiInit(uint8_t spiRate) {
108 105
   SPI.begin();
109 106
 }
110 107
 
111
-
112
-
113 108
 /**
114 109
  * @brief  Receives a single byte from the SPI port.
115 110
  *
@@ -133,8 +128,6 @@ uint8_t spiRec(void) {
133 128
  *
134 129
  * @details Uses DMA
135 130
  */
136
-
137
-
138 131
 void spiRead(uint8_t* buf, uint16_t nbyte) {
139 132
   SPI.beginTransaction(spiConfig);
140 133
   SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte);
@@ -162,8 +155,6 @@ void spiSend(uint8_t b) {
162 155
  *
163 156
  * @details Use DMA
164 157
  */
165
- 
166
-
167 158
 void spiSendBlock(uint8_t token, const uint8_t* buf) {
168 159
   SPI.beginTransaction(spiConfig);
169 160
   SPI.transfer(token);
@@ -171,8 +162,6 @@ void spiSendBlock(uint8_t token, const uint8_t* buf) {
171 162
   SPI.endTransaction();
172 163
 }
173 164
 
174
-
175
-
176 165
 #endif // SOFTWARE_SPI
177 166
 
178 167
 #endif // STM32F7

+ 20
- 24
Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.cpp 파일 보기

@@ -20,8 +20,8 @@
20 20
  *
21 21
  */
22 22
 
23
-
24 23
 #ifdef STM32F7
24
+
25 25
 // --------------------------------------------------------------------------
26 26
 // Includes
27 27
 // --------------------------------------------------------------------------
@@ -71,12 +71,12 @@ tTimerConfig timerConfig[NUM_HARDWARE_TIMERS];
71 71
 
72 72
 bool timers_initialised[NUM_HARDWARE_TIMERS] = {false};
73 73
 
74
-void HAL_timer_start(uint8_t timer_num, uint32_t frequency) {
74
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
75 75
 
76
-  if(!timers_initialised[timer_num]) {
76
+  if (!timers_initialised[timer_num]) {
77 77
     switch (timer_num) {
78 78
       case STEP_TIMER_NUM:
79
-      //STEPPER TIMER TIM5 //use a 32bit timer 
79
+      //STEPPER TIMER TIM5 //use a 32bit timer
80 80
       __HAL_RCC_TIM5_CLK_ENABLE();
81 81
       timerConfig[0].timerdef.Instance               = TIM5;
82 82
       timerConfig[0].timerdef.Init.Prescaler         = (STEPPER_TIMER_PRESCALE);
@@ -92,8 +92,8 @@ void HAL_timer_start(uint8_t timer_num, uint32_t frequency) {
92 92
       //TEMP TIMER TIM7 // any available 16bit Timer (1 already used for PWM)
93 93
       __HAL_RCC_TIM7_CLK_ENABLE();
94 94
       timerConfig[1].timerdef.Instance               = TIM7;
95
-      timerConfig[1].timerdef.Init.Prescaler         = (TEMP_TIMER_PRESCALE); 
96
-      timerConfig[1].timerdef.Init.CounterMode       = TIM_COUNTERMODE_UP;   
95
+      timerConfig[1].timerdef.Init.Prescaler         = (TEMP_TIMER_PRESCALE);
96
+      timerConfig[1].timerdef.Init.CounterMode       = TIM_COUNTERMODE_UP;
97 97
       timerConfig[1].timerdef.Init.ClockDivision     = TIM_CLOCKDIVISION_DIV1;
98 98
       timerConfig[1].IRQ_Id = TIM7_IRQn;
99 99
       timerConfig[1].callback = (uint32_t)TC7_Handler;
@@ -103,52 +103,48 @@ void HAL_timer_start(uint8_t timer_num, uint32_t frequency) {
103 103
     timers_initialised[timer_num] = true;
104 104
   }
105 105
 
106
-  timerConfig[timer_num].timerdef.Init.Period =  ((HAL_TIMER_RATE / timerConfig[timer_num].timerdef.Init.Prescaler) / (frequency)) - 1;
106
+  timerConfig[timer_num].timerdef.Init.Period = (((HAL_TIMER_RATE) / timerConfig[timer_num].timerdef.Init.Prescaler) / frequency) - 1;
107 107
 
108
-  if(HAL_TIM_Base_Init(&timerConfig[timer_num].timerdef)  == HAL_OK ){
108
+  if (HAL_TIM_Base_Init(&timerConfig[timer_num].timerdef) == HAL_OK)
109 109
     HAL_TIM_Base_Start_IT(&timerConfig[timer_num].timerdef);
110
-  } 
111
-
112 110
 }
113 111
 
114 112
 //forward the interrupt
115
-extern "C" void TIM5_IRQHandler()
116
-{
117
-    ((void(*)(void))timerConfig[0].callback)();
113
+extern "C" void TIM5_IRQHandler() {
114
+  ((void(*)(void))timerConfig[0].callback)();
118 115
 }
119
-extern "C" void TIM7_IRQHandler()
120
-{
121
-    ((void(*)(void))timerConfig[1].callback)();
116
+extern "C" void TIM7_IRQHandler() {
117
+  ((void(*)(void))timerConfig[1].callback)();
122 118
 }
123 119
 
124
-void HAL_timer_set_count (uint8_t timer_num, uint32_t count) {
120
+void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
125 121
   __HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, count);
126 122
 }
127 123
 
128
-void HAL_timer_set_current_count (uint8_t timer_num, uint32_t count) {
124
+void HAL_timer_set_current_count(const uint8_t timer_num, const uint32_t count) {
129 125
   __HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, count);
130 126
 }
131 127
 
132
-void HAL_timer_enable_interrupt (uint8_t timer_num) {
128
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
133 129
   HAL_NVIC_EnableIRQ(timerConfig[timer_num].IRQ_Id);
134 130
 }
135 131
 
136
-void HAL_timer_disable_interrupt (uint8_t timer_num) {
132
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
137 133
   HAL_NVIC_DisableIRQ(timerConfig[timer_num].IRQ_Id);
138 134
 }
139 135
 
140
-hal_timer_t HAL_timer_get_count (uint8_t timer_num) {
136
+hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
141 137
   return __HAL_TIM_GetAutoreload(&timerConfig[timer_num].timerdef);
142 138
 }
143 139
 
144
-uint32_t HAL_timer_get_current_count(uint8_t timer_num) {
140
+uint32_t HAL_timer_get_current_count(const uint8_t timer_num) {
145 141
   return __HAL_TIM_GetCounter(&timerConfig[timer_num].timerdef);
146 142
 }
147 143
 
148
-void HAL_timer_isr_prologue (uint8_t timer_num) {
144
+void HAL_timer_isr_prologue(const uint8_t timer_num) {
149 145
   if (__HAL_TIM_GET_FLAG(&timerConfig[timer_num].timerdef, TIM_FLAG_UPDATE) == SET) {
150 146
     __HAL_TIM_CLEAR_FLAG(&timerConfig[timer_num].timerdef, TIM_FLAG_UPDATE);
151 147
   }
152 148
 }
153 149
 
154
-#endif 
150
+#endif // STM32F7

+ 15
- 22
Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h 파일 보기

@@ -20,8 +20,6 @@
20 20
  *
21 21
  */
22 22
 
23
-
24
-
25 23
 #ifndef _HAL_TIMERS_STM32F7_H
26 24
 #define _HAL_TIMERS_STM32F7_H
27 25
 
@@ -35,16 +33,15 @@
35 33
 // Defines
36 34
 // --------------------------------------------------------------------------
37 35
 
38
-
39 36
 #define FORCE_INLINE __attribute__((always_inline)) inline
40 37
 
41
-#define hal_timer_t uint32_t	//hal_timer_t uint32_t		//TODO: One is 16-bit, one 32-bit - does this need to be checked?
42
-#define HAL_TIMER_TYPE_MAX 0xFFFF	
38
+#define hal_timer_t uint32_t  // TODO: One is 16-bit, one 32-bit - does this need to be checked?
39
+#define HAL_TIMER_TYPE_MAX 0xFFFF
43 40
 
44 41
 #define STEP_TIMER_NUM 0  // index of timer to use for stepper
45 42
 #define TEMP_TIMER_NUM 1  // index of timer to use for temperature
46 43
 
47
-#define HAL_TIMER_RATE         (HAL_RCC_GetSysClockFreq()/2)  // frequency of timer peripherals
44
+#define HAL_TIMER_RATE         (HAL_RCC_GetSysClockFreq() / 2)  // frequency of timer peripherals
48 45
 #define STEPPER_TIMER_PRESCALE 54            // was 40,prescaler for setting stepper timer, 2Mhz
49 46
 #define HAL_STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
50 47
 #define HAL_TICKS_PER_US       ((HAL_STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per us
@@ -55,11 +52,11 @@
55 52
 #define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
56 53
 #define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
57 54
 
58
-#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt (STEP_TIMER_NUM)
59
-#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt (STEP_TIMER_NUM)
55
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
56
+#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
60 57
 
61
-#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt (TEMP_TIMER_NUM)
62
-#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt (TEMP_TIMER_NUM)
58
+#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
59
+#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
63 60
 
64 61
 #define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
65 62
 // TODO change this
@@ -86,27 +83,23 @@ typedef struct {
86 83
 
87 84
 //extern const tTimerConfig timerConfig[];
88 85
 
89
-
90
-
91 86
 // --------------------------------------------------------------------------
92 87
 // Public functions
93 88
 // --------------------------------------------------------------------------
94 89
 
95
-void HAL_timer_start (uint8_t timer_num, uint32_t frequency);
96
-void HAL_timer_enable_interrupt(uint8_t timer_num);
97
-void HAL_timer_disable_interrupt(uint8_t timer_num);
98
-
99
-
90
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
91
+void HAL_timer_enable_interrupt(const uint8_t timer_num);
92
+void HAL_timer_disable_interrupt(const uint8_t timer_num);
100 93
 
101
-void HAL_timer_set_count (uint8_t timer_num, uint32_t count);
102
-hal_timer_t HAL_timer_get_count (uint8_t timer_num);
103
-uint32_t HAL_timer_get_current_count(uint8_t timer_num);
94
+void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count);
95
+hal_timer_t HAL_timer_get_count(const uint8_t timer_num);
96
+uint32_t HAL_timer_get_current_count(const uint8_t timer_num);
104 97
 
105
-void HAL_timer_set_current_count (uint8_t timer_num, uint32_t count);		//New
98
+void HAL_timer_set_current_count(const uint8_t timer_num, const uint32_t count); // New
106 99
 /*FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
107 100
   // To do ??
108 101
 }*/
109 102
 
110
-void HAL_timer_isr_prologue (uint8_t timer_num);
103
+void HAL_timer_isr_prologue(const uint8_t timer_num);
111 104
 
112 105
 #endif // _HAL_TIMERS_STM32F7_H

+ 657
- 761
Marlin/src/HAL/HAL_STM32F7/TMC2660.cpp
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


+ 96
- 99
Marlin/src/HAL/HAL_STM32F7/TMC2660.h 파일 보기

@@ -1,37 +1,35 @@
1
-/*
2
- TMC26XStepper.cpp - - TMC26X Stepper library for Wiring/Arduino
3
- 
4
- based on the stepper library by Tom Igoe, et. al.
5
-
6
- Copyright (c) 2011, Interactive Matter, Marcus Nowotny
7
- 
8
- Permission is hereby granted, free of charge, to any person obtaining a copy
9
- of this software and associated documentation files (the "Software"), to deal
10
- in the Software without restriction, including without limitation the rights
11
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- copies of the Software, and to permit persons to whom the Software is
13
- furnished to do so, subject to the following conditions:
14
- 
15
- The above copyright notice and this permission notice shall be included in
16
- all copies or substantial portions of the Software.
17
- 
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
- THE SOFTWARE.
25
-
1
+/**
2
+ * TMC26XStepper.h - - TMC26X Stepper library for Wiring/Arduino
3
+ * 
4
+ * based on the stepper library by Tom Igoe, et. al.
5
+ *
6
+ * Copyright (c) 2011, Interactive Matter, Marcus Nowotny
7
+ * 
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ * 
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ * 
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ *
26 26
  */
27 27
 
28
-
29
-
30 28
 #include "../../inc/MarlinConfig.h"
31 29
 
32 30
 // ensure this library description is only included once
33
-#ifndef TMC26XStepper_h
34
-#define TMC26XStepper_h
31
+#ifndef _TMC26XSTEPPER_H_
32
+#define _TMC26XSTEPPER_H_
35 33
 
36 34
 //! return value for TMC26XStepper.getOverTemperature() if there is a overtemperature situation in the TMC chip
37 35
 /*!
@@ -124,8 +122,8 @@ class TMC26XStepper {
124 122
      * You can select a different stepping with setMicrosteps() to aa different value.
125 123
      * \sa start(), setMicrosteps()
126 124
      */
127
-	TMC26XStepper(int number_of_steps, int cs_pin, int dir_pin, int step_pin, unsigned int current, unsigned int resistor=100);	//resistor=150
128
-	
125
+    TMC26XStepper(int number_of_steps, int cs_pin, int dir_pin, int step_pin, unsigned int current, unsigned int resistor=100); //resistor=150
126
+    
129 127
     /*!
130 128
      * \brief configures and starts the TMC26X stepper driver. Before you called this function the stepper driver is in nonfunctional mode.
131 129
      *
@@ -133,7 +131,7 @@ class TMC26XStepper {
133 131
      * Most member functions are non functional if the driver has not been started.
134 132
      * Therefore it is best to call this in your Arduino setup() function.
135 133
      */
136
-	void start();
134
+    void start();
137 135
     
138 136
     /*!
139 137
      * \brief resets the stepper in unconfigured mode.
@@ -145,7 +143,7 @@ class TMC26XStepper {
145 143
      * this has to be configured back by yourself.
146 144
      * (Hint: Normally you do not need this function)
147 145
      */
148
-	void un_start();
146
+    void un_start();
149 147
 
150 148
 
151 149
     /*!
@@ -168,9 +166,9 @@ class TMC26XStepper {
168 166
      * If you give any other value it will be rounded to the next smaller number (3 would give a microstepping of 2).
169 167
      * You can always check the current microstepping with getMicrosteps(). 
170 168
      */ 
171
-	void setMicrosteps(int number_of_steps);
169
+    void setMicrosteps(int number_of_steps);
172 170
     
173
-	/*!
171
+    /*!
174 172
      * \brief returns the effective current number of microsteps selected.
175 173
      *
176 174
      * This function always returns the effective number of microsteps. 
@@ -178,7 +176,7 @@ class TMC26XStepper {
178 176
      *
179 177
      * \sa setMicrosteps()
180 178
      */
181
-	int getMicrosteps(void);
179
+    int getMicrosteps(void);
182 180
 
183 181
     /*!
184 182
      * \brief Initiate a movement for the given number of steps. Positive numbers move in one, negative numbers in the other direction.
@@ -187,7 +185,7 @@ class TMC26XStepper {
187 185
      * \return 0 if the motor was not moving and moves now. -1 if the motor is moving and the new steps could not be set.
188 186
      *
189 187
      * If the previous movement is not finished yet the function will return -1 and not change the steps to move the motor.
190
-	 * If the motor does not move it return 0
188
+     * If the motor does not move it return 0
191 189
      *
192 190
      * The direction of the movement is indicated by the sign of the steps parameter. It is not determinable if positive values are right 
193 191
      * or left This depends on the internal construction of the motor and how you connected it to the stepper driver.
@@ -264,7 +262,7 @@ class TMC26XStepper {
264 262
      * \sa setSpreadCycleChoper() for other alternatives.
265 263
      * \sa setRandomOffTime() for spreading the noise over a wider spectrum
266 264
      */
267
-	void setConstantOffTimeChopper(char constant_off_time, char blank_time, char fast_decay_time_setting, char sine_wave_offset, unsigned char use_current_comparator);
265
+    void setConstantOffTimeChopper(char constant_off_time, char blank_time, char fast_decay_time_setting, char sine_wave_offset, unsigned char use_current_comparator);
268 266
     
269 267
     /*!
270 268
      * \brief Sets and configures with spread cycle chopper.
@@ -286,9 +284,9 @@ class TMC26XStepper {
286 284
      * 
287 285
      * \sa setRandomOffTime() for spreading the noise over a wider spectrum
288 286
      */
289
-	void setSpreadCycleChopper(char constant_off_time, char blank_time, char hysteresis_start, char hysteresis_end, char hysteresis_decrement);
287
+    void setSpreadCycleChopper(char constant_off_time, char blank_time, char hysteresis_start, char hysteresis_end, char hysteresis_decrement);
290 288
 
291
-	/*!
289
+    /*!
292 290
      * \brief Use random off time for noise reduction (0 for off, -1 for on).
293 291
      * \param value 0 for off, -1 for on
294 292
      *
@@ -303,16 +301,16 @@ class TMC26XStepper {
303 301
      * It modulates the slow decay time setting when switched on. The random off time feature further spreads the chopper spectrum,
304 302
      * reducing electromagnetic emission on single frequencies.
305 303
      */
306
-	void setRandomOffTime(char value);
304
+    void setRandomOffTime(char value);
307 305
     
308
-	/*!
306
+    /*!
309 307
      * \brief set the maximum motor current in mA (1000 is 1 Amp)
310 308
      * Keep in mind this is the maximum peak Current. The RMS current will be 1/sqrt(2) smaller. The actual current can also be smaller
311 309
      * by employing CoolStep.
312 310
      * \param current the maximum motor current in mA
313 311
      * \sa getCurrent(), getCurrentCurrent()
314 312
      */
315
-	void setCurrent(unsigned int current);
313
+    void setCurrent(unsigned int current);
316 314
     
317 315
     /*!
318 316
      * \brief readout the motor maximum current in mA (1000 is an Amp)
@@ -322,7 +320,7 @@ class TMC26XStepper {
322 320
      */
323 321
     unsigned int getCurrent(void);
324 322
     
325
-	/*!
323
+    /*!
326 324
      * \brief set the StallGuard threshold in order to get sensible StallGuard readings.
327 325
      * \param stall_guard_threshold -64 … 63 the StallGuard threshold
328 326
      * \param stall_guard_filter_enabled 0 if the filter is disabled, -1 if it is enabled
@@ -337,7 +335,7 @@ class TMC26XStepper {
337 335
      * 
338 336
      * \sa getCurrentStallGuardReading() to read out the current value.
339 337
      */ 
340
-	void setStallGuardThreshold(char stall_guard_threshold, char stall_guard_filter_enabled);
338
+    void setStallGuardThreshold(char stall_guard_threshold, char stall_guard_filter_enabled);
341 339
     
342 340
     /*!
343 341
      * \brief reads out the StallGuard threshold
@@ -416,13 +414,13 @@ class TMC26XStepper {
416 414
      */
417 415
     unsigned char getCoolStepLowerCurrentLimit();
418 416
     
419
-	/*!
417
+    /*!
420 418
      * \brief Get the current microstep position for phase A
421 419
      * \return The current microstep position for phase A 0…255
422 420
      * 
423 421
      * Keep in mind that this routine reads and writes a value via SPI - so this may take a bit time.
424 422
      */
425
-	int getMotorPosition(void);
423
+    int getMotorPosition(void);
426 424
     
427 425
     /*!
428 426
      * \brief Reads the current StallGuard value.
@@ -430,7 +428,7 @@ class TMC26XStepper {
430 428
      * Keep in mind that this routine reads and writes a value via SPI - so this may take a bit time.
431 429
      * \sa setStallGuardThreshold() for tuning the readout to sensible ranges.
432 430
      */
433
-	int getCurrentStallGuardReading(void);
431
+    int getCurrentStallGuardReading(void);
434 432
     
435 433
     /*!
436 434
      * \brief Reads the current current setting value as fraction of the maximum current
@@ -463,7 +461,7 @@ class TMC26XStepper {
463 461
      *
464 462
      * \sa setStallGuardThreshold() for tuning the readout to sensible ranges.
465 463
      */
466
-	boolean isStallGuardOverThreshold(void);
464
+    boolean isStallGuardOverThreshold(void);
467 465
     
468 466
     /*!
469 467
      * \brief Return over temperature status of the last status readout
@@ -471,7 +469,7 @@ class TMC26XStepper {
471 469
      * Keep in mind that this method does not enforce a readout but uses the value of the last status readout.
472 470
      * You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
473 471
      */
474
-	char getOverTemperature(void);
472
+    char getOverTemperature(void);
475 473
     
476 474
     /*!
477 475
      * \brief Is motor channel A shorted to ground detected in the last status readout.
@@ -480,7 +478,7 @@ class TMC26XStepper {
480 478
      * You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
481 479
      */
482 480
      
483
-	boolean isShortToGroundA(void);
481
+    boolean isShortToGroundA(void);
484 482
 
485 483
     /*!
486 484
      * \brief Is motor channel B shorted to ground detected in the last status readout.
@@ -488,22 +486,22 @@ class TMC26XStepper {
488 486
      * Keep in mind that this method does not enforce a readout but uses the value of the last status readout.
489 487
      * You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
490 488
      */
491
-	boolean isShortToGroundB(void);
492
-	/*!
489
+    boolean isShortToGroundB(void);
490
+    /*!
493 491
      * \brief iIs motor channel A connected according to the last statu readout.
494 492
      * \return true is yes, false if not.
495 493
      * Keep in mind that this method does not enforce a readout but uses the value of the last status readout.
496 494
      * You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
497 495
      */
498
-	boolean isOpenLoadA(void);
496
+    boolean isOpenLoadA(void);
499 497
 
500
-	/*!
498
+    /*!
501 499
      * \brief iIs motor channel A connected according to the last statu readout.
502 500
      * \return true is yes, false if not.
503 501
      * Keep in mind that this method does not enforce a readout but uses the value of the last status readout.
504 502
      * You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
505 503
      */
506
-	boolean isOpenLoadB(void);
504
+    boolean isOpenLoadB(void);
507 505
     
508 506
     /*!
509 507
      * \brief Is chopper inactive since 2^20 clock cycles - defaults to ~0,08s
@@ -511,7 +509,7 @@ class TMC26XStepper {
511 509
      * Keep in mind that this method does not enforce a readout but uses the value of the last status readout.
512 510
      * You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
513 511
      */
514
-	boolean isStandStill(void);
512
+    boolean isStandStill(void);
515 513
 
516 514
     /*!
517 515
      * \brief checks if there is a StallGuard warning in the last status
@@ -524,7 +522,7 @@ class TMC26XStepper {
524 522
      *
525 523
      * \sa setStallGuardThreshold() for tuning the readout to sensible ranges.
526 524
      */
527
-	boolean isStallGuardReached(void);
525
+    boolean isStallGuardReached(void);
528 526
     
529 527
     /*!
530 528
      *\brief enables or disables the motor driver bridges. If disabled the motor can run freely. If enabled not.
@@ -539,7 +537,7 @@ class TMC26XStepper {
539 537
      */
540 538
     boolean isEnabled();
541 539
 
542
-	/*!
540
+    /*!
543 541
      * \brief Manually read out the status register
544 542
      * This function sends a byte to the motor driver in order to get the current readout. The parameter read_value
545 543
      * seletcs which value will get returned. If the read_vlaue changes in respect to the previous readout this method
@@ -548,7 +546,7 @@ class TMC26XStepper {
548 546
      * \param read_value selects which value to read out (0..3). You can use the defines TMC26X_READOUT_POSITION, TMC_262_READOUT_STALLGUARD, or TMC_262_READOUT_CURRENT
549 547
      * \sa TMC26X_READOUT_POSITION, TMC_262_READOUT_STALLGUARD, TMC_262_READOUT_CURRENT
550 548
      */
551
-	void readStatus(char read_value);
549
+    void readStatus(char read_value);
552 550
     
553 551
     /*!
554 552
      * \brief Returns the current sense resistor value in milliohm.
@@ -560,51 +558,50 @@ class TMC26XStepper {
560 558
      * \brief Prints out all the information that can be found in the last status read out - it does not force a status readout. 
561 559
      * The result is printed via Serial
562 560
      */
563
-	void debugLastStatus(void);
564
-	/*!
561
+    void debugLastStatus(void);
562
+    /*!
565 563
      * \brief library version
566 564
      * \return the version number as int.
567 565
      */
568 566
     int version(void);
569 567
 
570 568
   private:    
571
-  	unsigned int steps_left;		//the steps the motor has to do to complete the movement
572
-    int direction;        // Direction of rotation
573
-    unsigned long step_delay;    // delay between steps, in ms, based on speed
574
-    int number_of_steps;      // total number of steps this motor can take
575
-    unsigned int speed; // we need to store the current speed in order to change the speed after changing microstepping
576
-    unsigned int resistor; //current sense resitor value in milliohm
569
+    unsigned int steps_left;    // The steps the motor has to do to complete the movement
570
+    int direction;              // Direction of rotation
571
+    unsigned long step_delay;   // Delay between steps, in ms, based on speed
572
+    int number_of_steps;        // Total number of steps this motor can take
573
+    unsigned int speed;         // Store the current speed in order to change the speed after changing microstepping
574
+    unsigned int resistor;      // Current sense resitor value in milliohm
577 575
         
578
-    unsigned long last_step_time;      // time stamp in ms of when the last step was taken
579
-    unsigned long next_step_time;      // time stamp in ms of when the last step was taken
580
-	
581
-	//driver control register copies to easily set & modify the registers
582
-	unsigned long driver_control_register_value;
583
-	unsigned long chopper_config_register;
584
-	unsigned long cool_step_register_value;
585
-	unsigned long stall_guard2_current_register_value;
586
-	unsigned long driver_configuration_register_value;
587
-	//the driver status result
588
-	unsigned long driver_status_result;
589
-	
590
-	//helper routione to get the top 10 bit of the readout
591
-	inline int getReadoutValue();
592
-	
593
-	//the pins for the stepper driver
594
-	unsigned char cs_pin;
595
-	unsigned char step_pin;
596
-	unsigned char dir_pin;
597
-	
598
-	//status values 
599
-	boolean started; //if the stepper has been started yet
600
-	int microsteps; //the current number of micro steps
601
-    char constant_off_time; //we need to remember this value in order to enable and disable the motor
602
-    unsigned char cool_step_lower_threshold; // we need to remember the threshold to enable and disable the CoolStep feature
603
-    boolean cool_step_enabled; //we need to remember this to configure the coolstep if it si enabled
604
-	
605
-	//SPI sender
606
-	inline void send262(unsigned long datagram);
576
+    unsigned long last_step_time;   // Time stamp in ms of when the last step was taken
577
+    unsigned long next_step_time;   // Time stamp in ms of when the last step was taken
578
+    
579
+    // Driver control register copies to easily set & modify the registers
580
+    unsigned long driver_control_register_value;
581
+    unsigned long chopper_config_register;
582
+    unsigned long cool_step_register_value;
583
+    unsigned long stall_guard2_current_register_value;
584
+    unsigned long driver_configuration_register_value;
585
+    // The driver status result
586
+    unsigned long driver_status_result;
587
+    
588
+    // Helper routione to get the top 10 bit of the readout
589
+    inline int getReadoutValue();
590
+    
591
+    // The pins for the stepper driver
592
+    unsigned char cs_pin;
593
+    unsigned char step_pin;
594
+    unsigned char dir_pin;
595
+    
596
+    // Status values 
597
+    boolean started; // If the stepper has been started yet
598
+    int microsteps; // The current number of micro steps
599
+    char constant_off_time; // We need to remember this value in order to enable and disable the motor
600
+    unsigned char cool_step_lower_threshold; //  we need to remember the threshold to enable and disable the CoolStep feature
601
+    boolean cool_step_enabled; // We need to remember this to configure the coolstep if it si enabled
602
+    
603
+    // SPI sender
604
+    inline void send262(unsigned long datagram);
607 605
 };
608 606
 
609
-#endif
610
-
607
+#endif // _TMC26XSTEPPER_H_

+ 12
- 12
Marlin/src/HAL/HAL_STM32F7/fastio_STM32F7.h 파일 보기

@@ -26,10 +26,10 @@
26 26
  * These use GPIO functions instead of Direct Port Manipulation, as on AVR.
27 27
  */
28 28
 
29
-#ifndef	_FASTIO_STM32F7_H
30
-#define	_FASTIO_STM32F7_H
29
+#ifndef _FASTIO_STM32F7_H
30
+#define _FASTIO_STM32F7_H
31 31
 
32
-#define _BV(bit) 	(1 << (bit))
32
+#define _BV(bit) (1 << (bit))
33 33
 
34 34
 #define READ(IO)              digitalRead(IO)
35 35
 #define WRITE(IO, v)          digitalWrite(IO,v)
@@ -38,17 +38,17 @@
38 38
 
39 39
 #define _GET_MODE(IO)
40 40
 #define _SET_MODE(IO,M)       pinMode(IO, M)
41
-#define _SET_OUTPUT(IO)       pinMode(IO, OUTPUT)								/*!< Output Push Pull Mode & GPIO_NOPULL   */
41
+#define _SET_OUTPUT(IO)       pinMode(IO, OUTPUT)                               /*!< Output Push Pull Mode & GPIO_NOPULL   */
42 42
 
43
-#define SET_INPUT(IO)         _SET_MODE(IO, INPUT)								/*!< Input Floating Mode                   */
44
-#define SET_INPUT_PULLUP(IO)  _SET_MODE(IO, INPUT_PULLUP)						/*!< Input with Pull-up activation         */
45
-#define SET_INPUT_PULLDOW(IO) _SET_MODE(IO, INPUT_PULLDOWN)						/*!< Input with Pull-down activation       */
46
-#define SET_OUTPUT(IO)        do{ _SET_OUTPUT(IO); WRITE(IO, LOW); }while(0)	
43
+#define SET_INPUT(IO)         _SET_MODE(IO, INPUT)                              /*!< Input Floating Mode                   */
44
+#define SET_INPUT_PULLUP(IO)  _SET_MODE(IO, INPUT_PULLUP)                       /*!< Input with Pull-up activation         */
45
+#define SET_INPUT_PULLDOW(IO) _SET_MODE(IO, INPUT_PULLDOWN)                     /*!< Input with Pull-down activation       */
46
+#define SET_OUTPUT(IO)        do{ _SET_OUTPUT(IO); WRITE(IO, LOW); }while(0)
47 47
 
48
-#define GET_INPUT(IO)         
49
-#define GET_OUTPUT(IO)        
50
-#define GET_TIMER(IO)         
48
+#define GET_INPUT(IO)
49
+#define GET_OUTPUT(IO)
50
+#define GET_TIMER(IO)
51 51
 
52 52
 #define OUT_WRITE(IO, v) { _SET_OUTPUT(IO); WRITE(IO, v); }
53 53
 
54
-#endif	/* _FASTIO_STM32F7_H */
54
+#endif // _FASTIO_STM32F7_H

+ 35
- 38
Marlin/src/HAL/HAL_STM32F7/watchdog_STM32F7.cpp 파일 보기

@@ -1,24 +1,24 @@
1 1
 /**
2
-* Marlin 3D Printer Firmware
3
-* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
-*
5
-* Based on Sprinter and grbl.
6
-* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
-*
8
-* This program is free software: you can redistribute it and/or modify
9
-* it under the terms of the GNU General Public License as published by
10
-* the Free Software Foundation, either version 3 of the License, or
11
-* (at your option) any later version.
12
-*
13
-* This program is distributed in the hope that it will be useful,
14
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
-* GNU General Public License for more details.
17
-*
18
-* You should have received a copy of the GNU General Public License
19
-* along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22 22
 
23 23
 #ifdef STM32F7
24 24
 
@@ -26,29 +26,26 @@
26 26
 
27 27
 #if ENABLED(USE_WATCHDOG)
28 28
 
29
-    #include "watchdog_STM32F7.h"
29
+  #include "watchdog_STM32F7.h"
30 30
 
31
-	IWDG_HandleTypeDef hiwdg;
31
+  IWDG_HandleTypeDef hiwdg;
32 32
 
33
-    void watchdog_init() {
34
-		hiwdg.Instance = IWDG;
35
-		hiwdg.Init.Prescaler = IWDG_PRESCALER_32;	//32kHz LSI clock and 32x prescalar = 1024Hz IWDG clock
36
-		hiwdg.Init.Reload = 4095; 					//4095 counts = 4 seconds at 1024Hz
37
-		if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
38
-		{
39
-			//Error_Handler();
40
-		}
33
+  void watchdog_init() {
34
+    hiwdg.Instance = IWDG;
35
+    hiwdg.Init.Prescaler = IWDG_PRESCALER_32; //32kHz LSI clock and 32x prescalar = 1024Hz IWDG clock
36
+    hiwdg.Init.Reload = 4095;           //4095 counts = 4 seconds at 1024Hz
37
+    if (HAL_IWDG_Init(&hiwdg) != HAL_OK) {
38
+      //Error_Handler();
41 39
     }
40
+  }
42 41
 
43
-    void watchdog_reset() {
44
-		/* Refresh IWDG: reload counter */
45
-		if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK)
46
-		{
47
-			/* Refresh Error */
48
-			//Error_Handler();
49
-		}
42
+  void watchdog_reset() {
43
+    /* Refresh IWDG: reload counter */
44
+    if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK) {
45
+      /* Refresh Error */
46
+      //Error_Handler();
50 47
     }
51
-
48
+  }
52 49
 
53 50
 #endif // USE_WATCHDOG
54 51
 

+ 2
- 2
Marlin/src/HAL/HAL_SanityCheck.h 파일 보기

@@ -37,10 +37,10 @@
37 37
   #elif defined(__STM32F1__)
38 38
     #include "HAL_STM32F1/SanityCheck_Stm32f1.h"
39 39
 
40
-	#elif defined(STM32F7)
40
+  #elif defined(STM32F7)
41 41
     #include "HAL_STM32F7/SanityCheck_STM32F7.h"
42 42
 
43
-	#else
43
+#else
44 44
   #error Unsupported Platform!
45 45
 #endif
46 46
 

+ 1
- 1
Marlin/src/HAL/HAL_spi_pins.h 파일 보기

@@ -41,7 +41,7 @@
41 41
 #elif defined(STM32F7)
42 42
   #include "HAL_STM32F7/spi_pins.h"
43 43
 
44
-	#else
44
+#else
45 45
   #error "Unsupported Platform!"
46 46
 #endif
47 47
 

+ 1
- 0
Marlin/src/core/macros.h 파일 보기

@@ -120,6 +120,7 @@
120 120
 // Macros to contrain values
121 121
 #define NOLESS(v,n) do{ if (v < n) v = n; }while(0)
122 122
 #define NOMORE(v,n) do{ if (v > n) v = n; }while(0)
123
+#define LIMIT(v,n1,n2) do{ if (v < n1) v = n1; else if (v > n2) v = n2; }while(0)
123 124
 
124 125
 // Macros to support option testing
125 126
 #define _CAT(a, ...) a ## __VA_ARGS__

+ 1
- 1
Marlin/src/module/stepper_indirection.cpp 파일 보기

@@ -42,7 +42,7 @@
42 42
 
43 43
   #include <SPI.h>
44 44
   
45
-  #if defined(STM32F7)
45
+  #ifdef STM32F7
46 46
     #include "../HAL/HAL_STM32F7/TMC2660.h"
47 47
   #else
48 48
     #include <TMC26XStepper.h>

+ 1
- 1
Marlin/src/module/stepper_indirection.h 파일 보기

@@ -49,7 +49,7 @@
49 49
 // TMC26X drivers have STEP/DIR on normal pins, but ENABLE via SPI
50 50
 #if ENABLED(HAVE_TMCDRIVER)
51 51
   #include <SPI.h>
52
-  #if defined(STM32F7)
52
+  #ifdef STM32F7
53 53
     #include "../HAL/HAL_STM32F7/TMC2660.h"
54 54
   #else
55 55
     #include <TMC26XStepper.h>

Loading…
취소
저장