Parcourir la source

SPI TFT for STM32F4 boards (#20384)

* fix pinsDebug for F1 boards

* add MKS Robin PRO V2 board - development board

* tft spi working with F4 boards

* pins formating

* sanity check for TFT on supported cores in STM32

* Fix tabs/spaces in pins file

Co-authored-by: Jason Smith <jason.inet@gmail.com>
Victor Oliveira il y a 4 ans
Parent
révision
9ead6a30f2
Aucun compte lié à l'adresse e-mail de l'auteur

+ 4
- 0
Marlin/src/HAL/STM32/inc/SanityCheck.h Voir le fichier

@@ -51,3 +51,7 @@
51 51
 #elif ENABLED(SERIAL_STATS_DROPPED_RX)
52 52
   #error "SERIAL_STATS_DROPPED_RX is not supported on this platform."
53 53
 #endif
54
+
55
+#if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI) && NOT_TARGET(STM32F4xx, STM32F1xx)
56
+  #error "TFT_COLOR_UI, TFT_LVGL_UI and TFT_CLASSIC_U are currently only supported on STM32F4 and STM32F1 hardware."
57
+#endif

+ 67
- 76
Marlin/src/HAL/STM32/pinsDebug.h Voir le fichier

@@ -137,32 +137,19 @@ const XrefInfo pin_xref[] PROGMEM = {
137 137
 #endif
138 138
 
139 139
 uint8_t get_pin_mode(const pin_t Ard_num) {
140
-  uint32_t mode_all = 0;
141 140
   const PinName dp = digitalPinToPinName(Ard_num);
142
-  switch (PORT_ALPHA(dp)) {
143
-    case 'A' : mode_all = GPIOA->MODER; break;
144
-    case 'B' : mode_all = GPIOB->MODER; break;
145
-    case 'C' : mode_all = GPIOC->MODER; break;
146
-    case 'D' : mode_all = GPIOD->MODER; break;
147
-    #ifdef PE_0
148
-      case 'E' : mode_all = GPIOE->MODER; break;
149
-    #elif defined(PF_0)
150
-      case 'F' : mode_all = GPIOF->MODER; break;
151
-    #elif defined(PG_0)
152
-      case 'G' : mode_all = GPIOG->MODER; break;
153
-    #elif defined(PH_0)
154
-      case 'H' : mode_all = GPIOH->MODER; break;
155
-    #elif defined(PI_0)
156
-      case 'I' : mode_all = GPIOI->MODER; break;
157
-    #elif defined(PJ_0)
158
-      case 'J' : mode_all = GPIOJ->MODER; break;
159
-    #elif defined(PK_0)
160
-      case 'K' : mode_all = GPIOK->MODER; break;
161
-    #elif defined(PL_0)
162
-      case 'L' : mode_all = GPIOL->MODER; break;
163
-    #endif
141
+  uint32_t ll_pin  = STM_LL_GPIO_PIN(dp);
142
+  GPIO_TypeDef *port = get_GPIO_Port(STM_PORT(dp));
143
+  uint32_t mode = LL_GPIO_GetPinMode(port, ll_pin);
144
+  switch (mode)
145
+  {
146
+    case LL_GPIO_MODE_ANALOG: return MODE_PIN_ANALOG;
147
+    case LL_GPIO_MODE_INPUT: return MODE_PIN_INPUT;
148
+    case LL_GPIO_MODE_OUTPUT: return MODE_PIN_OUTPUT;
149
+    case LL_GPIO_MODE_ALTERNATE: return MODE_PIN_ALT;
150
+    TERN_(STM32F1xx, case LL_GPIO_MODE_FLOATING:)
151
+    default: return 0;
164 152
   }
165
-  return (mode_all >> (2 * uint8_t(PIN_NUM(dp)))) & 0x03;
166 153
 }
167 154
 
168 155
 bool GET_PINMODE(const pin_t Ard_num) {
@@ -217,58 +204,62 @@ bool pwm_status(const pin_t Ard_num) {
217 204
 }
218 205
 
219 206
 void pwm_details(const pin_t Ard_num) {
220
-  if (pwm_status(Ard_num)) {
221
-    uint32_t alt_all = 0;
222
-    const PinName dp = digitalPinToPinName(Ard_num);
223
-    pin_t pin_number = uint8_t(PIN_NUM(dp));
224
-    const bool over_7 = pin_number >= 8;
225
-    const uint8_t ind = over_7 ? 1 : 0;
226
-    switch (PORT_ALPHA(dp)) {  // get alt function
227
-      case 'A' : alt_all = GPIOA->AFR[ind]; break;
228
-      case 'B' : alt_all = GPIOB->AFR[ind]; break;
229
-      case 'C' : alt_all = GPIOC->AFR[ind]; break;
230
-      case 'D' : alt_all = GPIOD->AFR[ind]; break;
231
-      #ifdef PE_0
232
-        case 'E' : alt_all = GPIOE->AFR[ind]; break;
233
-      #elif defined (PF_0)
234
-        case 'F' : alt_all = GPIOF->AFR[ind]; break;
235
-      #elif defined (PG_0)
236
-        case 'G' : alt_all = GPIOG->AFR[ind]; break;
237
-      #elif defined (PH_0)
238
-        case 'H' : alt_all = GPIOH->AFR[ind]; break;
239
-      #elif defined (PI_0)
240
-        case 'I' : alt_all = GPIOI->AFR[ind]; break;
241
-      #elif defined (PJ_0)
242
-        case 'J' : alt_all = GPIOJ->AFR[ind]; break;
243
-      #elif defined (PK_0)
244
-        case 'K' : alt_all = GPIOK->AFR[ind]; break;
245
-      #elif defined (PL_0)
246
-        case 'L' : alt_all = GPIOL->AFR[ind]; break;
247
-      #endif
248
-    }
249
-    if (over_7) pin_number -= 8;
207
+  #ifndef STM32F1xx
208
+    if (pwm_status(Ard_num)) {
209
+      uint32_t alt_all = 0;
210
+      const PinName dp = digitalPinToPinName(Ard_num);
211
+      pin_t pin_number = uint8_t(PIN_NUM(dp));
212
+      const bool over_7 = pin_number >= 8;
213
+      const uint8_t ind = over_7 ? 1 : 0;
214
+      switch (PORT_ALPHA(dp)) {  // get alt function
215
+        case 'A' : alt_all = GPIOA->AFR[ind]; break;
216
+        case 'B' : alt_all = GPIOB->AFR[ind]; break;
217
+        case 'C' : alt_all = GPIOC->AFR[ind]; break;
218
+        case 'D' : alt_all = GPIOD->AFR[ind]; break;
219
+        #ifdef PE_0
220
+          case 'E' : alt_all = GPIOE->AFR[ind]; break;
221
+        #elif defined (PF_0)
222
+          case 'F' : alt_all = GPIOF->AFR[ind]; break;
223
+        #elif defined (PG_0)
224
+          case 'G' : alt_all = GPIOG->AFR[ind]; break;
225
+        #elif defined (PH_0)
226
+          case 'H' : alt_all = GPIOH->AFR[ind]; break;
227
+        #elif defined (PI_0)
228
+          case 'I' : alt_all = GPIOI->AFR[ind]; break;
229
+        #elif defined (PJ_0)
230
+          case 'J' : alt_all = GPIOJ->AFR[ind]; break;
231
+        #elif defined (PK_0)
232
+          case 'K' : alt_all = GPIOK->AFR[ind]; break;
233
+        #elif defined (PL_0)
234
+          case 'L' : alt_all = GPIOL->AFR[ind]; break;
235
+        #endif
236
+      }
237
+      if (over_7) pin_number -= 8;
250 238
 
251
-    uint8_t alt_func = (alt_all >> (4 * pin_number)) & 0x0F;
252
-    SERIAL_ECHOPAIR("Alt Function: ", alt_func);
253
-    if (alt_func < 10) SERIAL_CHAR(' ');
254
-    SERIAL_ECHOPGM(" - ");
255
-    switch (alt_func) {
256
-      case  0 : SERIAL_ECHOPGM("system (misc. I/O)"); break;
257
-      case  1 : SERIAL_ECHOPGM("TIM1/TIM2 (probably PWM)"); break;
258
-      case  2 : SERIAL_ECHOPGM("TIM3..5 (probably PWM)"); break;
259
-      case  3 : SERIAL_ECHOPGM("TIM8..11 (probably PWM)"); break;
260
-      case  4 : SERIAL_ECHOPGM("I2C1..3"); break;
261
-      case  5 : SERIAL_ECHOPGM("SPI1/SPI2"); break;
262
-      case  6 : SERIAL_ECHOPGM("SPI3"); break;
263
-      case  7 : SERIAL_ECHOPGM("USART1..3"); break;
264
-      case  8 : SERIAL_ECHOPGM("USART4..6"); break;
265
-      case  9 : SERIAL_ECHOPGM("CAN1/CAN2, TIM12..14  (probably PWM)"); break;
266
-      case 10 : SERIAL_ECHOPGM("OTG"); break;
267
-      case 11 : SERIAL_ECHOPGM("ETH"); break;
268
-      case 12 : SERIAL_ECHOPGM("FSMC, SDIO, OTG"); break;
269
-      case 13 : SERIAL_ECHOPGM("DCMI"); break;
270
-      case 14 : SERIAL_ECHOPGM("unused (shouldn't see this)"); break;
271
-      case 15 : SERIAL_ECHOPGM("EVENTOUT"); break;
239
+      uint8_t alt_func = (alt_all >> (4 * pin_number)) & 0x0F;
240
+      SERIAL_ECHOPAIR("Alt Function: ", alt_func);
241
+      if (alt_func < 10) SERIAL_CHAR(' ');
242
+      SERIAL_ECHOPGM(" - ");
243
+      switch (alt_func) {
244
+        case  0 : SERIAL_ECHOPGM("system (misc. I/O)"); break;
245
+        case  1 : SERIAL_ECHOPGM("TIM1/TIM2 (probably PWM)"); break;
246
+        case  2 : SERIAL_ECHOPGM("TIM3..5 (probably PWM)"); break;
247
+        case  3 : SERIAL_ECHOPGM("TIM8..11 (probably PWM)"); break;
248
+        case  4 : SERIAL_ECHOPGM("I2C1..3"); break;
249
+        case  5 : SERIAL_ECHOPGM("SPI1/SPI2"); break;
250
+        case  6 : SERIAL_ECHOPGM("SPI3"); break;
251
+        case  7 : SERIAL_ECHOPGM("USART1..3"); break;
252
+        case  8 : SERIAL_ECHOPGM("USART4..6"); break;
253
+        case  9 : SERIAL_ECHOPGM("CAN1/CAN2, TIM12..14  (probably PWM)"); break;
254
+        case 10 : SERIAL_ECHOPGM("OTG"); break;
255
+        case 11 : SERIAL_ECHOPGM("ETH"); break;
256
+        case 12 : SERIAL_ECHOPGM("FSMC, SDIO, OTG"); break;
257
+        case 13 : SERIAL_ECHOPGM("DCMI"); break;
258
+        case 14 : SERIAL_ECHOPGM("unused (shouldn't see this)"); break;
259
+        case 15 : SERIAL_ECHOPGM("EVENTOUT"); break;
260
+      }
272 261
     }
273
-  }
262
+  #else
263
+    // TODO: F1 doesn't support changing pins function, so we need to check the function of the PIN and if it's enabled
264
+  #endif
274 265
 } // pwm_details

+ 65
- 43
Marlin/src/HAL/STM32/tft/tft_spi.cpp Voir le fichier

@@ -34,35 +34,25 @@ DMA_HandleTypeDef TFT_SPI::DMAtx;
34 34
 void TFT_SPI::Init() {
35 35
   SPI_TypeDef *spiInstance;
36 36
 
37
-  #if PIN_EXISTS(TFT_RESET)
38
-    OUT_WRITE(TFT_RESET_PIN, HIGH);
39
-    HAL_Delay(100);
40
-  #endif
41
-
42
-  #if PIN_EXISTS(TFT_BACKLIGHT)
43
-    OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
44
-  #endif
45
-
46 37
   OUT_WRITE(TFT_A0_PIN, HIGH);
47 38
   OUT_WRITE(TFT_CS_PIN, HIGH);
48 39
 
49 40
   if ((spiInstance = (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_SCK_PIN),  PinMap_SPI_SCLK)) == NP) return;
50 41
   if (spiInstance != (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_MOSI_PIN), PinMap_SPI_MOSI)) return;
51 42
 
52
-  #if PIN_EXISTS(TFT_MISO) && (TFT_MISO_PIN != TFT_MOSI_PIN)
53
-    if (spiInstance != (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO)) return;
43
+  #if PIN_EXISTS(TFT_MISO)
44
+    if (TFT_MISO_PIN != TFT_MOSI_PIN)
45
+      if (spiInstance != (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO)) return;
54 46
   #endif
55 47
 
56 48
   SPIx.Instance                = spiInstance;
57 49
   SPIx.State                   = HAL_SPI_STATE_RESET;
58 50
   SPIx.Init.NSS                = SPI_NSS_SOFT;
59 51
   SPIx.Init.Mode               = SPI_MODE_MASTER;
60
-  SPIx.Init.Direction          =
61
-  #if TFT_MISO_PIN == TFT_MOSI_PIN
62
-                                 SPI_DIRECTION_1LINE;
63
-  #else
64
-                                 SPI_DIRECTION_2LINES;
65
-  #endif
52
+  if (TFT_MISO_PIN == TFT_MOSI_PIN)
53
+    SPIx.Init.Direction         = SPI_DIRECTION_1LINE;
54
+  else
55
+    SPIx.Init.Direction         = SPI_DIRECTION_2LINES;
66 56
   SPIx.Init.BaudRatePrescaler  = SPI_BAUDRATEPRESCALER_2;
67 57
   SPIx.Init.CLKPhase           = SPI_PHASE_1EDGE;
68 58
   SPIx.Init.CLKPolarity        = SPI_POLARITY_LOW;
@@ -74,31 +64,50 @@ void TFT_SPI::Init() {
74 64
 
75 65
   pinmap_pinout(digitalPinToPinName(TFT_SCK_PIN), PinMap_SPI_SCLK);
76 66
   pinmap_pinout(digitalPinToPinName(TFT_MOSI_PIN), PinMap_SPI_MOSI);
77
-  #if PIN_EXISTS(TFT_MISO) && (TFT_MISO_PIN != TFT_MOSI_PIN)
78
-    pinmap_pinout(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO);
67
+  #if PIN_EXISTS(TFT_MISO)
68
+    if (TFT_MISO_PIN != TFT_MOSI_PIN)
69
+      pinmap_pinout(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO);
79 70
   #endif
80 71
   pin_PullConfig(get_GPIO_Port(STM_PORT(digitalPinToPinName(TFT_SCK_PIN))), STM_LL_GPIO_PIN(digitalPinToPinName(TFT_SCK_PIN)), GPIO_PULLDOWN);
81 72
 
82 73
   #ifdef SPI1_BASE
83 74
     if (SPIx.Instance == SPI1) {
84 75
       __HAL_RCC_SPI1_CLK_ENABLE();
85
-      __HAL_RCC_DMA1_CLK_ENABLE();
76
+      #ifdef STM32F1xx
77
+        __HAL_RCC_DMA1_CLK_ENABLE();
78
+        DMAtx.Instance = DMA1_Channel3;
79
+      #elif defined(STM32F4xx)
80
+        __HAL_RCC_DMA2_CLK_ENABLE();
81
+        DMAtx.Instance = DMA2_Stream3;
82
+        DMAtx.Init.Channel = DMA_CHANNEL_3;
83
+      #endif
86 84
       SPIx.Init.BaudRatePrescaler  = SPI_BAUDRATEPRESCALER_4;
87
-      DMAtx.Instance = DMA1_Channel3;
88 85
     }
89 86
   #endif
90 87
   #ifdef SPI2_BASE
91 88
     if (SPIx.Instance == SPI2) {
92 89
       __HAL_RCC_SPI2_CLK_ENABLE();
93
-      __HAL_RCC_DMA1_CLK_ENABLE();
94
-      DMAtx.Instance = DMA1_Channel5;
90
+      #ifdef STM32F1xx
91
+        __HAL_RCC_DMA1_CLK_ENABLE();
92
+        DMAtx.Instance = DMA1_Channel5;
93
+      #elif defined(STM32F4xx)
94
+        __HAL_RCC_DMA1_CLK_ENABLE();
95
+        DMAtx.Instance = DMA1_Stream4;
96
+        DMAtx.Init.Channel = DMA_CHANNEL_4;
97
+      #endif
95 98
     }
96 99
   #endif
97 100
   #ifdef SPI3_BASE
98 101
     if (SPIx.Instance == SPI3) {
99 102
       __HAL_RCC_SPI3_CLK_ENABLE();
100
-      __HAL_RCC_DMA2_CLK_ENABLE();
101
-      DMAtx.Instance = DMA2_Channel2;
103
+      #ifdef STM32F1xx
104
+        __HAL_RCC_DMA2_CLK_ENABLE();
105
+        DMAtx.Instance = DMA2_Channel2;
106
+      #elif defined(STM32F4xx)
107
+        __HAL_RCC_DMA1_CLK_ENABLE();
108
+        DMAtx.Instance = DMA1_Stream5;
109
+        DMAtx.Init.Channel = DMA_CHANNEL_5;
110
+      #endif
102 111
     }
103 112
   #endif
104 113
 
@@ -110,6 +119,9 @@ void TFT_SPI::Init() {
110 119
   DMAtx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
111 120
   DMAtx.Init.Mode = DMA_NORMAL;
112 121
   DMAtx.Init.Priority = DMA_PRIORITY_LOW;
122
+  #if defined(STM32F4xx)
123
+    DMAtx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
124
+  #endif
113 125
 }
114 126
 
115 127
 void TFT_SPI::DataTransferBegin(uint16_t DataSize) {
@@ -142,12 +154,12 @@ uint32_t TFT_SPI::ReadID(uint16_t Reg) {
142 154
     __HAL_SPI_ENABLE(&SPIx);
143 155
 
144 156
     for (i = 0; i < 4; i++) {
145
-      #if TFT_MISO_PIN != TFT_MOSI_PIN
157
+      if (TFT_MISO_PIN != TFT_MOSI_PIN) {
146 158
         //if (hspi->Init.Direction == SPI_DIRECTION_2LINES) {
147 159
           while ((SPIx.Instance->SR & SPI_FLAG_TXE) != SPI_FLAG_TXE) {}
148 160
           SPIx.Instance->DR = 0;
149 161
         //}
150
-      #endif
162
+      }
151 163
       while ((SPIx.Instance->SR & SPI_FLAG_RXNE) != SPI_FLAG_RXNE) {}
152 164
       Data = (Data << 8) | SPIx.Instance->DR;
153 165
     }
@@ -162,21 +174,34 @@ uint32_t TFT_SPI::ReadID(uint16_t Reg) {
162 174
 }
163 175
 
164 176
 bool TFT_SPI::isBusy() {
165
-  if (DMAtx.Instance->CCR & DMA_CCR_EN)
177
+  #if defined(STM32F1xx)
178
+    volatile bool dmaEnabled = (DMAtx.Instance->CCR & DMA_CCR_EN) != RESET;
179
+  #elif defined(STM32F4xx)
180
+    volatile bool dmaEnabled = DMAtx.Instance->CR & DMA_SxCR_EN;
181
+  #endif
182
+  if (dmaEnabled) {
166 183
     if (__HAL_DMA_GET_FLAG(&DMAtx, __HAL_DMA_GET_TC_FLAG_INDEX(&DMAtx)) != 0 || __HAL_DMA_GET_FLAG(&DMAtx, __HAL_DMA_GET_TE_FLAG_INDEX(&DMAtx)) != 0)
167 184
       Abort();
168
-  return DMAtx.Instance->CCR & DMA_CCR_EN;
185
+  }
186
+  else {
187
+    Abort();
188
+  }
189
+  return dmaEnabled;
169 190
 }
170 191
 
171 192
 void TFT_SPI::Abort() {
172
-  __HAL_DMA_DISABLE(&DMAtx);
193
+  // First, abort any running dma
194
+  HAL_DMA_Abort(&DMAtx);
195
+  // DeInit objects
196
+  HAL_DMA_DeInit(&DMAtx);
197
+  HAL_SPI_DeInit(&SPIx);
198
+  // Deselect CS
173 199
   DataTransferEnd();
174 200
 }
175 201
 
176 202
 void TFT_SPI::Transmit(uint16_t Data) {
177
-  #if TFT_MISO_PIN == TFT_MOSI_PIN
203
+  if (TFT_MISO_PIN == TFT_MOSI_PIN)
178 204
     SPI_1LINE_TX(&SPIx);
179
-  #endif
180 205
 
181 206
   __HAL_SPI_ENABLE(&SPIx);
182 207
 
@@ -185,26 +210,23 @@ void TFT_SPI::Transmit(uint16_t Data) {
185 210
   while ((SPIx.Instance->SR & SPI_FLAG_TXE) != SPI_FLAG_TXE) {}
186 211
   while ((SPIx.Instance->SR & SPI_FLAG_BSY) == SPI_FLAG_BSY) {}
187 212
 
188
-  #if TFT_MISO_PIN != TFT_MOSI_PIN
213
+  if (TFT_MISO_PIN != TFT_MOSI_PIN)
189 214
     __HAL_SPI_CLEAR_OVRFLAG(&SPIx);   /* Clear overrun flag in 2 Lines communication mode because received is not read */
190
-  #endif
191 215
 }
192 216
 
193 217
 void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
218
+  // Wait last dma finish, to start another
219
+  while(isBusy()) { }
220
+
194 221
   DMAtx.Init.MemInc = MemoryIncrease;
195 222
   HAL_DMA_Init(&DMAtx);
196 223
 
197
-  DataTransferBegin();
198
-
199
-  #if TFT_MISO_PIN == TFT_MOSI_PIN
224
+  if (TFT_MISO_PIN == TFT_MOSI_PIN)
200 225
     SPI_1LINE_TX(&SPIx);
201
-  #endif
202 226
 
203
-  DMAtx.DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << DMAtx.ChannelIndex);
204
-  DMAtx.Instance->CNDTR = Count;
205
-  DMAtx.Instance->CPAR = (uint32_t)&(SPIx.Instance->DR);
206
-  DMAtx.Instance->CMAR = (uint32_t)Data;
207
-  __HAL_DMA_ENABLE(&DMAtx);
227
+  DataTransferBegin();
228
+
229
+  HAL_DMA_Start(&DMAtx, (uint32_t)Data, (uint32_t)&(SPIx.Instance->DR), Count);
208 230
   __HAL_SPI_ENABLE(&SPIx);
209 231
 
210 232
   SET_BIT(SPIx.Instance->CR2, SPI_CR2_TXDMAEN);   /* Enable Tx DMA Request */

+ 1
- 0
Marlin/src/core/boards.h Voir le fichier

@@ -365,6 +365,7 @@
365 365
 #define BOARD_FYSETC_S6_V2_0          4216  // FYSETC S6 v2.0 board
366 366
 #define BOARD_FLYF407ZG               4217  // FLYF407ZG board (STM32F407ZG)
367 367
 #define BOARD_MKS_ROBIN2              4218  // MKS_ROBIN2 (STM32F407ZE)
368
+#define BOARD_MKS_ROBIN_PRO_V2        4219  // MKS Robin Pro V2 (STM32F407VE)
368 369
 
369 370
 //
370 371
 // ARM Cortex M7

+ 2
- 0
Marlin/src/pins/pins.h Voir le fichier

@@ -588,6 +588,8 @@
588 588
   #include "stm32f4/pins_FLYF407ZG.h"           // STM32F4                                env:FLYF407ZG
589 589
 #elif MB(MKS_ROBIN2)
590 590
   #include "stm32f4/pins_MKS_ROBIN2.h"          // STM32F4                                env:MKS_ROBIN2
591
+#elif MB(MKS_ROBIN_PRO_V2)
592
+  #include "stm32f4/pins_MKS_ROBIN_PRO_V2.h"    // STM32F4                                env:mks_robin_pro2
591 593
 
592 594
 //
593 595
 // ARM Cortex M7

+ 381
- 0
Marlin/src/pins/stm32f4/pins_MKS_ROBIN_PRO_V2.h Voir le fichier

@@ -0,0 +1,381 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 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
+#if NOT_TARGET(STM32F4, STM32F4xx)
25
+  #error "Oops! Select an STM32F4 board in 'Tools > Board.'"
26
+#elif HOTENDS > 2 || E_STEPPERS > 2
27
+  #error "MKS Robin Nano V3 supports up to 1 hotends / E-steppers."
28
+#endif
29
+
30
+#define BOARD_INFO_NAME "MKS Robin PRO V2"
31
+
32
+// Use one of these or SDCard-based Emulation will be used
33
+//#define SRAM_EEPROM_EMULATION                   // Use BackSRAM-based EEPROM emulation
34
+//#define FLASH_EEPROM_EMULATION                  // Use Flash-based EEPROM emulation
35
+#define I2C_EEPROM
36
+
37
+//
38
+// Release PB4 (Y_ENABLE_PIN) from JTAG NRST role
39
+//
40
+
41
+//
42
+// Note: MKS Robin board is using SPI2 interface.
43
+//
44
+//#define SPI_MODULE                           2
45
+
46
+//
47
+// Limit Switches
48
+//
49
+#define X_DIAG_PIN                          PA15
50
+#define Y_DIAG_PIN                          PA12
51
+#define Z_DIAG_PIN                          PA11
52
+#define E0_DIAG_PIN                         PC4
53
+#define E1_DIAG_PIN                         PE7
54
+
55
+//
56
+
57
+#define X_STOP_PIN                          PA15
58
+#define Y_STOP_PIN                          PA12
59
+#define Z_MIN_PIN                           PA11
60
+#define Z_MAX_PIN                           PC4
61
+
62
+#ifndef FIL_RUNOUT_PIN
63
+  #define FIL_RUNOUT_PIN                    PA4   // MT_DET
64
+#endif
65
+
66
+//
67
+// Steppers
68
+//
69
+#define X_ENABLE_PIN                        PE4
70
+#define X_STEP_PIN                          PE3
71
+#define X_DIR_PIN                           PE2
72
+#ifndef X_CS_PIN
73
+  #define X_CS_PIN                          PD5
74
+#endif
75
+
76
+#define Y_ENABLE_PIN                        PE1
77
+#define Y_STEP_PIN                          PE0
78
+#define Y_DIR_PIN                           PB9
79
+#ifndef Y_CS_PIN
80
+  #define Y_CS_PIN                          PD7
81
+#endif
82
+
83
+#define Z_ENABLE_PIN                        PB8
84
+#define Z_STEP_PIN                          PB5
85
+#define Z_DIR_PIN                           PB4
86
+#ifndef Z_CS_PIN
87
+  #define Z_CS_PIN                          PD4
88
+#endif
89
+
90
+#define E0_ENABLE_PIN                       PB3
91
+#define E0_STEP_PIN                         PD6
92
+#define E0_DIR_PIN                          PD3
93
+#ifndef E0_CS_PIN
94
+  #define E0_CS_PIN                         PD9
95
+#endif
96
+
97
+#define E1_ENABLE_PIN                       PA3
98
+#define E1_STEP_PIN                         PD15
99
+#define E1_DIR_PIN                          PA1
100
+#ifndef E1_CS_PIN
101
+  #define E1_CS_PIN                         PD8
102
+#endif
103
+
104
+//
105
+// Software SPI pins for TMC2130 stepper drivers
106
+//
107
+#if ENABLED(TMC_USE_SW_SPI)
108
+  #ifndef TMC_SW_MOSI
109
+    #define TMC_SW_MOSI                     PD14
110
+  #endif
111
+  #ifndef TMC_SW_MISO
112
+    #define TMC_SW_MISO                     PD1
113
+  #endif
114
+  #ifndef TMC_SW_SCK
115
+    #define TMC_SW_SCK                      PD0
116
+  #endif
117
+#endif
118
+
119
+#if HAS_TMC_UART
120
+  /**
121
+   * TMC2208/TMC2209 stepper drivers
122
+   *
123
+   * Hardware serial communication ports.
124
+   * If undefined software serial is used according to the pins below
125
+   */
126
+  //#define X_HARDWARE_SERIAL  Serial1
127
+  //#define X2_HARDWARE_SERIAL Serial1
128
+  //#define Y_HARDWARE_SERIAL  Serial1
129
+  //#define Y2_HARDWARE_SERIAL Serial1
130
+  //#define Z_HARDWARE_SERIAL  Serial1
131
+  //#define Z2_HARDWARE_SERIAL Serial1
132
+  //#define E0_HARDWARE_SERIAL Serial1
133
+  //#define E1_HARDWARE_SERIAL Serial1
134
+  //#define E2_HARDWARE_SERIAL Serial1
135
+  //#define E3_HARDWARE_SERIAL Serial1
136
+  //#define E4_HARDWARE_SERIAL Serial1
137
+
138
+  //
139
+  // Software serial
140
+  //
141
+
142
+  #define X_SERIAL_TX_PIN                   PD5
143
+  #define X_SERIAL_RX_PIN                   PD5
144
+
145
+  #define Y_SERIAL_TX_PIN                   PD7
146
+  #define Y_SERIAL_RX_PIN                   PD7
147
+
148
+  #define Z_SERIAL_TX_PIN                   PD4
149
+  #define Z_SERIAL_RX_PIN                   PD4
150
+
151
+  #define E0_SERIAL_TX_PIN                  PD9
152
+  #define E0_SERIAL_RX_PIN                  PD9
153
+
154
+  #define E1_SERIAL_TX_PIN                  PD8
155
+  #define E1_SERIAL_RX_PIN                  PD8
156
+
157
+  // Reduce baud rate to improve software serial reliability
158
+  #define TMC_BAUD_RATE                    19200
159
+#endif // TMC2208 || TMC2209
160
+
161
+//
162
+// Temperature Sensors
163
+//
164
+#define TEMP_0_PIN                          PC1   // TH1
165
+#define TEMP_1_PIN                          PC2   // TH2
166
+#define TEMP_BED_PIN                        PC0   // TB1
167
+
168
+//
169
+// Heaters / Fans
170
+//
171
+#define HEATER_0_PIN                        PC3   // HEATER1
172
+#define HEATER_1_PIN                        PB0   // HEATER2
173
+#define HEATER_BED_PIN                      PA0   // HOT BED
174
+
175
+#define FAN_PIN                             PB1   // FAN
176
+
177
+//
178
+// Thermocouples
179
+//
180
+//#define MAX6675_SS_PIN                    PE5   // TC1 - CS1
181
+//#define MAX6675_SS_PIN                    PE6   // TC2 - CS2
182
+
183
+//
184
+// Misc. Functions
185
+//
186
+// #define POWER_LOSS_PIN                      PA2   // PW_DET
187
+// #define PS_ON_PIN                           PA3   // PW_OFF
188
+// #define SUICIDE_PIN                         PB2     // Enable MKSPWC support
189
+// #define KILL_PIN                            PA2     // Enable MKSPWC support
190
+// #define KILL_PIN_INVERTING                  true     // Enable MKSPWC support
191
+#define SERVO0_PIN                          PA8   // Enable BLTOUCH support
192
+//#define LED_PIN                           PB2
193
+
194
+#ifndef SDCARD_CONNECTION
195
+  #define SDCARD_CONNECTION              ONBOARD
196
+#endif
197
+
198
+// #define USE_NEW_SPI_API 1
199
+
200
+//
201
+// Onboard SD card
202
+// NOT compatible with LCD
203
+//
204
+// detect pin dont work when ONBOARD and NO_SD_HOST_DRIVE disabled
205
+#if !defined(SDCARD_CONNECTION) || SDCARD_CONNECTION == ONBOARD
206
+  #define CUSTOM_SPI_PINS
207
+  #if ENABLED(CUSTOM_SPI_PINS)
208
+
209
+    #if USE_NEW_SPI_API
210
+      #define SD_SPI MARLIN_SPI(HardwareSPI3, PC9)
211
+    #else
212
+      #define ENABLE_SPI3
213
+      #define SS_PIN                        -1
214
+      #define SDSS                          PC9
215
+      #define SCK_PIN                       PC10
216
+      #define MISO_PIN                      PC11
217
+      #define MOSI_PIN                      PC12
218
+    #endif
219
+    #define SD_DETECT_PIN                   PD12
220
+  #endif
221
+#endif
222
+
223
+/*
224
+//
225
+// LCD SD
226
+//
227
+#if SDCARD_CONNECTION == LCD
228
+  #define CUSTOM_SPI_PINS
229
+  #if ENABLED(CUSTOM_SPI_PINS)
230
+    #define ENABLE_SPI1
231
+    #define SDSS                            PE10
232
+    #define SCK_PIN                         PA5
233
+    #define MISO_PIN                        PA6
234
+    #define MOSI_PIN                        PA7
235
+    #define SD_DETECT_PIN                   PE12
236
+  #endif
237
+#endif
238
+*/
239
+
240
+//
241
+// LCD / Controller
242
+#define SPI_FLASH
243
+// #define HAS_SPI_FLASH 1
244
+#define SPI_DEVICE                             2
245
+#define SPI_FLASH_SIZE                 0x1000000
246
+#if ENABLED(SPI_FLASH)
247
+  #define W25QXX_CS_PIN                     PB12
248
+  #define W25QXX_MOSI_PIN                   PB15
249
+  #define W25QXX_MISO_PIN                   PB14
250
+  #define W25QXX_SCK_PIN                    PB13
251
+#endif
252
+
253
+/**
254
+ *                _____                                             _____
255
+ *   (BEEPER)PC5 | · · | PE13(BTN_ENC)             (SPI1 MISO) PA6 | · · | PA5 (SPI1 SCK)
256
+ *  (LCD_EN)PD13 | · · | PC6(LCD_RS)                 (BTN_EN1) PE8 | · · | PE10 (SPI1 CS)
257
+ *  (LCD_D4)PE14 | · · | PE15(LCD_D5)               (BTN_EN2) PE11 | · · | PA7 (SPI1 MOSI)
258
+ *  (LCD_D6)PD11 | · · | PD10(LCD_D7)               (SPI DET) PE12 | · · | RESET
259
+ *           GND | · · | 5V                                    GND | · · | 3.3V
260
+ *                 ̄ ̄ ̄                                              ̄ ̄ ̄
261
+ *                EXP1                                               EXP2
262
+ */
263
+
264
+#if EITHER(TFT_480x320_SPI, TFT_LVGL_UI_SPI)
265
+  #ifndef TOUCH_CALIBRATION_X
266
+    #define TOUCH_CALIBRATION_X           -17253
267
+  #endif
268
+  #ifndef TOUCH_CALIBRATION_Y
269
+    #define TOUCH_CALIBRATION_Y            11579
270
+  #endif
271
+  #ifndef TOUCH_OFFSET_X
272
+    #define TOUCH_OFFSET_X                   514
273
+  #endif
274
+  #ifndef TOUCH_OFFSET_Y
275
+    #define TOUCH_OFFSET_Y                   -24
276
+  #endif
277
+  #ifndef TOUCH_ORIENTATION
278
+    #define TOUCH_ORIENTATION    TOUCH_LANDSCAPE
279
+  #endif
280
+
281
+  #define TFT_CS_PIN                        PD11
282
+  #define TFT_SCK_PIN                       PA5
283
+  #define TFT_MISO_PIN                      PA6
284
+  #define TFT_MOSI_PIN                      PA7
285
+  #define TFT_DC_PIN                        PD10
286
+  #define TFT_RST_PIN                       PC6
287
+  #define TFT_A0_PIN                  TFT_DC_PIN
288
+
289
+  #define TFT_RESET_PIN                     PC6
290
+  #define TFT_BACKLIGHT_PIN                 PD13
291
+
292
+  #define TOUCH_BUTTONS_HW_SPI
293
+  #define TOUCH_BUTTONS_HW_SPI_DEVICE          1
294
+
295
+  #define LCD_BACKLIGHT_PIN                 PD13
296
+  #ifndef TFT_WIDTH
297
+    #define TFT_WIDTH                        480
298
+  #endif
299
+  #ifndef TFT_HEIGHT
300
+    #define TFT_HEIGHT                       320
301
+  #endif
302
+
303
+  #define TOUCH_CS_PIN                      PE14  // SPI1_NSS
304
+  #define TOUCH_SCK_PIN                     PA5   // SPI1_SCK
305
+  #define TOUCH_MISO_PIN                    PA6   // SPI1_MISO
306
+  #define TOUCH_MOSI_PIN                    PA7   // SPI1_MOSI
307
+
308
+  #define BTN_EN1                           PE8
309
+  #define BTN_EN2                           PE11
310
+  #define BEEPER_PIN                        PC5
311
+  #define BTN_ENC                           PE13
312
+
313
+  #define LCD_READ_ID                       0xD3
314
+  #define LCD_USE_DMA_SPI
315
+
316
+  // #define TFT_DRIVER                      ST7796
317
+  #define TFT_BUFFER_SIZE                  14400
318
+
319
+#elif HAS_SPI_LCD
320
+  #define BEEPER_PIN                        PC5
321
+  #define BTN_ENC                           PE13
322
+  #define LCD_PINS_ENABLE                   PD13
323
+  #define LCD_PINS_RS                       PC6
324
+  #define BTN_EN1                           PE8
325
+  #define BTN_EN2                           PE11
326
+  #define LCD_BACKLIGHT_PIN                 -1
327
+
328
+  // MKS MINI12864 and MKS LCD12864B; If using MKS LCD12864A (Need to remove RPK2 resistor)
329
+  #if ENABLED(MKS_MINI_12864)
330
+    //#define LCD_BACKLIGHT_PIN             -1
331
+    //#define LCD_RESET_PIN                 -1
332
+    #define DOGLCD_A0                       PD11
333
+    #define DOGLCD_CS                       PE15
334
+    //#define DOGLCD_SCK                    PA5
335
+    //#define DOGLCD_MOSI                   PA7
336
+
337
+    // Required for MKS_MINI_12864 with this board
338
+    //#define MKS_LCD12864B
339
+    //#undef SHOW_BOOTSCREEN
340
+
341
+  #else                                           // !MKS_MINI_12864
342
+
343
+    #define LCD_PINS_D4                     PE14
344
+    #if ENABLED(ULTIPANEL)
345
+      #define LCD_PINS_D5                   PE15
346
+      #define LCD_PINS_D6                   PD11
347
+      #define LCD_PINS_D7                   PD10
348
+    #endif
349
+
350
+    #ifndef ST7920_DELAY_1
351
+    #define ST7920_DELAY_1          DELAY_NS(96)
352
+    #endif
353
+    #ifndef ST7920_DELAY_2
354
+      #define ST7920_DELAY_2        DELAY_NS(48)
355
+    #endif
356
+    #ifndef ST7920_DELAY_3
357
+      #define ST7920_DELAY_3       DELAY_NS(600)
358
+    #endif
359
+
360
+  #endif // !MKS_MINI_12864
361
+
362
+#elif ENABLED(SPI_GRAPHICAL_TFT)
363
+  #define SPI_TFT_CS_PIN                    PD11
364
+  #define SPI_TFT_SCK_PIN                   PA5
365
+  #define SPI_TFT_MISO_PIN                  PA6
366
+  #define SPI_TFT_MOSI_PIN                  PA7
367
+  #define SPI_TFT_DC_PIN                    PD10
368
+  #define SPI_TFT_RST_PIN                   PC6
369
+
370
+  #define LCD_BACKLIGHT_PIN                 PD13
371
+
372
+  #define TOUCH_CS_PIN                      PE14  // SPI1_NSS
373
+  #define TOUCH_SCK_PIN                     PA5   // SPI1_SCK
374
+  #define TOUCH_MISO_PIN                    PA6   // SPI1_MISO
375
+  #define TOUCH_MOSI_PIN                    PA7   // SPI1_MOSI
376
+
377
+  #define BTN_EN1                           PE8
378
+  #define BTN_EN2                           PE11
379
+  #define BEEPER_PIN                        PC5
380
+  #define BTN_ENC                           PE13
381
+#endif // HAS_SPI_LCD

+ 20
- 0
platformio.ini Voir le fichier

@@ -1351,6 +1351,26 @@ extra_scripts        = ${common.extra_scripts}
1351 1351
   buildroot/share/PlatformIO/scripts/stm32_bootloader.py
1352 1352
   buildroot/share/PlatformIO/scripts/mks_encrypt.py
1353 1353
 
1354
+#
1355
+# MKS Robin Pro V2
1356
+#
1357
+[env:mks_robin_pro2]
1358
+platform      = ${common_stm32.platform}
1359
+extends       = common_stm32
1360
+build_flags   = ${common_stm32.build_flags} -DHAL_HCD_MODULE_ENABLED  -DUSBHOST -DARDUINO_BLACK_F407VE
1361
+board         = genericSTM32F407VET6
1362
+board_build.core     = stm32
1363
+board_build.variant  = MARLIN_F407VE
1364
+board_build.ldscript = ldscript.ld
1365
+board_build.firmware = Robin_nano35.bin
1366
+build_unflags        = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC
1367
+debug_tool           = jlink
1368
+upload_protocol      = jlink
1369
+extra_scripts        = ${common.extra_scripts}
1370
+  pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py
1371
+  buildroot/share/PlatformIO/scripts/stm32_bootloader.py
1372
+  buildroot/share/PlatformIO/scripts/mks_encrypt.py
1373
+
1354 1374
 #################################
1355 1375
 #                               #
1356 1376
 #      Other Architectures      #

Chargement…
Annuler
Enregistrer