Browse Source

[2.0.x] Teensy 3.1 and 3.2 support (#11460)

Ilya Bukhonin 7 years ago
parent
commit
7ecb8b4af5

+ 90
- 0
Marlin/src/HAL/HAL_TEENSY31_32/HAL.cpp View File

@@ -0,0 +1,90 @@
1
+/* **************************************************************************
2
+
3
+ Marlin 3D Printer Firmware
4
+ Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
+****************************************************************************/
20
+
21
+
22
+/**
23
+ * Description: HAL for Teensy32 (MK20DX256)
24
+ */
25
+
26
+#ifdef __MK20DX256__
27
+
28
+#include "HAL.h"
29
+#include "../Delay.h"
30
+
31
+#include <Wire.h>
32
+
33
+uint16_t HAL_adc_result;
34
+
35
+static const uint8_t pin2sc1a[] = {
36
+    5, 14, 8, 9, 13, 12, 6, 7, 15, 4, 0, 19, 3, 31, // 0-13, we treat them as A0-A13
37
+    5, 14, 8, 9, 13, 12, 6, 7, 15, 4, // 14-23 (A0-A9)
38
+    31, 31, 31, 31, 31, 31, 31, 31, 31, 31, // 24-33
39
+    0+64, 19+64, 3+64, 31+64, // 34-37 (A10-A13)
40
+    26, 22, 23, 27, 29, 30 // 38-43: temp. sensor, VREF_OUT, A14, bandgap, VREFH, VREFL. A14 isn't connected to anything in Teensy 3.0.
41
+};
42
+
43
+/*
44
+  // disable interrupts
45
+  void cli(void) { noInterrupts(); }
46
+
47
+  // enable interrupts
48
+  void sei(void) { interrupts(); }
49
+*/
50
+
51
+void HAL_adc_init() {
52
+  analog_init();
53
+  while (ADC0_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish
54
+  NVIC_ENABLE_IRQ(IRQ_FTM1);
55
+}
56
+
57
+void HAL_clear_reset_source(void) { }
58
+
59
+uint8_t HAL_get_reset_source(void) {
60
+  switch (RCM_SRS0) {
61
+    case 128: return RST_POWER_ON; break;
62
+    case 64: return RST_EXTERNAL; break;
63
+    case 32: return RST_WATCHDOG; break;
64
+    // case 8: return RST_LOSS_OF_LOCK; break;
65
+    // case 4: return RST_LOSS_OF_CLOCK; break;
66
+    // case 2: return RST_LOW_VOLTAGE; break;
67
+  }
68
+  return 0;
69
+}
70
+
71
+extern "C" {
72
+  extern char __bss_end;
73
+  extern char __heap_start;
74
+  extern void* __brkval;
75
+
76
+  int freeMemory() {
77
+    int free_memory;
78
+    if ((int)__brkval == 0)
79
+      free_memory = ((int)&free_memory) - ((int)&__bss_end);
80
+    else
81
+      free_memory = ((int)&free_memory) - ((int)__brkval);
82
+    return free_memory;
83
+  }
84
+}
85
+
86
+void HAL_adc_start_conversion(const uint8_t adc_pin) { ADC0_SC1A = pin2sc1a[adc_pin]; }
87
+
88
+uint16_t HAL_adc_get_result(void) { return ADC0_RA; }
89
+
90
+#endif // __MK20DX256__

+ 159
- 0
Marlin/src/HAL/HAL_TEENSY31_32/HAL.h View File

@@ -0,0 +1,159 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ *
4
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
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
+
23
+/**
24
+ * Description: HAL for Teensy 3.5 and Teensy 3.6
25
+ */
26
+
27
+#pragma once
28
+
29
+#define CPU_32_BIT
30
+
31
+// _BV is re-defined in Arduino.h
32
+#undef _BV
33
+
34
+#include <Arduino.h>
35
+
36
+// Redefine sq macro defined by teensy3/wiring.h
37
+#undef sq
38
+#define sq(x) ((x)*(x))
39
+
40
+#include "../math_32bit.h"
41
+#include "../HAL_SPI.h"
42
+
43
+#include "fastio_Teensy.h"
44
+#include "watchdog_Teensy.h"
45
+
46
+#include "HAL_timers_Teensy.h"
47
+
48
+#include <stdint.h>
49
+
50
+#define ST7920_DELAY_1 DELAY_NS(600)
51
+#define ST7920_DELAY_2 DELAY_NS(750)
52
+#define ST7920_DELAY_3 DELAY_NS(750)
53
+
54
+//#undef MOTHERBOARD
55
+//#define MOTHERBOARD BOARD_TEENSY31_32
56
+
57
+#define IS_32BIT_TEENSY defined(__MK20DX256__)
58
+#define IS_TEENSY32 defined(__MK20DX256__)
59
+
60
+#define NUM_SERIAL 1
61
+
62
+#if SERIAL_PORT == -1
63
+  #define MYSERIAL0 SerialUSB
64
+#elif SERIAL_PORT == 0
65
+  #define MYSERIAL0 Serial
66
+#elif SERIAL_PORT == 1
67
+  #define MYSERIAL0 Serial1
68
+#elif SERIAL_PORT == 2
69
+  #define MYSERIAL0 Serial2
70
+#elif SERIAL_PORT == 3
71
+  #define MYSERIAL0 Serial3
72
+#endif
73
+
74
+#define HAL_SERVO_LIB libServo
75
+
76
+typedef int8_t pin_t;
77
+
78
+#ifndef analogInputToDigitalPin
79
+  #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
80
+#endif
81
+
82
+#define CRITICAL_SECTION_START  uint32_t primask = __get_PRIMASK(); __disable_irq()
83
+#define CRITICAL_SECTION_END    if (!primask) __enable_irq()
84
+#define ISRS_ENABLED() (!__get_PRIMASK())
85
+#define ENABLE_ISRS()  __enable_irq()
86
+#define DISABLE_ISRS() __disable_irq()
87
+
88
+#ifndef strncpy_P
89
+  #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
90
+#endif
91
+
92
+// Fix bug in pgm_read_ptr
93
+#undef pgm_read_ptr
94
+#define pgm_read_ptr(addr) (*((void**)(addr)))
95
+// Add type-checking to pgm_read_word
96
+#undef pgm_read_word
97
+#define pgm_read_word(addr) (*((uint16_t*)(addr)))
98
+
99
+#define RST_POWER_ON   1
100
+#define RST_EXTERNAL   2
101
+#define RST_BROWN_OUT  4
102
+#define RST_WATCHDOG   8
103
+#define RST_JTAG       16
104
+#define RST_SOFTWARE   32
105
+#define RST_BACKUP     64
106
+
107
+// Clear the reset reason
108
+void HAL_clear_reset_source(void);
109
+
110
+// Get the reason for the reset
111
+uint8_t HAL_get_reset_source(void);
112
+
113
+FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
114
+
115
+extern "C" {
116
+  int freeMemory(void);
117
+}
118
+
119
+// SPI: Extended functions which take a channel number (hardware SPI only)
120
+
121
+// Write single byte to specified SPI channel
122
+void spiSend(uint32_t chan, byte b);
123
+
124
+// Write buffer to specified SPI channel
125
+void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
126
+
127
+// Read single byte from specified SPI channel
128
+uint8_t spiRec(uint32_t chan);
129
+
130
+// ADC
131
+
132
+void HAL_adc_init();
133
+
134
+#define HAL_START_ADC(pin)  HAL_adc_start_conversion(pin)
135
+#define HAL_READ_ADC()      HAL_adc_get_result()
136
+#define HAL_ADC_READY()     true
137
+
138
+#define HAL_ANALOG_SELECT(pin) NOOP;
139
+
140
+void HAL_adc_start_conversion(const uint8_t adc_pin);
141
+
142
+uint16_t HAL_adc_get_result(void);
143
+
144
+/*
145
+uint16_t HAL_getAdcReading(uint8_t chan);
146
+
147
+void HAL_startAdcConversion(uint8_t chan);
148
+uint8_t HAL_pinToAdcChannel(int pin);
149
+
150
+uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
151
+//uint16_t HAL_getAdcSuperSample(uint8_t chan);
152
+
153
+void HAL_enable_AdcFreerun(void);
154
+//void HAL_disable_AdcFreerun(uint8_t chan);
155
+*/
156
+
157
+#define GET_PIN_MAP_PIN(index) index
158
+#define GET_PIN_MAP_INDEX(pin) pin
159
+#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)

+ 36
- 0
Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.cpp View File

@@ -0,0 +1,36 @@
1
+#ifdef __MK20DX256__
2
+
3
+#include "../../inc/MarlinConfig.h"
4
+
5
+#if HAS_SERVOS
6
+
7
+#include "HAL_Servo_Teensy.h"
8
+
9
+uint8_t servoPin[MAX_SERVOS] = { 0 };
10
+
11
+int8_t libServo::attach(const int pin) {
12
+  if (this->servoIndex >= MAX_SERVOS) return -1;
13
+  if (pin > 0) servoPin[this->servoIndex] = pin;
14
+  return Servo::attach(servoPin[this->servoIndex]);
15
+}
16
+
17
+int8_t libServo::attach(const int pin, const int min, const int max) {
18
+  if (pin > 0) servoPin[this->servoIndex] = pin;
19
+  return Servo::attach(servoPin[this->servoIndex], min, max);
20
+}
21
+
22
+void libServo::move(const int value) {
23
+  constexpr uint16_t servo_delay[] = SERVO_DELAY;
24
+  static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
25
+  if (this->attach(0) >= 0) {
26
+    this->write(value);
27
+    safe_delay(servo_delay[this->servoIndex]);
28
+    #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
29
+      this->detach();
30
+    #endif
31
+  }
32
+}
33
+
34
+#endif // HAS_SERVOS
35
+
36
+#endif // __MK20DX256__

+ 37
- 0
Marlin/src/HAL/HAL_TEENSY31_32/HAL_Servo_Teensy.h View File

@@ -0,0 +1,37 @@
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
+ */
22
+
23
+#pragma once
24
+
25
+#include <Servo.h>
26
+
27
+// Inherit and expand on the official library
28
+class libServo : public Servo {
29
+  public:
30
+    int8_t attach(const int pin);
31
+    int8_t attach(const int pin, const int min, const int max);
32
+    void move(const int value);
33
+  private:
34
+     uint16_t min_ticks;
35
+     uint16_t max_ticks;
36
+     uint8_t servoIndex;               // index into the channel data for this servo
37
+};

+ 132
- 0
Marlin/src/HAL/HAL_TEENSY31_32/HAL_spi_Teensy.cpp View File

@@ -0,0 +1,132 @@
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
+ */
22
+#ifdef __MK20DX256__
23
+
24
+#include "HAL.h"
25
+#include <SPI.h>
26
+#include <pins_arduino.h>
27
+#include "spi_pins.h"
28
+#include "../../core/macros.h"
29
+
30
+static SPISettings spiConfig;
31
+
32
+/**
33
+ * Standard SPI functions
34
+ */
35
+
36
+// Initialise SPI bus
37
+void spiBegin(void) {
38
+  #if !PIN_EXISTS(SS)
39
+    #error "SS_PIN not defined!"
40
+  #endif
41
+  SET_OUTPUT(SS_PIN);
42
+  WRITE(SS_PIN, HIGH);
43
+  SET_OUTPUT(SCK_PIN);
44
+  SET_INPUT(MISO_PIN);
45
+  SET_OUTPUT(MOSI_PIN);
46
+
47
+  //#if DISABLED(SOFTWARE_SPI)
48
+  #if 0
49
+    // set SS high - may be chip select for another SPI device
50
+    #if SET_SPI_SS_HIGH
51
+      WRITE(SS_PIN, HIGH);
52
+    #endif
53
+    // set a default rate
54
+    spiInit(SPI_HALF_SPEED); // 1
55
+  #endif
56
+}
57
+
58
+// Configure SPI for specified SPI speed
59
+void spiInit(uint8_t spiRate) {
60
+  // Use data rates Marlin uses
61
+  uint32_t clock;
62
+  switch (spiRate) {
63
+    case SPI_FULL_SPEED:    clock = 10000000; break;
64
+    case SPI_HALF_SPEED:    clock =  5000000; break;
65
+    case SPI_QUARTER_SPEED: clock =  2500000; break;
66
+    case SPI_EIGHTH_SPEED:  clock =  1250000; break;
67
+    case SPI_SPEED_5:       clock =   625000; break;
68
+    case SPI_SPEED_6:       clock =   312500; break;
69
+    default:                clock = 4000000; // Default from the SPI libarary
70
+  }
71
+  spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
72
+  SPI.begin();
73
+}
74
+
75
+// SPI receive a byte
76
+uint8_t spiRec(void) {
77
+  SPI.beginTransaction(spiConfig);
78
+  const uint8_t returnByte = SPI.transfer(0xFF);
79
+  SPI.endTransaction();
80
+  return returnByte;
81
+  //SPDR = 0xFF;
82
+  //while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
83
+  //return SPDR;
84
+}
85
+
86
+// SPI read data
87
+void spiRead(uint8_t* buf, uint16_t nbyte) {
88
+  SPI.beginTransaction(spiConfig);
89
+  SPI.transfer(buf, nbyte);
90
+  SPI.endTransaction();
91
+  //if (nbyte-- == 0) return;
92
+  //  SPDR = 0xFF;
93
+  //for (uint16_t i = 0; i < nbyte; i++) {
94
+  //  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
95
+  //  buf[i] = SPDR;
96
+  //  SPDR = 0xFF;
97
+  //}
98
+  //while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
99
+  //buf[nbyte] = SPDR;
100
+}
101
+
102
+// SPI send a byte
103
+void spiSend(uint8_t b) {
104
+  SPI.beginTransaction(spiConfig);
105
+  SPI.transfer(b);
106
+  SPI.endTransaction();
107
+  //SPDR = b;
108
+  //while (!TEST(SPSR, SPIF)) { /* nada */ }
109
+}
110
+
111
+// SPI send block
112
+void spiSendBlock(uint8_t token, const uint8_t* buf) {
113
+  SPI.beginTransaction(spiConfig);
114
+  SPDR = token;
115
+  for (uint16_t i = 0; i < 512; i += 2) {
116
+    while (!TEST(SPSR, SPIF)) { /* nada */ };
117
+    SPDR = buf[i];
118
+    while (!TEST(SPSR, SPIF)) { /* nada */ };
119
+    SPDR = buf[i + 1];
120
+  }
121
+  while (!TEST(SPSR, SPIF)) { /* nada */ };
122
+  SPI.endTransaction();
123
+}
124
+
125
+
126
+// Begin SPI transaction, set clock, bit order, data mode
127
+void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
128
+  spiConfig = SPISettings(spiClock, bitOrder, dataMode);
129
+  SPI.beginTransaction(spiConfig);
130
+}
131
+
132
+#endif // __MK20DX256__

+ 113
- 0
Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.cpp View File

@@ -0,0 +1,113 @@
1
+/* **************************************************************************
2
+
3
+ Marlin 3D Printer Firmware
4
+ Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
+****************************************************************************/
20
+
21
+
22
+/**
23
+ * Teensy3.2 __MK20DX256__
24
+ */
25
+
26
+#ifdef __MK20DX256__
27
+
28
+#include "HAL.h"
29
+#include "HAL_timers_Teensy.h"
30
+
31
+/** \brief Instruction Synchronization Barrier
32
+  Instruction Synchronization Barrier flushes the pipeline in the processor,
33
+  so that all instructions following the ISB are fetched from cache or
34
+  memory, after the instruction has been completed.
35
+*/
36
+FORCE_INLINE static void __ISB(void) {
37
+  __asm__ __volatile__("isb 0xF":::"memory");
38
+}
39
+
40
+/** \brief Data Synchronization Barrier
41
+  This function acts as a special kind of Data Memory Barrier.
42
+  It completes when all explicit memory accesses before this instruction complete.
43
+*/
44
+FORCE_INLINE static void __DSB(void) {
45
+  __asm__ __volatile__("dsb 0xF":::"memory");
46
+}
47
+
48
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
49
+  switch (timer_num) {
50
+    case 0:
51
+      FTM0_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN;
52
+      FTM0_SC = 0x00; // Set this to zero before changing the modulus
53
+      FTM0_CNT = 0x0000; // Reset the count to zero
54
+      FTM0_MOD = 0xFFFF; // max modulus = 65535
55
+      FTM0_C0V = FTM0_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value
56
+      FTM0_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM0_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 8
57
+      FTM0_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
58
+      break;
59
+    case 1:
60
+      FTM1_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN; // Disable write protection, Enable FTM1
61
+      FTM1_SC = 0x00; // Set this to zero before changing the modulus
62
+      FTM1_CNT = 0x0000; // Reset the count to zero
63
+      FTM1_MOD = 0xFFFF; // max modulus = 65535
64
+      FTM1_C0V = FTM1_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value 65535
65
+      FTM1_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM1_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 4
66
+      FTM1_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
67
+      break;
68
+  }
69
+}
70
+
71
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
72
+  switch(timer_num) {
73
+    case 0: NVIC_ENABLE_IRQ(IRQ_FTM0); break;
74
+    case 1: NVIC_ENABLE_IRQ(IRQ_FTM1); break;
75
+  }
76
+}
77
+
78
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
79
+  switch (timer_num) {
80
+    case 0: NVIC_DISABLE_IRQ(IRQ_FTM0); break;
81
+    case 1: NVIC_DISABLE_IRQ(IRQ_FTM1); break;
82
+  }
83
+
84
+  // We NEED memory barriers to ensure Interrupts are actually disabled!
85
+  // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
86
+  __DSB();
87
+  __ISB();
88
+}
89
+
90
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
91
+  switch (timer_num) {
92
+    case 0: return NVIC_IS_ENABLED(IRQ_FTM0);
93
+    case 1: return NVIC_IS_ENABLED(IRQ_FTM1);
94
+  }
95
+  return false;
96
+}
97
+
98
+void HAL_timer_isr_prologue(const uint8_t timer_num) {
99
+  switch(timer_num) {
100
+    case 0:
101
+      FTM0_CNT = 0x0000;
102
+      FTM0_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
103
+      FTM0_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
104
+      break;
105
+    case 1:
106
+      FTM1_CNT = 0x0000;
107
+      FTM1_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
108
+      FTM1_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
109
+      break;
110
+  }
111
+}
112
+
113
+#endif // __MK20DX256__

