Browse Source

STM32F7 HAL using the official STM32 Arduino Core (#11750)

Scott Lahteine 6 years ago
parent
commit
348004c34f
No account linked to committer's email address

+ 126
- 0
Marlin/src/HAL/HAL_STM32/HAL.cpp View File

@@ -0,0 +1,126 @@
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
+ * Copyright (c) 2017 Victor Perez
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+
24
+#ifdef ARDUINO_ARCH_STM32
25
+
26
+// --------------------------------------------------------------------------
27
+// Includes
28
+// --------------------------------------------------------------------------
29
+
30
+#include "HAL.h"
31
+
32
+#if ENABLED(EEPROM_EMULATED_WITH_SRAM)
33
+  #if STM32F7xx
34
+    #include "stm32f7xx_ll_pwr.h"
35
+  #else
36
+    #error "EEPROM_EMULATED_WITH_SRAM is currently only supported for STM32F7xx"
37
+  #endif
38
+#endif // EEPROM_EMULATED_WITH_SRAM
39
+
40
+// --------------------------------------------------------------------------
41
+// Externals
42
+// --------------------------------------------------------------------------
43
+
44
+// --------------------------------------------------------------------------
45
+// Local defines
46
+// --------------------------------------------------------------------------
47
+
48
+// --------------------------------------------------------------------------
49
+// Types
50
+// --------------------------------------------------------------------------
51
+
52
+// --------------------------------------------------------------------------
53
+// Variables
54
+// --------------------------------------------------------------------------
55
+
56
+// --------------------------------------------------------------------------
57
+// Public Variables
58
+// --------------------------------------------------------------------------
59
+
60
+uint16_t HAL_adc_result;
61
+
62
+// --------------------------------------------------------------------------
63
+// Private Variables
64
+// --------------------------------------------------------------------------
65
+
66
+// --------------------------------------------------------------------------
67
+// Function prototypes
68
+// --------------------------------------------------------------------------
69
+
70
+// --------------------------------------------------------------------------
71
+// Private functions
72
+// --------------------------------------------------------------------------
73
+
74
+// --------------------------------------------------------------------------
75
+// Public functions
76
+// --------------------------------------------------------------------------
77
+
78
+// HAL initialization task
79
+void HAL_init(void) {
80
+
81
+  #if ENABLED(SDSUPPORT)
82
+    OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
83
+  #endif
84
+
85
+  #if ENABLED(EEPROM_EMULATED_WITH_SRAM)
86
+  // Enable access to backup SRAM
87
+  __HAL_RCC_PWR_CLK_ENABLE();
88
+  HAL_PWR_EnableBkUpAccess();
89
+  __HAL_RCC_BKPSRAM_CLK_ENABLE();
90
+
91
+  // Enable backup regulator
92
+  LL_PWR_EnableBkUpRegulator();
93
+  // Wait until backup regulator is initialized
94
+  while (!LL_PWR_IsActiveFlag_BRR());
95
+  #endif // EEPROM_EMULATED_SRAM
96
+}
97
+
98
+void HAL_clear_reset_source(void) { __HAL_RCC_CLEAR_RESET_FLAGS(); }
99
+
100
+uint8_t HAL_get_reset_source (void) {
101
+  if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET) return RST_WATCHDOG;
102
+  if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET)  return RST_SOFTWARE;
103
+  if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET)  return RST_EXTERNAL;
104
+  if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET)  return RST_POWER_ON;
105
+  return 0;
106
+}
107
+
108
+void _delay_ms(const int delay_ms) { delay(delay_ms); }
109
+
110
+extern "C" {
111
+  extern unsigned int _ebss; // end of bss section
112
+}
113
+
114
+// --------------------------------------------------------------------------
115
+// ADC
116
+// --------------------------------------------------------------------------
117
+
118
+void HAL_adc_start_conversion(const uint8_t adc_pin) {
119
+  HAL_adc_result = analogRead(adc_pin);
120
+}
121
+
122
+uint16_t HAL_adc_get_result(void) {
123
+  return HAL_adc_result;
124
+}
125
+
126
+#endif // ARDUINO_ARCH_STM32

+ 220
- 0
Marlin/src/HAL/HAL_STM32/HAL.h View File