+ 113
- 0
Marlin/src/HAL/HAL_TEENSY31_32/HAL_timers_Teensy.h View File

@@ -0,0 +1,113 @@
1
+/* **************************************************************************
2
+
3
+ Marlin 3D Printer Firmware
4
+ Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+ Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
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
+/**
23
+ * Description: HAL for
24
+ * Teensy3.2 (__MK20DX256__)
25
+ */
26
+
27
+#pragma once
28
+
29
+// --------------------------------------------------------------------------
30
+// Includes
31
+// --------------------------------------------------------------------------
32
+
33
+#include <stdint.h>
34
+
35
+// --------------------------------------------------------------------------
36
+// Defines
37
+// --------------------------------------------------------------------------
38
+
39
+#define FORCE_INLINE __attribute__((always_inline)) inline
40
+
41
+typedef uint32_t hal_timer_t;
42
+#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
43
+
44
+#define FTM0_TIMER_PRESCALE 8
45
+#define FTM1_TIMER_PRESCALE 4
46
+#define FTM0_TIMER_PRESCALE_BITS 0b011
47
+#define FTM1_TIMER_PRESCALE_BITS 0b010
48
+
49
+#define FTM0_TIMER_RATE (F_BUS / FTM0_TIMER_PRESCALE) // 60MHz / 8 = 7500kHz
50
+#define FTM1_TIMER_RATE (F_BUS / FTM1_TIMER_PRESCALE) // 60MHz / 4 = 15MHz
51
+
52
+#define HAL_TIMER_RATE         (FTM0_TIMER_RATE)
53
+
54
+#define STEP_TIMER_NUM 0
55
+#define TEMP_TIMER_NUM 1
56
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
57
+
58
+#define TEMP_TIMER_FREQUENCY    1000
59
+
60
+#define STEPPER_TIMER_RATE     HAL_TIMER_RATE
61
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000)
62
+#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
63
+
64
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
65
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
66
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
67
+
68
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
69
+#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
70
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
71
+
72
+#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
73
+#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
74
+
75
+#define HAL_STEP_TIMER_ISR  extern "C" void ftm0_isr(void) //void TC3_Handler()
76
+#define HAL_TEMP_TIMER_ISR  extern "C" void ftm1_isr(void) //void TC4_Handler()
77
+
78
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
79
+
80
+FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
81
+  switch (timer_num) {
82
+    case 0: FTM0_C0V = compare; break;
83
+    case 1: FTM1_C0V = compare; break;
84
+  }
85
+}
86
+
87
+FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
88
+  switch (timer_num) {
89
+    case 0: return FTM0_C0V;
90
+    case 1: return FTM1_C0V;
91
+  }
92
+  return 0;
93
+}
94
+
95
+FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
96
+  switch (timer_num) {
97
+    case 0: return FTM0_CNT;
98
+    case 1: return FTM1_CNT;
99
+  }
100
+  return 0;
101
+}
102
+
103
+FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
104
+  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
105
+  if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
106
+}
107
+
108
+void HAL_timer_enable_interrupt(const uint8_t timer_num);
109
+void HAL_timer_disable_interrupt(const uint8_t timer_num);
110
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
111
+
112
+void HAL_timer_isr_prologue(const uint8_t timer_num);
113
+#define HAL_timer_isr_epilogue(TIMER_NUM)

+ 29
- 0
Marlin/src/HAL/HAL_TEENSY31_32/SanityCheck.h View File

@@ -0,0 +1,29 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 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
+
23
+/**
24
+ * Test TEENSY35_36 specific configuration values for errors at compile-time.
25
+ */
26
+
27
+#if ENABLED(EMERGENCY_PARSER)
28
+  #error "EMERGENCY_PARSER is not yet implemented for Teensy 3.1/3.2. Disable EMERGENCY_PARSER to continue."
29
+#endif

+ 86
- 0
Marlin/src/HAL/HAL_TEENSY31_32/endstop_interrupts.h View File

@@ -0,0 +1,86 @@
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
+ */
22
+
23
+/**
24
+ * Endstop Interrupts
25
+ *
26
+ * Without endstop interrupts the endstop pins must be polled continually in
27
+ * the temperature-ISR via endstops.update(), most of the time finding no change.
28
+ * With this feature endstops.update() is called only when we know that at
29
+ * least one endstop has changed state, saving valuable CPU cycles.
30
+ *
31
+ * This feature only works when all used endstop pins can generate an 'external interrupt'.
32
+ *
33
+ * Test whether pins issue interrupts on your board by flashing 'pin_interrupt_test.ino'.
34
+ * (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
35
+ */
36
+
37
+#pragma once
38
+
39
+#include "../../module/endstops.h"
40
+
41
+// One ISR for all EXT-Interrupts
42
+void endstop_ISR(void) { endstops.update(); }
43
+
44
+/**
45
+ *  Endstop interrupts for Due based targets.
46
+ *  On Due, all pins support external interrupt capability.
47
+ */
48
+
49
+void setup_endstop_interrupts( void ) {
50
+
51
+  #if HAS_X_MAX
52
+    attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE); // assign it
53
+  #endif
54
+
55
+  #if HAS_X_MIN
56
+    attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
57
+  #endif
58
+
59
+  #if HAS_Y_MAX
60
+    attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
61
+  #endif
62
+
63
+  #if HAS_Y_MIN
64
+    attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
65
+  #endif
66
+
67
+  #if HAS_Z_MAX
68
+    attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
69
+  #endif
70
+
71
+  #if HAS_Z_MIN
72
+     attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
73
+  #endif
74
+
75
+  #if HAS_Z2_MAX
76
+    attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
77
+  #endif
78
+
79
+  #if HAS_Z2_MIN
80
+    attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
81
+  #endif
82
+
83
+  #if HAS_Z_MIN_PROBE_PIN
84
+    attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
85
+  #endif
86
+}