@@ -0,0 +1,220 @@
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
+ * Copyright (c) 2017 Victor Perez
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+#pragma once
24
+
25
+#define CPU_32_BIT
26
+#undef DEBUG_NONE
27
+
28
+#ifndef vsnprintf_P
29
+  #define vsnprintf_P vsnprintf
30
+#endif
31
+
32
+// --------------------------------------------------------------------------
33
+// Includes
34
+// --------------------------------------------------------------------------
35
+
36
+#include <stdint.h>
37
+
38
+#include "Arduino.h"
39
+
40
+#ifdef USBCON
41
+  #include <USBSerial.h>
42
+#endif
43
+
44
+#include "../shared/math_32bit.h"
45
+#include "../shared/HAL_SPI.h"
46
+#include "fastio_STM32.h"
47
+#include "watchdog_STM32.h"
48
+
49
+#include "HAL_timers_STM32.h"
50
+
51
+// --------------------------------------------------------------------------
52
+// Defines
53
+// --------------------------------------------------------------------------
54
+
55
+#if SERIAL_PORT == 0
56
+  #error "Serial port 0 does not exist"
57
+#endif
58
+
59
+#if !WITHIN(SERIAL_PORT, -1, 6)
60
+  #error "SERIAL_PORT must be from -1 to 6"
61
+#endif
62
+#if SERIAL_PORT == -1
63
+  #define MYSERIAL0 SerialUSB
64
+#elif SERIAL_PORT == 1
65
+  #define MYSERIAL0 Serial1
66
+#elif SERIAL_PORT == 2
67
+  #define MYSERIAL0 Serial2
68
+#elif SERIAL_PORT == 3
69
+  #define MYSERIAL0 Serial3
70
+#elif SERIAL_PORT == 4
71
+  #define MYSERIAL0 Serial4
72
+#elif SERIAL_PORT == 5
73
+  #define MYSERIAL0 Serial5
74
+#elif SERIAL_PORT == 6
75
+  #define MYSERIAL0 Serial6
76
+#endif
77
+
78
+#ifdef SERIAL_PORT_2
79
+  #if SERIAL_PORT_2 == 0
80
+    #error "Serial port 0 does not exist"
81
+  #endif
82
+
83
+  #if !WITHIN(SERIAL_PORT_2, -1, 6)
84
+    #error "SERIAL_PORT_2 must be from -1 to 6"
85
+  #elif SERIAL_PORT_2 == SERIAL_PORT
86
+    #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
87
+  #endif
88
+  #define NUM_SERIAL 2
89
+  #if SERIAL_PORT_2 == -1
90
+    #define MYSERIAL1 Serial0 // TODO Once CDC is supported
91
+  #elif SERIAL_PORT_2 == 1
92
+    #define MYSERIAL1 Serial1
93
+  #elif SERIAL_PORT_2 == 2
94
+    #define MYSERIAL1 Serial2
95
+  #elif SERIAL_PORT_2 == 3
96
+    #define MYSERIAL1 Serial3
97
+  #elif SERIAL_PORT_2 == 4
98
+    #define MYSERIAL1 Serial4
99
+  #elif SERIAL_PORT_2 == 5
100
+    #define MYSERIAL1 Serial5
101
+  #elif SERIAL_PORT_2 == 6
102
+    #define MYSERIAL1 Serial6
103
+  #endif
104
+#else
105
+  #define NUM_SERIAL 1
106
+#endif
107
+
108
+#define _BV(b) (1 << (b))
109
+
110
+/**
111
+ * TODO: review this to return 1 for pins that are not analog input
112
+ */
113
+#ifndef analogInputToDigitalPin
114
+  #define analogInputToDigitalPin(p) (p)
115
+#endif
116
+
117
+#define CRITICAL_SECTION_START  uint32_t primask = __get_PRIMASK(); __disable_irq()
118
+#define CRITICAL_SECTION_END    if (!primask) __enable_irq()
119
+#define ISRS_ENABLED() (!__get_PRIMASK())
120
+#define ENABLE_ISRS()  __enable_irq()
121
+#define DISABLE_ISRS() __disable_irq()
122
+#define cli() __disable_irq()
123
+#define sei() __enable_irq()
124
+
125
+// On AVR this is in math.h?
126
+#define square(x) ((x)*(x))
127
+
128
+#ifndef strncpy_P
129
+  #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
130
+#endif
131
+
132
+// Fix bug in pgm_read_ptr
133
+#undef pgm_read_ptr
134
+#define pgm_read_ptr(addr) (*(addr))
135
+
136
+#define RST_POWER_ON   1
137
+#define RST_EXTERNAL   2
138
+#define RST_BROWN_OUT  4
139
+#define RST_WATCHDOG   8
140
+#define RST_JTAG       16
141
+#define RST_SOFTWARE   32
142
+#define RST_BACKUP     64
143
+
144
+// --------------------------------------------------------------------------
145
+// Types
146
+// --------------------------------------------------------------------------
147
+
148
+typedef int8_t pin_t;
149
+
150
+#define HAL_SERVO_LIB libServo
151
+
152
+// --------------------------------------------------------------------------
153
+// Public Variables
154
+// --------------------------------------------------------------------------
155
+
156
+/** result of last ADC conversion */
157
+extern uint16_t HAL_adc_result;
158
+
159
+// --------------------------------------------------------------------------
160
+// Public functions
161
+// --------------------------------------------------------------------------
162
+
163
+// Memory related
164
+#define __bss_end __bss_end__
165
+
166
+// Enable hooks into  setup for HAL
167
+#define HAL_INIT 1
168
+void HAL_init(void);
169
+
170
+/** clear reset reason */
171
+void HAL_clear_reset_source (void);
172
+
173
+/** reset reason */
174
+uint8_t HAL_get_reset_source (void);
175
+
176
+void _delay_ms(const int delay);
177
+
178
+extern "C" char* _sbrk(int incr);
179
+
180
+static int freeMemory() {
181
+  volatile char top;
182
+  return &top - reinterpret_cast<char*>(_sbrk(0));
183
+}
184
+
185
+// SPI: Extended functions which take a channel number (hardware SPI only)
186
+/** Write single byte to specified SPI channel */
187
+void spiSend(uint32_t chan, byte b);
188
+/** Write buffer to specified SPI channel */
189
+void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
190
+/** Read single byte from specified SPI channel */
191
+uint8_t spiRec(uint32_t chan);
192
+
193
+
194
+// EEPROM
195
+
196
+/**
197
+ * Wire library should work for i2c eeproms.
198
+ */
199
+void eeprom_write_byte(unsigned char *pos, unsigned char value);
200
+unsigned char eeprom_read_byte(unsigned char *pos);
201
+void eeprom_read_block (void *__dst, const void *__src, size_t __n);
202
+void eeprom_update_block (const void *__src, void *__dst, size_t __n);
203
+
204
+// ADC
205
+
206
+#define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
207
+
208
+inline void HAL_adc_init(void) {}
209
+
210
+#define HAL_START_ADC(pin)  HAL_adc_start_conversion(pin)
211
+#define HAL_READ_ADC()      HAL_adc_result
212
+#define HAL_ADC_READY()     true
213
+
214
+void HAL_adc_start_conversion(const uint8_t adc_pin);
215
+
216
+uint16_t HAL_adc_get_result(void);
217
+
218
+#define GET_PIN_MAP_PIN(index) index
219
+#define GET_PIN_MAP_INDEX(pin) pin
220
+#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)

+ 57
- 0
Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.cpp View File

@@ -0,0 +1,57 @@
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
+ * Copyright (C) 2017 Victor Perez
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+#ifdef ARDUINO_ARCH_STM32
24
+
25
+#include "../../inc/MarlinConfig.h"
26
+
27
+#if HAS_SERVOS
28
+
29
+#include "HAL_Servo_STM32.h"
30
+
31
+uint8_t servoPin[MAX_SERVOS] = { 0 };
32
+
33
+int8_t libServo::attach(const int pin) {
34
+  if (this->servoIndex >= MAX_SERVOS) return -1;
35
+  if (pin > 0) servoPin[this->servoIndex] = pin;
36
+  return Servo::attach(servoPin[this->servoIndex]);
37
+}
38
+
39
+int8_t libServo::attach(const int pin, const int min, const int max) {
40
+  if (pin > 0) servoPin[this->servoIndex] = pin;
41
+  return Servo::attach(servoPin[this->servoIndex], min, max);
42
+}
43
+
44
+void libServo::move(const int value) {
45
+  constexpr uint16_t servo_delay[] = SERVO_DELAY;
46
+  static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
47
+  if (this->attach(0) >= 0) {
48
+    this->write(value);
49
+    safe_delay(servo_delay[this->servoIndex]);
50
+    #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
51
+      this->detach();
52
+    #endif
53
+  }
54
+}
55
+#endif // HAS_SERVOS
56
+
57
+#endif // ARDUINO_ARCH_STM32

+ 36
- 0
Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.h View File