+ 92
- 0
Marlin/src/HAL/HAL_TEENSY31_32/fastio_Teensy.h View File

@@ -0,0 +1,92 @@
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
+ */
22
+
23
+/**
24
+ * Fast I/O Routines for Teensy 3.5 and Teensy 3.6
25
+ * Use direct port manipulation to save scads of processor time.
26
+ * Contributed by Triffid_Hunter and modified by Kliment, thinkyhead, Bob-the-Kuhn, et.al.
27
+ */
28
+
29
+#pragma once
30
+
31
+#ifndef MASK
32
+  #define MASK(PIN) (1 << PIN)
33
+#endif
34
+
35
+#define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000)
36
+#define GPIO_BITBAND(reg, bit) (*(uint32_t *)GPIO_BITBAND_ADDR((reg), (bit)))
37
+
38
+/**
39
+ * Magic I/O routines
40
+ *
41
+ * Now you can simply SET_OUTPUT(PIN); WRITE(PIN, HIGH); WRITE(PIN, LOW);
42
+ *
43
+ * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
44
+ */
45
+
46
+#define _READ(p) bool(CORE_PIN ## p ## _PINREG & CORE_PIN ## p ## _BITMASK)
47
+
48
+#define _WRITE(P,V) do{ \
49
+  if (V) CORE_PIN ## P ## _PORTSET = CORE_PIN ## P ## _BITMASK; \
50
+  else CORE_PIN ## P ## _PORTCLEAR = CORE_PIN ## P ## _BITMASK; \
51
+}while(0)
52
+
53
+#define _TOGGLE(P) (*(&(CORE_PIN ## P ## _PORTCLEAR)+1) = CORE_PIN ## P ## _BITMASK)
54
+
55
+#define _SET_INPUT(P) do{ \
56
+  CORE_PIN ## P ## _CONFIG = PORT_PCR_MUX(1); \
57
+  GPIO_BITBAND(CORE_PIN ## P ## _DDRREG , CORE_PIN ## P ## _BIT) = 0; \
58
+}while(0)
59
+
60
+#define _SET_OUTPUT(P) do{ \
61
+  CORE_PIN ## P ## _CONFIG = PORT_PCR_MUX(1)|PORT_PCR_SRE|PORT_PCR_DSE; \
62
+  GPIO_BITBAND(CORE_PIN ## P ## _DDRREG , CORE_PIN ## P ## _BIT) = 1; \
63
+}while(0)
64
+
65
+#define _SET_INPUT_PULLUP(P) do{ \
66
+  CORE_PIN ## P ## _CONFIG = PORT_PCR_MUX(1) | PORT_PCR_PE | PORT_PCR_PS; \
67
+  GPIO_BITBAND(CORE_PIN ## P ## _DDRREG , CORE_PIN ## P ## _BIT) = 0; \
68
+}while(0)
69
+
70
+#define _GET_INPUT(P)   ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0)
71
+#define _GET_OUTPUT(P)  ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0)
72
+
73
+#define READ(IO)              _READ(IO)
74
+
75
+#define WRITE_VAR(IO,V)       _WRITE_VAR(IO,V)
76
+#define WRITE(IO,V)           _WRITE(IO,V)
77
+#define TOGGLE(IO)            _TOGGLE(IO)
78
+
79
+#define SET_INPUT(IO)         _SET_INPUT(IO)
80
+#define SET_INPUT_PULLUP(IO)  _SET_INPUT_PULLUP(IO)
81
+#define SET_OUTPUT(IO)        _SET_OUTPUT(IO)
82
+
83
+#define GET_INPUT(IO)         _GET_INPUT(IO)
84
+#define GET_OUTPUT(IO)        _GET_OUTPUT(IO)
85
+
86
+#define OUT_WRITE(IO,V)       do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
87
+
88
+/**
89
+ * Ports, functions, and pins
90
+ */
91
+
92
+#define DIO0_PIN 8

+ 51
- 0
Marlin/src/HAL/HAL_TEENSY31_32/persistent_store_impl.cpp View File

@@ -0,0 +1,51 @@
1
+#ifdef __MK20DX256__
2
+
3
+#include "../../inc/MarlinConfig.h"
4
+
5
+#if ENABLED(EEPROM_SETTINGS)
6
+
7
+#include "../persistent_store_api.h"
8
+
9
+namespace HAL {
10
+namespace PersistentStore {
11
+
12
+bool access_start() { return true; }
13
+bool access_finish() { return true; }
14
+
15
+bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
16
+  while (size--) {
17
+    uint8_t * const p = (uint8_t * const)pos;
18
+    uint8_t v = *value;
19
+    // EEPROM has only ~100,000 write cycles,
20
+    // so only write bytes that have changed!
21
+    if (v != eeprom_read_byte(p)) {
22
+      eeprom_write_byte(p, v);
23
+      if (eeprom_read_byte(p) != v) {
24
+        SERIAL_ECHO_START();
25
+        SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
26
+        return true;
27
+      }
28
+    }
29
+    crc16(crc, &v, 1);
30
+    pos++;
31
+    value++;
32
+  };
33
+  return false;
34
+}
35
+
36
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
37
+  do {
38
+    uint8_t c = eeprom_read_byte((unsigned char*)pos);
39
+    if (writing) *value = c;
40
+    crc16(crc, &c, 1);
41
+    pos++;
42
+    value++;
43
+  } while (--size);
44
+  return false;
45
+}
46
+
47
+} // PersistentStore
48
+} // HAL
49
+
50
+#endif // EEPROM_SETTINGS
51
+#endif // __MK20DX256__