@@ -0,0 +1,36 @@
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
+ * Copyright (C) 2017 Victor Perez
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
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, max_ticks;
35
+    uint8_t servoIndex;               // index into the channel data for this servo
36
+};

+ 159
- 0
Marlin/src/HAL/HAL_STM32/HAL_spi_STM32.cpp View File

@@ -0,0 +1,159 @@
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
+ * Copyright (C) 2017 Victor Perez
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+#ifdef ARDUINO_ARCH_STM32
24
+
25
+// --------------------------------------------------------------------------
26
+// Includes
27
+// --------------------------------------------------------------------------
28
+
29
+#include "HAL.h"
30
+#include "../shared/HAL_SPI.h"
31
+#include "pins_arduino.h"
32
+#include "spi_pins.h"
33
+#include "../../core/macros.h"
34
+
35
+#include <SPI.h>
36
+
37
+// --------------------------------------------------------------------------
38
+// Public Variables
39
+// --------------------------------------------------------------------------
40
+
41
+static SPISettings spiConfig;
42
+
43
+// --------------------------------------------------------------------------
44
+// Public functions
45
+// --------------------------------------------------------------------------
46
+
47
+#if ENABLED(SOFTWARE_SPI)
48
+  // --------------------------------------------------------------------------
49
+  // Software SPI
50
+  // --------------------------------------------------------------------------
51
+  #error "Software SPI not supported for STM32F7. Use Hardware SPI."
52
+
53
+#else
54
+
55
+// --------------------------------------------------------------------------
56
+// Hardware SPI
57
+// --------------------------------------------------------------------------
58
+
59
+/**
60
+ * VGPV SPI speed start and PCLK2/2, by default 108/2 = 54Mhz
61
+ */
62
+
63
+/**
64
+ * @brief  Begin SPI port setup
65
+ *
66
+ * @return Nothing
67
+ *
68
+ * @details Only configures SS pin since stm32duino creates and initialize the SPI object
69
+ */
70
+void spiBegin(void) {
71
+  #if !PIN_EXISTS(SS)
72
+    #error "SS_PIN not defined!"
73
+  #endif
74
+
75
+  SET_OUTPUT(SS_PIN);
76
+  WRITE(SS_PIN, HIGH);
77
+}
78
+
79
+/** Configure SPI for specified SPI speed */
80
+void spiInit(uint8_t spiRate) {
81
+  // Use datarates Marlin uses
82
+  uint32_t clock;
83
+  switch (spiRate) {
84
+  case SPI_FULL_SPEED:    clock = 20000000; break; // 13.9mhz=20000000  6.75mhz=10000000  3.38mhz=5000000  .833mhz=1000000
85
+  case SPI_HALF_SPEED:    clock =  5000000; break;
86
+  case SPI_QUARTER_SPEED: clock =  2500000; break;
87
+  case SPI_EIGHTH_SPEED:  clock =  1250000; break;
88
+  case SPI_SPEED_5:       clock =   625000; break;
89
+  case SPI_SPEED_6:       clock =   300000; break;
90
+  default:
91
+    clock = 4000000; // Default from the SPI library
92
+  }
93
+  spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
94
+  SPI.begin();
95
+}
96
+
97
+/**
98
+ * @brief  Receives a single byte from the SPI port.
99
+ *
100
+ * @return Byte received
101
+ *
102
+ * @details
103
+ */
104
+uint8_t spiRec(void) {
105
+  SPI.beginTransaction(spiConfig);
106
+  uint8_t returnByte = SPI.transfer(0xFF);
107
+  SPI.endTransaction();
108
+  return returnByte;
109
+}
110
+
111
+/**
112
+ * @brief  Receives a number of bytes from the SPI port to a buffer
113
+ *
114
+ * @param  buf   Pointer to starting address of buffer to write to.
115
+ * @param  nbyte Number of bytes to receive.
116
+ * @return Nothing
117
+ *
118
+ * @details Uses DMA
119
+ */
120
+void spiRead(uint8_t* buf, uint16_t nbyte) {
121
+  if (nbyte == 0) return;
122
+  SPI.beginTransaction(spiConfig);
123
+  for (int i = 0; i < nbyte; i++) {
124
+    buf[i] = SPI.transfer(0xFF);
125
+  }
126
+  SPI.endTransaction();
127
+}
128
+
129
+/**
130
+ * @brief  Sends a single byte on SPI port
131
+ *
132
+ * @param  b Byte to send
133
+ *
134
+ * @details
135
+ */
136
+void spiSend(uint8_t b) {
137
+  SPI.beginTransaction(spiConfig);
138
+  SPI.transfer(b);
139
+  SPI.endTransaction();
140
+}
141
+
142
+/**
143
+ * @brief  Write token and then write from 512 byte buffer to SPI (for SD card)
144
+ *
145
+ * @param  buf   Pointer with buffer start address
146
+ * @return Nothing
147
+ *
148
+ * @details Use DMA
149
+ */
150
+void spiSendBlock(uint8_t token, const uint8_t* buf) {
151
+  SPI.beginTransaction(spiConfig);
152
+  SPI.transfer(token);
153
+  SPI.transfer((uint8_t*)buf, (uint8_t*)0, 512);
154
+  SPI.endTransaction();
155
+}
156
+
157
+#endif // SOFTWARE_SPI
158
+
159
+#endif // ARDUINO_ARCH_STM32

+ 117
- 0
Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.cpp View File

@@ -0,0 +1,117 @@
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
+#ifdef ARDUINO_ARCH_STM32
23
+
24
+// --------------------------------------------------------------------------
25
+// Includes
26
+// --------------------------------------------------------------------------
27
+
28
+#include "HAL.h"
29
+
30
+#include "HAL_timers_STM32.h"
31
+
32
+// --------------------------------------------------------------------------
33
+// Externals
34
+// --------------------------------------------------------------------------
35
+
36
+// --------------------------------------------------------------------------
37
+// Local defines
38
+// --------------------------------------------------------------------------
39
+
40
+#define NUM_HARDWARE_TIMERS 2
41
+
42
+//#define PRESCALER 1
43
+// --------------------------------------------------------------------------
44
+// Types
45
+// --------------------------------------------------------------------------
46
+
47
+// --------------------------------------------------------------------------
48
+// Public Variables
49
+// --------------------------------------------------------------------------
50
+
51
+// --------------------------------------------------------------------------
52
+// Private Variables
53
+// --------------------------------------------------------------------------
54
+
55
+stm32f4_timer_t TimerHandle[NUM_HARDWARE_TIMERS];
56
+
57
+// --------------------------------------------------------------------------
58
+// Function prototypes
59
+// --------------------------------------------------------------------------
60
+
61
+// --------------------------------------------------------------------------
62
+// Private functions
63
+// --------------------------------------------------------------------------
64
+
65
+// --------------------------------------------------------------------------
66
+// Public functions
67
+// --------------------------------------------------------------------------
68
+
69
+bool timers_initialised[NUM_HARDWARE_TIMERS] = {false};
70
+
71
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
72
+
73
+  if (!timers_initialised[timer_num]) {
74
+    constexpr uint32_t step_prescaler = STEPPER_TIMER_PRESCALE - 1,
75
+                       temp_prescaler = TEMP_TIMER_PRESCALE - 1;
76
+    switch (timer_num) {
77
+      case STEP_TIMER_NUM:
78
+        // STEPPER TIMER - use a 32bit timer if possible
79
+        TimerHandle[timer_num].timer = STEP_TIMER_DEV;
80
+        TimerHandle[timer_num].irqHandle = Step_Handler;
81
+        TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / step_prescaler) / frequency) - 1, step_prescaler);
82
+        HAL_NVIC_SetPriority(STEP_TIMER_IRQ_NAME, 6, 0);
83
+        break;
84
+
85
+      case TEMP_TIMER_NUM:
86
+        // TEMP TIMER - any available 16bit Timer
87
+        TimerHandle[timer_num].timer = TEMP_TIMER_DEV;
88
+        TimerHandle[timer_num].irqHandle = Temp_Handler;
89
+        TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / temp_prescaler) / frequency) - 1, temp_prescaler);
90
+        HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, 2, 0);
91
+        break;
92
+    }
93
+    timers_initialised[timer_num] = true;
94
+  }
95
+}
96
+
97
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
98
+  const IRQn_Type IRQ_Id = IRQn_Type(getTimerIrq(TimerHandle[timer_num].timer));
99
+  HAL_NVIC_EnableIRQ(IRQ_Id);
100
+}
101
+
102
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
103
+  const IRQn_Type IRQ_Id = IRQn_Type(getTimerIrq(TimerHandle[timer_num].timer));
104
+  HAL_NVIC_DisableIRQ(IRQ_Id);
105
+
106
+  // We NEED memory barriers to ensure Interrupts are actually disabled!
107
+  // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
108
+  __DSB();
109
+  __ISB();
110
+}
111
+
112
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
113
+  const uint32_t IRQ_Id = getTimerIrq(TimerHandle[timer_num].timer);
114
+  return NVIC->ISER[IRQ_Id >> 5] & _BV32(IRQ_Id & 0x1F);
115
+}
116
+
117
+#endif // ARDUINO_ARCH_STM32

+ 168
- 0
Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.h View File

@@ -0,0 +1,168 @@
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) 2017 Victor Perez
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
+#pragma once
23
+
24
+// --------------------------------------------------------------------------
25
+// Includes
26
+// --------------------------------------------------------------------------
27
+
28
+#include <stdint.h>
29
+
30
+// --------------------------------------------------------------------------
31
+// Defines
32
+// --------------------------------------------------------------------------
33
+
34
+#define FORCE_INLINE __attribute__((always_inline)) inline
35
+
36
+#define hal_timer_t uint32_t  // TODO: One is 16-bit, one 32-bit - does this need to be checked?
37
+#define HAL_TIMER_TYPE_MAX 0xFFFF
38
+
39
+#ifdef STM32F0xx
40
+
41
+  #define HAL_TIMER_RATE         (HAL_RCC_GetSysClockFreq())  // frequency of timer peripherals
42
+  #define TEMP_TIMER_PRESCALE    666  // prescaler for setting temperature timer, 72Khz
43
+  #define STEPPER_TIMER_PRESCALE 24   // prescaler for setting stepper timer, 2Mhz
44
+
45
+  #define STEP_TIMER 16
46
+  #define TEMP_TIMER 17
47
+
48
+#elif defined STM32F1xx
49
+
50
+  #define HAL_TIMER_RATE         (HAL_RCC_GetPCLK2Freq())  // frequency of timer peripherals
51
+  #define TEMP_TIMER_PRESCALE    1000 // prescaler for setting temperature timer, 72Khz
52
+  #define STEPPER_TIMER_PRESCALE 36   // prescaler for setting stepper timer, 2Mhz.
53
+
54
+  #define STEP_TIMER 4
55
+  #define TEMP_TIMER 2
56
+
57
+#elif defined STM32F4xx
58
+
59
+  #define HAL_TIMER_RATE         (HAL_RCC_GetPCLK2Freq())  // frequency of timer peripherals
60
+  #define TEMP_TIMER_PRESCALE    2333 // prescaler for setting temperature timer, 72Khz
61
+  #define STEPPER_TIMER_PRESCALE 84   // prescaler for setting stepper timer, 2Mhz
62
+
63
+  #define STEP_TIMER 4
64
+  #define TEMP_TIMER 5
65
+
66
+#elif defined STM32F7xx
67
+
68
+  #define HAL_TIMER_RATE         (HAL_RCC_GetSysClockFreq()/2)  // frequency of timer peripherals
69
+  #define TEMP_TIMER_PRESCALE    1500 // prescaler for setting temperature timer, 72Khz
70
+  #define STEPPER_TIMER_PRESCALE 54   // prescaler for setting stepper timer, 2Mhz.
71
+
72
+  #define STEP_TIMER 5
73
+  #define TEMP_TIMER 7
74
+
75
+  #if MB(REMRAM_V1)
76
+  #define STEP_TIMER 2
77
+  #endif
78
+
79
+#endif
80
+
81
+#define STEP_TIMER_NUM 0  // index of timer to use for stepper
82
+#define TEMP_TIMER_NUM 1  // index of timer to use for temperature
83
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
84
+
85
+#define STEPPER_TIMER_RATE     (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer
86
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
87
+
88
+#define TEMP_TIMER_FREQUENCY  1000  // temperature interrupt frequency
89
+
90
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
91
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
92
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
93
+
94
+#define __TIMER_DEV(X) TIM##X
95
+#define _TIMER_DEV(X) __TIMER_DEV(X)
96
+#define STEP_TIMER_DEV _TIMER_DEV(STEP_TIMER)
97
+#define TEMP_TIMER_DEV _TIMER_DEV(TEMP_TIMER)
98
+
99
+#define __TIMER_CALLBACK(X) TIM##X##_IRQHandler
100
+#define _TIMER_CALLBACK(X) __TIMER_CALLBACK(X)
101
+
102
+#define STEP_TIMER_CALLBACK _TIMER_CALLBACK(STEP_TIMER)
103
+#define TEMP_TIMER_CALLBACK _TIMER_CALLBACK(TEMP_TIMER)
104
+
105
+#define __TIMER_IRQ_NAME(X) TIM##X##_IRQn
106
+#define _TIMER_IRQ_NAME(X) __TIMER_IRQ_NAME(X)
107
+
108
+#define STEP_TIMER_IRQ_NAME _TIMER_IRQ_NAME(STEP_TIMER)
109
+#define TEMP_TIMER_IRQ_NAME _TIMER_IRQ_NAME(TEMP_TIMER)
110
+
111
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
112
+#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
113
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
114
+
115
+#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
116
+#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
117
+
118
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
119
+#define TEMP_ISR_ENABLED() HAL_timer_interrupt_enabled(TEMP_TIMER_NUM)
120
+
121
+extern void Step_Handler(stimer_t *htim);
122
+extern void Temp_Handler(stimer_t *htim);
123
+#define HAL_STEP_TIMER_ISR void Step_Handler(stimer_t *htim)
124
+#define HAL_TEMP_TIMER_ISR void Temp_Handler(stimer_t *htim)
125
+
126
+// --------------------------------------------------------------------------
127
+// Types
128
+// --------------------------------------------------------------------------
129
+
130
+typedef stimer_t stm32f4_timer_t;
131
+
132
+// --------------------------------------------------------------------------
133
+// Public Variables
134
+// --------------------------------------------------------------------------
135
+
136
+extern stm32f4_timer_t TimerHandle[];
137
+
138
+// --------------------------------------------------------------------------
139
+// Public functions
140
+// --------------------------------------------------------------------------
141
+
142
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
143
+void HAL_timer_enable_interrupt(const uint8_t timer_num);
144
+void HAL_timer_disable_interrupt(const uint8_t timer_num);
145
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
146
+
147
+FORCE_INLINE static uint32_t HAL_timer_get_count(const uint8_t timer_num) {
148
+  return __HAL_TIM_GET_COUNTER(&TimerHandle[timer_num].handle);
149
+}
150
+
151
+FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
152
+  __HAL_TIM_SET_AUTORELOAD(&TimerHandle[timer_num].handle, compare);
153
+  if (HAL_timer_get_count(timer_num) >= compare)
154
+    TimerHandle[timer_num].handle.Instance->EGR |= TIM_EGR_UG; // Generate an immediate update interrupt
155
+}
156
+
157
+FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
158
+  return __HAL_TIM_GET_AUTORELOAD(&TimerHandle[timer_num].handle);
159
+}
160
+
161
+FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
162
+  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
163
+  if (HAL_timer_get_compare(timer_num) < mincmp)
164
+    HAL_timer_set_compare(timer_num, mincmp);
165
+}
166
+
167
+#define HAL_timer_isr_prologue(TIMER_NUM)
168
+#define HAL_timer_isr_epilogue(TIMER_NUM)