+ 1
- 0
Marlin/src/HAL/HAL_TEENSY31_32/pinsDebug.h View File

@@ -0,0 +1 @@
1
+#error "Debug pins is not supported on the Teensy 3.1 / 3.2 Platform!"

+ 28
- 0
Marlin/src/HAL/HAL_TEENSY31_32/spi_pins.h View File

@@ -0,0 +1,28 @@
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
+ */
22
+
23
+#pragma once
24
+
25
+#define SCK_PIN   13
26
+#define MISO_PIN  12
27
+#define MOSI_PIN  11
28
+#define SS_PIN    20 //SDSS // A.28, A.29, B.21, C.26, C.29

+ 39
- 0
Marlin/src/HAL/HAL_TEENSY31_32/watchdog_Teensy.cpp View File

@@ -0,0 +1,39 @@
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
+ */
22
+
23
+#ifdef __MK20DX256__
24
+
25
+#include "../../inc/MarlinConfig.h"
26
+
27
+#if ENABLED(USE_WATCHDOG)
28
+
29
+#include "watchdog_Teensy.h"
30
+
31
+void watchdog_init() {
32
+  WDOG_TOVALH = 0;
33
+  WDOG_TOVALL = 4000;
34
+  WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
35
+}
36
+
37
+#endif // USE_WATCHDOG
38
+
39
+#endif // __MK20DX256__

+ 35
- 0
Marlin/src/HAL/HAL_TEENSY31_32/watchdog_Teensy.h View File

@@ -0,0 +1,35 @@
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
+ */
22
+
23
+#pragma once
24
+
25
+#include "HAL.h"
26
+
27
+// Arduino Due core now has watchdog support
28
+
29
+void watchdog_init();
30
+
31
+inline void watchdog_reset() {
32
+  // Watchdog refresh sequence
33
+  WDOG_REFRESH = 0xA602;
34
+  WDOG_REFRESH = 0xB480;
35
+}

+ 2
- 0
Marlin/src/HAL/platforms.h View File

@@ -7,6 +7,8 @@
7 7
   #define HAL_PLATFORM HAL_AVR
8 8
 #elif defined(ARDUINO_ARCH_SAM)
9 9
   #define HAL_PLATFORM HAL_DUE
10
+#elif defined(__MK20DX256__)
11
+  #define HAL_PLATFORM HAL_TEENSY31_32
10 12
 #elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
11 13
   #define HAL_PLATFORM HAL_TEENSY35_36
12 14
 #elif defined(TARGET_LPC1768)

+ 11
- 0
Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp View File

@@ -84,6 +84,17 @@
84 84
 #define END_FLASH_ADDR    0x08100000
85 85
 #endif
86 86
 
87
+#ifdef __MK20DX256__
88
+// For MK20DX256 in TEENSY 3.1 or TEENSY 3.2
89
+//  SRAM  (0x1FFF8000 - 0x20008000) (64kb)
90
+//  FLASH (0x00000000 - 0x00040000) (256kb)
91
+//
92
+#define START_SRAM_ADDR   0x1FFF8000
93
+#define END_SRAM_ADDR     0x20008000
94
+#define START_FLASH_ADDR  0x00000000
95
+#define END_FLASH_ADDR    0x00040000
96
+#endif
97
+
87 98
 #ifdef __MK64FX512__
88 99
 // For MK64FX512 in TEENSY 3.5
89 100
 //  SRAM  (0x1FFF0000 - 0x20020000) (192kb)

+ 5
- 7
Marlin/src/HAL/shared/servo.h View File

@@ -66,12 +66,12 @@
66 66
  *                   With DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DELAY and detach.
67 67
  */
68 68
 
69
-#ifndef SERVO_H
70
-#define SERVO_H
71
-
72
-#if IS_32BIT_TEENSY
73
-  #include "../HAL_TEENSY35_36/HAL_Servo_Teensy.h" // Teensy HAL uses an inherited library
69
+#pragma once
74 70
 
71
+#if IS_TEENSY32
72
+  #include "../HAL_TEENSY31_32/HAL_Servo_Teensy.h"
73
+#elif IS_TEENSY35 || IS_TEENSY36
74
+  #include "../HAL_TEENSY35_36/HAL_Servo_Teensy.h"
75 75
 #elif defined(TARGET_LPC1768)
76 76
   #include "../HAL_LPC1768/LPC1768_Servo.h"
77 77
 #elif defined(STM32F1) || defined(STM32F1xx)
@@ -111,5 +111,3 @@
111 111
   };
112 112
 