+ 11
- 0
Marlin/src/HAL/HAL_STM32/README.md View File

@@ -0,0 +1,11 @@
1
+# Generic STM32 HAL based on the stm32duino core
2
+
3
+This HAL is intended to act as the generic STM32 HAL for all STM32 chips (The whole F, H and L family).
4
+
5
+Currently it supports:
6
+ * STM32F0xx
7
+ * STM32F1xx
8
+ * STM32F4xx
9
+ * STM32F7xx
10
+
11
+Targeting the official [Arduino STM32 Core](https://github.com/stm32duino/Arduino_Core_STM32).

+ 71
- 0
Marlin/src/HAL/HAL_STM32/SanityCheck.h View File

@@ -0,0 +1,71 @@
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
+#pragma once
23
+
24
+/**
25
+ * Test Re-ARM specific configuration values for errors at compile-time.
26
+ */
27
+#if ENABLED(SPINDLE_LASER_ENABLE)
28
+  #if !PIN_EXISTS(SPINDLE_LASER_ENABLE)
29
+    #error "SPINDLE_LASER_ENABLE requires SPINDLE_LASER_ENABLE_PIN."
30
+  #elif SPINDLE_DIR_CHANGE && !PIN_EXISTS(SPINDLE_DIR)
31
+    #error "SPINDLE_DIR_PIN not defined."
32
+  #elif ENABLED(SPINDLE_LASER_PWM) && PIN_EXISTS(SPINDLE_LASER_PWM)
33
+    #if !PWM_PIN(SPINDLE_LASER_PWM_PIN)
34
+      #error "SPINDLE_LASER_PWM_PIN not assigned to a PWM pin."
35
+    #elif !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11)
36
+      #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
37
+    #elif SPINDLE_LASER_POWERUP_DELAY < 1
38
+      #error "SPINDLE_LASER_POWERUP_DELAY must be greater than 0."
39
+    #elif SPINDLE_LASER_POWERDOWN_DELAY < 1
40
+      #error "SPINDLE_LASER_POWERDOWN_DELAY must be greater than 0."
41
+    #elif !defined(SPINDLE_LASER_PWM_INVERT)
42
+      #error "SPINDLE_LASER_PWM_INVERT missing."
43
+    #elif !defined(SPEED_POWER_SLOPE) || !defined(SPEED_POWER_INTERCEPT) || !defined(SPEED_POWER_MIN) || !defined(SPEED_POWER_MAX)
44
+      #error "SPINDLE_LASER_PWM equation constant(s) missing."
45
+    #elif PIN_EXISTS(CASE_LIGHT) && SPINDLE_LASER_PWM_PIN == CASE_LIGHT_PIN
46
+      #error "SPINDLE_LASER_PWM_PIN is used by CASE_LIGHT_PIN."
47
+    #elif PIN_EXISTS(E0_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E0_AUTO_FAN_PIN
48
+      #error "SPINDLE_LASER_PWM_PIN is used by E0_AUTO_FAN_PIN."
49
+    #elif PIN_EXISTS(E1_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E1_AUTO_FAN_PIN
50
+      #error "SPINDLE_LASER_PWM_PIN is used by E1_AUTO_FAN_PIN."
51
+    #elif PIN_EXISTS(E2_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E2_AUTO_FAN_PIN
52
+      #error "SPINDLE_LASER_PWM_PIN is used by E2_AUTO_FAN_PIN."
53
+    #elif PIN_EXISTS(E3_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E3_AUTO_FAN_PIN
54
+      #error "SPINDLE_LASER_PWM_PIN is used by E3_AUTO_FAN_PIN."
55
+    #elif PIN_EXISTS(E4_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E4_AUTO_FAN_PIN
56
+      #error "SPINDLE_LASER_PWM_PIN is used by E4_AUTO_FAN_PIN."
57
+    #elif PIN_EXISTS(FAN) && SPINDLE_LASER_PWM_PIN == FAN_PIN
58
+      #error "SPINDLE_LASER_PWM_PIN is used FAN_PIN."
59
+    #elif PIN_EXISTS(FAN1) && SPINDLE_LASER_PWM_PIN == FAN1_PIN
60
+      #error "SPINDLE_LASER_PWM_PIN is used FAN1_PIN."
61
+    #elif PIN_EXISTS(FAN2) && SPINDLE_LASER_PWM_PIN == FAN2_PIN
62
+      #error "SPINDLE_LASER_PWM_PIN is used FAN2_PIN."
63
+    #elif PIN_EXISTS(CONTROLLERFAN) && SPINDLE_LASER_PWM_PIN == CONTROLLERFAN_PIN
64
+      #error "SPINDLE_LASER_PWM_PIN is used by CONTROLLERFAN_PIN."
65
+    #endif
66
+  #endif
67
+#endif // SPINDLE_LASER_ENABLE
68
+
69
+#if ENABLED(EMERGENCY_PARSER)
70
+  #error "EMERGENCY_PARSER is not yet implemented for STM32. Disable EMERGENCY_PARSER to continue."
71
+#endif

+ 59
- 0
Marlin/src/HAL/HAL_STM32/endstop_interrupts.h View File

@@ -0,0 +1,59 @@
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
+ * Copyright (C) 2017 Victor Perez
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+#pragma once
24
+
25
+#include "../../module/endstops.h"
26
+
27
+// One ISR for all EXT-Interrupts
28
+void endstop_ISR(void) { endstops.update(); }
29
+
30
+void setup_endstop_interrupts(void) {
31
+  #if HAS_X_MAX
32
+    attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE);
33
+  #endif
34
+  #if HAS_X_MIN
35
+    attachInterrupt(X_MIN_PIN, endstop_ISR, CHANGE);
36
+  #endif
37
+  #if HAS_Y_MAX
38
+    attachInterrupt(Y_MAX_PIN, endstop_ISR, CHANGE);
39
+  #endif
40
+  #if HAS_Y_MIN
41
+    attachInterrupt(Y_MIN_PIN, endstop_ISR, CHANGE);
42
+  #endif
43
+  #if HAS_Z_MAX
44
+    attachInterrupt(Z_MAX_PIN, endstop_ISR, CHANGE);
45
+  #endif
46
+  #if HAS_Z_MIN
47
+    attachInterrupt(Z_MIN_PIN, endstop_ISR, CHANGE);
48
+  #endif
49
+  #if HAS_Z2_MAX
50
+    attachInterrupt(Z2_MAX_PIN, endstop_ISR, CHANGE);
51
+  #endif
52
+  #if HAS_Z2_MIN
53
+    attachInterrupt(Z2_MIN_PIN, endstop_ISR, CHANGE);
54
+  #endif
55
+  #if HAS_Z_MIN_PROBE_PIN
56
+    attachInterrupt(Z_MIN_PROBE_PIN, endstop_ISR, CHANGE);
57
+  #endif
58
+}
59
+

+ 53
- 0
Marlin/src/HAL/HAL_STM32/fastio_STM32.h View File

@@ -0,0 +1,53 @@
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
+ * Copyright (C) 2017 Victor Perez
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+#pragma once
24
+
25
+/**
26
+ * Fast I/O interfaces for STM32F7
27
+ * These use GPIO functions instead of Direct Port Manipulation, as on AVR.
28
+ */
29
+
30
+#define _BV(b) (1 << (b))
31
+
32
+#define USEABLE_HARDWARE_PWM(p) true
33
+
34
+#define READ(IO)                digitalRead(IO)
35
+#define WRITE(IO,V)             digitalWrite(IO,V)
36
+#define WRITE_VAR(IO,V)         WRITE(IO,V)
37
+
38
+#define _GET_MODE(IO)
39
+#define _SET_MODE(IO,M)         pinMode(IO, M)
40
+#define _SET_OUTPUT(IO)         pinMode(IO, OUTPUT)                               /*!< Output Push Pull Mode & GPIO_NOPULL   */
41
+
42
+#define OUT_WRITE(IO,V)         do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
43
+
44
+#define SET_INPUT(IO)           _SET_MODE(IO, INPUT)                              /*!< Input Floating Mode                   */
45
+#define SET_INPUT_PULLUP(IO)    _SET_MODE(IO, INPUT_PULLUP)                       /*!< Input with Pull-up activation         */
46
+#define SET_INPUT_PULLDOWN(IO)  _SET_MODE(IO, INPUT_PULLDOWN)                     /*!< Input with Pull-down activation       */
47
+#define SET_OUTPUT(IO)          OUT_WRITE(IO, LOW)
48
+
49
+#define TOGGLE(IO)              OUT_WRITE(IO, !READ(IO))
50
+
51
+#define GET_INPUT(IO)
52
+#define GET_OUTPUT(IO)
53
+#define GET_TIMER(IO)

+ 103
- 0
Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp View File

@@ -0,0 +1,103 @@
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
+ * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+#ifdef ARDUINO_ARCH_STM32
24
+
25
+#include "../../inc/MarlinConfig.h"
26
+
27
+#if ENABLED(EEPROM_SETTINGS)
28
+
29
+#include "../shared/persistent_store_api.h"
30
+
31
+#if DISABLED(EEPROM_EMULATED_WITH_SRAM)
32
+  #include <EEPROM.h>
33
+  static bool eeprom_data_written = false;
34
+#endif
35
+
36
+bool PersistentStore::access_start() {
37
+  #if DISABLED(EEPROM_EMULATED_WITH_SRAM)
38
+    eeprom_buffer_fill();
39
+  #endif
40
+  return true;
41
+}
42
+
43
+bool PersistentStore::access_finish() {
44
+  #if DISABLED(EEPROM_EMULATED_WITH_SRAM)
45
+    if (eeprom_data_written) {
46
+      eeprom_buffer_flush();
47
+      eeprom_data_written = false;
48
+    }
49
+  #endif
50
+  return true;
51
+}
52
+
53
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
54
+  while (size--) {
55
+    uint8_t v = *value;
56
+
57
+    // Save to either program flash or Backup SRAM
58
+    #if DISABLED(EEPROM_EMULATED_WITH_SRAM)
59
+      eeprom_buffered_write_byte(pos, v);
60
+    #else
61
+      *(__IO uint8_t *)(BKPSRAM_BASE + (uint8_t * const)pos) = v;
62
+    #endif
63
+
64
+    crc16(crc, &v, 1);
65
+    pos++;
66
+    value++;
67
+  };
68
+  #if DISABLED(EEPROM_EMULATED_WITH_SRAM)
69
+    eeprom_data_written = true;
70
+  #endif
71
+
72
+  return false;
73
+}
74
+
75
+bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing) {
76
+  do {
77
+    // Read from either program flash or Backup SRAM
78
+    const uint8_t c = (
79
+      #if DISABLED(EEPROM_EMULATED_WITH_SRAM)
80
+        eeprom_buffered_read_byte(pos)
81
+      #else
82
+        (*(__IO uint8_t *)(BKPSRAM_BASE + ((unsigned char*)pos)))
83
+      #endif
84
+    );
85
+
86
+    if (writing) *value = c;
87
+    crc16(crc, &c, 1);
88
+    pos++;
89
+    value++;
90
+  } while (--size);
91
+  return false;
92
+}
93
+
94
+size_t PersistentStore::capacity() {
95
+  #if DISABLED(EEPROM_EMULATED_WITH_SRAM)
96
+    return E2END + 1;
97
+  #else
98
+    return 4096; // 4kB
99
+  #endif
100
+}
101
+
102
+#endif // EEPROM_SETTINGS
103
+#endif // ARDUINO_ARCH_STM32

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