113 113
 #endif
114
-
115
-#endif // SERVO_H

+ 1
- 0
Marlin/src/core/boards.h View File

@@ -222,6 +222,7 @@
222 222
 // STM32 ARM Cortex-M4F
223 223
 //
224 224
 
225
+#define BOARD_TEENSY31_32      1552   // Teensy3.1 and Teensy3.2
225 226
 #define BOARD_TEENSY35_36       841   // Teensy3.5 and Teensy3.6
226 227
 #define BOARD_BEAST            1802   // STM32FxxxVxT6 Libmaple based stm32f4 controller
227 228
 #define BOARD_STM32F4          1804   // STM32 STM32GENERIC based STM32F4 controller

+ 2
- 0
Marlin/src/pins/pins.h View File

@@ -381,6 +381,8 @@
381 381
 // STM32 ARM Cortex-M4F
382 382
 //
383 383
 
384
+#elif MB(TEENSY31_32)
385
+  #include "pins_TEENSY31_32.h"       // TEENSY31_32                                env:teensy31
384 386
 #elif MB(TEENSY35_36)
385 387
   #include "pins_TEENSY35_36.h"       // TEENSY35_36                                env:teensy35
386 388
 #elif MB(BEAST)

+ 111
- 0
Marlin/src/pins/pins_TEENSY31_32.h View File

@@ -0,0 +1,111 @@
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
+ */
22
+
23
+/****************************************************************************************
24
+* Teensy 3.1 (MK20DX256) and Teensy 3.2 (MK20DX256) Breadboard pin assignments
25
+* Requires the Teensyduino software with Teensy 3.1 or Teensy 3.2 selected in Arduino IDE!
26
+* http://www.pjrc.com/teensy/teensyduino.html
27
+****************************************************************************************/
28
+
29
+#if !IS_32BIT_TEENSY
30
+  #error "Oops!  Make sure you have 'Teensy 3.1' or 'Teensy 3.2' selected from the 'Tools -> Boards' menu."
31
+#endif
32
+
33
+#if IS_TEENSY32
34
+  #define BOARD_NAME "Teensy3.2"
35
+#endif
36
+
37
+#define AT90USB 1286   // Disable MarlinSerial etc.
38
+#define USBCON //1286  // Disable MarlinSerial etc.
39
+
40
+//
41
+// Limit Switches
42
+//
43
+#define X_STOP_PIN         3
44
+#define Y_STOP_PIN         4
45
+#define Z_STOP_PIN         5
46
+
47
+//
48
+// Steppers
49
+//
50
+#define X_STEP_PIN         5
51
+#define X_DIR_PIN          6
52
+#define X_ENABLE_PIN       2
53
+
54
+#define Y_STEP_PIN         7
55
+#define Y_DIR_PIN          8
56
+#define Y_ENABLE_PIN       2
57
+
58
+#define Z_STEP_PIN         9
59
+#define Z_DIR_PIN          10
60
+#define Z_ENABLE_PIN       2
61
+
62
+#define E0_STEP_PIN        11
63
+#define E0_DIR_PIN         12
64
+#define E0_ENABLE_PIN      2
65
+
66
+// #define E1_STEP_PIN        33
67
+// #define E1_DIR_PIN         34
68
+// #define E1_ENABLE_PIN      35
69
+
70
+#define HEATER_0_PIN       20
71
+// #define HEATER_1_PIN       36
72
+#define HEATER_BED_PIN     21
73
+#ifndef FAN_PIN
74
+  #define FAN_PIN          22
75
+#endif
76
+
77
+#define TEMP_0_PIN         14   // Extruder / Analog pin numbering: 2 => A2
78
+// #define TEMP_1_PIN          0
79
+#define TEMP_BED_PIN       15   // Bed / Analog pin numbering
80
+
81
+// #define SDSS               16   // 8
82
+#define LED_PIN            13
83
+#define PS_ON_PIN          -1
84
+#define ALARM_PIN          -1
85
+
86
+// #define FILWIDTH_PIN        6
87
+// #define SOL1_PIN           28
88
+
89
+#if 0
90
+// Pretty sure this is obsolete!
91
+// Please use Marlin 1.1.x pins files as reference for new pins files.
92
+#ifndef SDSUPPORT
93
+  // these are defined in the SD library if building with SD support
94
+  #define SCK_PIN          13
95
+  #define MISO_PIN         12
96
+  #define MOSI_PIN         11
97
+#endif
98
+#endif
99
+/*
100
+#ifdef ULTRA_LCD
101
+  #define LCD_PINS_RS      40
102
+  #define LCD_PINS_ENABLE  41
103
+  #define LCD_PINS_D4      42
104
+  #define LCD_PINS_D5      43
105
+  #define LCD_PINS_D6      44
106
+  #define LCD_PINS_D7      45
107
+  #define BTN_EN1          46
108
+  #define BTN_EN2          47
109
+  #define BTN_ENC          48
110
+#endif
111
+*/

Loading…
Cancel
Save