@@ -0,0 +1 @@
1
+#error "Debug pins is not yet supported for STM32!"

+ 36
- 0
Marlin/src/HAL/HAL_STM32/spi_pins.h View File

@@ -0,0 +1,36 @@
1
+/**
2
+* Marlin 3D Printer Firmware
3
+* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+*
5
+* This program is free software: you can redistribute it and/or modify
6
+* it under the terms of the GNU General Public License as published by
7
+* the Free Software Foundation, either version 3 of the License, or
8
+* (at your option) any later version.
9
+*
10
+* This program is distributed in the hope that it will be useful,
11
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+* GNU General Public License for more details.
14
+*
15
+* You should have received a copy of the GNU General Public License
16
+* along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+*
18
+*/
19
+#pragma once
20
+
21
+/**
22
+ * Define SPI Pins: SCK, MISO, MOSI, SS
23
+ *
24
+ */
25
+#ifndef SCK_PIN
26
+  #define SCK_PIN   13
27
+#endif
28
+#ifndef MISO_PIN
29
+  #define MISO_PIN  12
30
+#endif
31
+#ifndef MOSI_PIN
32
+  #define MOSI_PIN  11
33
+#endif
34
+#ifndef SS_PIN
35
+  #define SS_PIN    14
36
+#endif

+ 37
- 0
Marlin/src/HAL/HAL_STM32/watchdog_STM32.cpp 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
+#ifdef ARDUINO_ARCH_STM32
24
+
25
+#include "../../inc/MarlinConfig.h"
26
+
27
+#if ENABLED(USE_WATCHDOG)
28
+
29
+  #include "watchdog_STM32.h"
30
+  #include <IWatchdog.h>
31
+
32
+  void watchdog_init() { IWatchdog.begin(4000000); } // 4 sec timeout
33
+
34
+  void watchdog_reset() { IWatchdog.reload(); }
35
+
36
+#endif // USE_WATCHDOG
37
+#endif // ARDUINO_ARCH_STM32

+ 27
- 0
Marlin/src/HAL/HAL_STM32/watchdog_STM32.h View File

@@ -0,0 +1,27 @@
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
+#pragma once
23
+
24
+#include "../../inc/MarlinConfig.h"
25
+
26
+void watchdog_init();
27
+void watchdog_reset();

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

@@ -15,10 +15,12 @@
15 15
   #define HAL_PLATFORM HAL_LPC1768
16 16
 #elif defined(__STM32F1__) || defined(TARGET_STM32F1)
17 17
   #define HAL_PLATFORM HAL_STM32F1
18
-#elif defined(STM32F4) || defined(STM32F4xx)
18
+#elif defined(STM32GENERIC) && defined(STM32F4)
19 19
   #define HAL_PLATFORM HAL_STM32F4
20
-#elif defined(STM32F7)
20
+#elif defined(STM32GENERIC) && defined(STM32F7)
21 21
   #define HAL_PLATFORM HAL_STM32F7
22
+#elif defined(ARDUINO_ARCH_STM32)
23
+  #define HAL_PLATFORM HAL_STM32
22 24
 #elif defined(ARDUINO_ARCH_ESP32)
23 25
   #define HAL_PLATFORM HAL_ESP32
24 26
 #else

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

@@ -15,6 +15,7 @@
15 15
 #if defined(__arm__) || defined(__thumb__)
16 16
 
17 17
 #include "unwmemaccess.h"
18
+#include "../../../inc/MarlinConfig.h"
18 19
 
19 20
 /* Validate address */
20 21
 
@@ -73,7 +74,7 @@
73 74
 #define END_FLASH_ADDR    0x08080000
74 75
 #endif
75 76
 
76
-#ifdef STM32F7
77
+#if MB(THE_BORG)
77 78
 // For STM32F765 in BORG
78 79
 //  SRAM  (0x20000000 - 0x20080000) (512kb)
79 80
 //  FLASH (0x08000000 - 0x08100000) (1024kb)
@@ -84,6 +85,17 @@
84 85
 #define END_FLASH_ADDR    0x08100000
85 86
 #endif
86 87
 
88
+#if MB(REMRAM_V1)
89
+// For STM32F765VI in RemRam v1
90
+//  SRAM  (0x20000000 - 0x20080000) (512kb)
91
+//  FLASH (0x08000000 - 0x08200000) (2048kb)
92
+//
93
+#define START_SRAM_ADDR   0x20000000
94
+#define END_SRAM_ADDR     0x20080000
95
+#define START_FLASH_ADDR  0x08000000
96
+#define END_FLASH_ADDR    0x08200000
97
+#endif
98
+
87 99
 #ifdef __MK20DX256__
88 100
 // For MK20DX256 in TEENSY 3.1 or TEENSY 3.2
89 101
 //  SRAM  (0x1FFF8000 - 0x20008000) (64kb)

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

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

+ 4
- 2
Marlin/src/HAL/shared/servo.h View File

@@ -74,10 +74,12 @@
74 74
   #include "../HAL_TEENSY35_36/HAL_Servo_Teensy.h"
75 75
 #elif defined(TARGET_LPC1768)
76 76
   #include "../HAL_LPC1768/LPC1768_Servo.h"
77
-#elif defined(STM32F1) || defined(STM32F1xx)
77
+#elif defined(__STM32F1__) || defined(TARGET_STM32F1)
78 78
   #include "../HAL_STM32F1/HAL_Servo_STM32F1.h"
79
-#elif defined(STM32F4) || defined(STM32F4xx)
79
+#elif defined(STM32GENERIC) && defined(STM32F4)
80 80
   #include "../HAL_STM32F4/HAL_Servo_STM32F4.h"
81
+#elif defined(ARDUINO_ARCH_STM32)
82
+  #include "../HAL_STM32/HAL_Servo_STM32.h"
81 83
 #else
82 84
   #include <stdint.h>
83 85
 

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

@@ -236,6 +236,7 @@
236 236
 //
237 237
 
238 238
 #define BOARD_THE_BORG         1860   // THE-BORG (Power outputs: Hotend0, Hotend1, Bed, Fan)
239
+#define BOARD_REMRAM_V1        1862   // RemRam v1
239 240
 
240 241
 //
241 242
 // Espressif ESP32 WiFi

+ 4
- 0
Marlin/src/lcd/dogm/ultralcd_st7920_u8glib_rrd_AVR.cpp View File

@@ -72,6 +72,10 @@
72 72
   #define CPU_ST7920_DELAY_1 DELAY_NS(0)
73 73
   #define CPU_ST7920_DELAY_2 DELAY_NS(0)
74 74
   #define CPU_ST7920_DELAY_3 DELAY_NS(189)
75
+#elif MB(REMRAM_V1)
76
+  #define CPU_ST7920_DELAY_1 DELAY_NS(0)
77
+  #define CPU_ST7920_DELAY_2 DELAY_NS(0)
78
+  #define CPU_ST7920_DELAY_3 DELAY_NS(0)
75 79
 #elif F_CPU == 16000000
76 80
   #define CPU_ST7920_DELAY_1 DELAY_NS(0)
77 81
   #define CPU_ST7920_DELAY_2 DELAY_NS(0)

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

@@ -404,6 +404,8 @@
404 404
 
405 405
 #elif MB(THE_BORG)
406 406
   #include "pins_THE_BORG.h"          // STM32F7                                    env:STM32F7
407
+#elif MB(REMRAM_V1)
408
+  #include "pins_REMRAM_V1.h"         // STM32F7                                    env:STM32F7xx
407 409
 
408 410
 //
409 411
 // Espressif ESP32

+ 126
- 0
Marlin/src/pins/pins_REMRAM_V1.h View File

@@ -0,0 +1,126 @@
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
+#ifndef STM32F7xx
24
+  #error "Oops!  Make sure you have an STM32F7 board selected from the 'Tools -> Boards' menu."
25
+#endif
26
+
27
+#define DEFAULT_MACHINE_NAME "RemRam"
28
+#define BOARD_NAME "RemRam v1"
29
+
30
+#define EEPROM_EMULATED_WITH_SRAM // Emulate the EEPROM using Backup SRAM
31
+
32
+#if E_STEPPERS > 1 || HOTENDS > 1
33
+  #error "RemRam supports only one hotend / E-stepper."
34
+#endif
35
+
36
+//
37
+// Limit Switches
38
+//
39
+#if DISABLED(SENSORLESS_HOMING)
40
+  #define X_MIN_PIN        58
41
+  #define X_MAX_PIN        59
42
+  #define Y_MIN_PIN        60
43
+  #define Y_MAX_PIN        61
44
+  #define Z_MIN_PIN        62
45
+  #define Z_MAX_PIN        63
46
+#else
47
+  #define X_STOP_PIN       36
48
+  #define Y_STOP_PIN       39
49
+  #define Z_MIN_PIN        62
50
+  #define Z_MAX_PIN        42
51
+#endif
52
+
53
+//
54
+// Z Probe (when not Z_MIN_PIN)
55
+//
56
+#ifndef Z_MIN_PROBE_PIN
57
+  #define Z_MIN_PROBE_PIN  26   // EXT_D1
58
+#endif
59
+
60
+//
61
+// Steppers
62
+//
63
+#define X_STEP_PIN         22
64
+#define X_DIR_PIN          35
65
+#define X_ENABLE_PIN       34
66
+#define X_CS_PIN           14
67
+
68
+#define Y_STEP_PIN         23
69
+#define Y_DIR_PIN          38
70
+#define Y_ENABLE_PIN       37
71
+#define Y_CS_PIN           15
72
+
73
+#define Z_STEP_PIN         24
74
+#define Z_DIR_PIN          41
75
+#define Z_ENABLE_PIN       40
76
+#define Z_CS_PIN           16
77
+
78
+#define E0_STEP_PIN        25
79
+#define E0_DIR_PIN         44
80
+#define E0_ENABLE_PIN      43
81
+#define E0_CS_PIN          10
82
+
83
+//
84
+// Temperature Sensors
85
+//
86
+#define TEMP_0_PIN         65   // THERM_2
87
+#define TEMP_1_PIN         66   // THERM_3
88
+#define TEMP_BED_PIN       64   // THERM_1
89
+
90
+//
91
+// Heaters / Fans
92
+//
93
+#define HEATER_0_PIN       33
94
+#define HEATER_BED_PIN     31
95
+
96
+#ifndef FAN_PIN
97
+  #define FAN_PIN          30   // "FAN1"
98
+#endif
99
+#define FAN1_PIN           32   // "FAN2"
100
+
101
+#define ORIG_E0_AUTO_FAN_PIN 32   // Use this by NOT overriding E0_AUTO_FAN_PIN
102
+
103
+//
104
+// Servos
105
+//
106
+#define SERVO0_PIN         26   // PWM_EXT1
107
+#define SERVO1_PIN         27   // PWM_EXT2
108
+
109
+#define SDSS                9
110
+#define LED_PIN            21   // STATUS_LED
111
+#define KILL_PIN           57
112
+
113
+//
114
+// LCD / Controller
115
+//
116
+#define SD_DETECT_PIN      56   // SD_CARD_DET
117
+#define BEEPER_PIN         46   // LCD_BEEPER
118
+#define LCD_PINS_RS        49   // LCD_RS
119
+#define LCD_PINS_ENABLE    48   // LCD_EN
120
+#define LCD_PINS_D4        50   // LCD_D4
121
+#define LCD_PINS_D5        51   // LCD_D5
122
+#define LCD_PINS_D6        52   // LCD_D6
123
+#define LCD_PINS_D7        53   // LCD_D7
124
+#define BTN_EN1            54   // BTN_EN1
125
+#define BTN_EN2            55   // BTN_EN2
126
+#define BTN_ENC            47   // BTN_ENC

Loading…
Cancel
Save