Browse Source

STM32 soft SPI. STEVAL_3DP001V1 SD read. M906 tweaks. (#16579)

Bob-the-Kuhn 4 years ago
parent
commit
0d0dfba203

+ 173
- 101
Marlin/src/HAL/HAL_STM32/HAL_SPI.cpp View File

@@ -37,121 +37,193 @@ static SPISettings spiConfig;
37 37
 // ------------------------
38 38
 
39 39
 #if ENABLED(SOFTWARE_SPI)
40
+
40 41
   // ------------------------
41 42
   // Software SPI
42 43
   // ------------------------
43
-  #error "Software SPI not supported for STM32. Use Hardware SPI."
44 44
 
45
-#else
45
+  #include "../shared/Delay.h"
46 46
 
47
-// ------------------------
48
-// Hardware SPI
49
-// ------------------------
47
+  void spiBegin(void) {
48
+    OUT_WRITE(SS_PIN, HIGH);
49
+    OUT_WRITE(SCK_PIN, HIGH);
50
+    SET_INPUT(MISO_PIN);
51
+    OUT_WRITE(MOSI_PIN, HIGH);
52
+  }
50 53
 
51
-/**
52
- * VGPV SPI speed start and PCLK2/2, by default 108/2 = 54Mhz
53
- */
54
+  static uint16_t delay_STM32_soft_spi;
55
+
56
+  void spiInit(uint8_t spiRate) {
57
+    // Use datarates Marlin uses
58
+    switch (spiRate) {
59
+      case SPI_FULL_SPEED:   delay_STM32_soft_spi =  125; break;  // desired: 8,000,000  actual: ~1.1M
60
+      case SPI_HALF_SPEED:   delay_STM32_soft_spi =  125; break;  // desired: 4,000,000  actual: ~1.1M
61
+      case SPI_QUARTER_SPEED:delay_STM32_soft_spi =  250; break;  // desired: 2,000,000  actual: ~890K
62
+      case SPI_EIGHTH_SPEED: delay_STM32_soft_spi =  500; break;  // desired: 1,000,000  actual: ~590K
63
+      case SPI_SPEED_5:      delay_STM32_soft_spi = 1000; break;  // desired:   500,000  actual: ~360K
64
+      case SPI_SPEED_6:      delay_STM32_soft_spi = 2000; break;  // desired:   250,000  actual: ~210K
65
+      default:               delay_STM32_soft_spi = 4000; break;  // desired:   125,000  actual: ~123K
66
+    }
67
+    SPI.begin();
68
+  }
54 69
 
55
-/**
56
- * @brief  Begin SPI port setup
57
- *
58
- * @return Nothing
59
- *
60
- * @details Only configures SS pin since stm32duino creates and initialize the SPI object
61
- */
62
-void spiBegin() {
63
-  #if !PIN_EXISTS(SS)
64
-    #error "SS_PIN not defined!"
65
-  #endif
66
-
67
-  OUT_WRITE(SS_PIN, HIGH);
68
-}
69
-
70
-/** Configure SPI for specified SPI speed */
71
-void spiInit(uint8_t spiRate) {
72
-  // Use datarates Marlin uses
73
-  uint32_t clock;
74
-  switch (spiRate) {
75
-    case SPI_FULL_SPEED:    clock = 20000000; break; // 13.9mhz=20000000  6.75mhz=10000000  3.38mhz=5000000  .833mhz=1000000
76
-    case SPI_HALF_SPEED:    clock =  5000000; break;
77
-    case SPI_QUARTER_SPEED: clock =  2500000; break;
78
-    case SPI_EIGHTH_SPEED:  clock =  1250000; break;
79
-    case SPI_SPEED_5:       clock =   625000; break;
80
-    case SPI_SPEED_6:       clock =   300000; break;
81
-    default:
82
-      clock = 4000000; // Default from the SPI library
70
+  // Begin SPI transaction, set clock, bit order, data mode
71
+  void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) { /* do nothing */ }
72
+
73
+  uint8_t HAL_SPI_STM32_SpiTransfer_Mode_3(uint8_t b) { // using Mode 3
74
+    for (uint8_t bits = 8; bits--;) {
75
+      WRITE(SCK_PIN, LOW);
76
+      WRITE(MOSI_PIN, b & 0x80);
77
+
78
+      DELAY_NS(delay_STM32_soft_spi);
79
+      WRITE(SCK_PIN, HIGH);
80
+      DELAY_NS(delay_STM32_soft_spi);
81
+
82
+      b <<= 1;        // little setup time
83
+      b |= (READ(MISO_PIN) != 0);
84
+    }
85
+    DELAY_NS(125);
86
+    return b;
83 87
   }
84
-  spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
85 88
 
86
-  #if ENABLED(CUSTOM_SPI_PINS)
87
-    SPI.setMISO(MISO_PIN);
88
-    SPI.setMOSI(MOSI_PIN);
89
-    SPI.setSCLK(SCK_PIN);
90
-    SPI.setSSEL(SS_PIN);
91
-  #endif
89
+  // Soft SPI receive byte
90
+  uint8_t spiRec() {
91
+    DISABLE_ISRS();                                               // No interrupts during byte receive
92
+    const uint8_t data = HAL_SPI_STM32_SpiTransfer_Mode_3(0xFF);
93
+    ENABLE_ISRS();                                                // Enable interrupts
94
+    return data;
95
+  }
92 96
 
93
-  SPI.begin();
94
-}
97
+  // Soft SPI read data
98
+  void spiRead(uint8_t *buf, uint16_t nbyte) {
99
+    for (uint16_t i = 0; i < nbyte; i++)
100
+      buf[i] = spiRec();
101
+  }
95 102
 
96
-/**
97
- * @brief  Receives a single byte from the SPI port.
98
- *
99
- * @return Byte received
100
- *
101
- * @details
102
- */
103
-uint8_t spiRec() {
104
-  SPI.beginTransaction(spiConfig);
105
-  uint8_t returnByte = SPI.transfer(0xFF);
106
-  SPI.endTransaction();
107
-  return returnByte;
108
-}
103
+  // Soft SPI send byte
104
+  void spiSend(uint8_t data) {
105
+    DISABLE_ISRS();                         // No interrupts during byte send
106
+    HAL_SPI_STM32_SpiTransfer_Mode_3(data); // Don't care what is received
107
+    ENABLE_ISRS();                          // Enable interrupts
108
+  }
109 109
 
110
-/**
111
- * @brief  Receives a number of bytes from the SPI port to a buffer
112
- *
113
- * @param  buf   Pointer to starting address of buffer to write to.
114
- * @param  nbyte Number of bytes to receive.
115
- * @return Nothing
116
- *
117
- * @details Uses DMA
118
- */
119
-void spiRead(uint8_t* buf, uint16_t nbyte) {
120
-  if (nbyte == 0) return;
121
-  memset(buf, 0xFF, nbyte);
122
-  SPI.beginTransaction(spiConfig);
123
-  SPI.transfer(buf, nbyte);
124
-  SPI.endTransaction();
125
-}
110
+  // Soft SPI send block
111
+  void spiSendBlock(uint8_t token, const uint8_t *buf) {
112
+    spiSend(token);
113
+    for (uint16_t i = 0; i < 512; i++)
114
+      spiSend(buf[i]);
115
+  }
126 116
 
127
-/**
128
- * @brief  Sends a single byte on SPI port
129
- *
130
- * @param  b Byte to send
131
- *
132
- * @details
133
- */
134
-void spiSend(uint8_t b) {
135
-  SPI.beginTransaction(spiConfig);
136
-  SPI.transfer(b);
137
-  SPI.endTransaction();
138
-}
117
+#else
139 118
 
140
-/**
141
- * @brief  Write token and then write from 512 byte buffer to SPI (for SD card)
142
- *
143
- * @param  buf   Pointer with buffer start address
144
- * @return Nothing
145
- *
146
- * @details Use DMA
147
- */
148
-void spiSendBlock(uint8_t token, const uint8_t* buf) {
149
-  uint8_t rxBuf[512];
150
-  SPI.beginTransaction(spiConfig);
151
-  SPI.transfer(token);
152
-  SPI.transfer((uint8_t*)buf, &rxBuf, 512);
153
-  SPI.endTransaction();
154
-}
119
+  // ------------------------
120
+  // Hardware SPI
121
+  // ------------------------
122
+
123
+  /**
124
+   * VGPV SPI speed start and PCLK2/2, by default 108/2 = 54Mhz
125
+   */
126
+
127
+  /**
128
+   * @brief  Begin SPI port setup
129
+   *
130
+   * @return Nothing
131
+   *
132
+   * @details Only configures SS pin since stm32duino creates and initialize the SPI object
133
+   */
134
+  void spiBegin() {
135
+    #if !PIN_EXISTS(SS)
136
+      #error "SS_PIN not defined!"
137
+    #endif
138
+
139
+    OUT_WRITE(SS_PIN, HIGH);
140
+  }
141
+
142
+  // Configure SPI for specified SPI speed
143
+  void spiInit(uint8_t spiRate) {
144
+    // Use datarates Marlin uses
145
+    uint32_t clock;
146
+    switch (spiRate) {
147
+      case SPI_FULL_SPEED:    clock = 20000000; break; // 13.9mhz=20000000  6.75mhz=10000000  3.38mhz=5000000  .833mhz=1000000
148
+      case SPI_HALF_SPEED:    clock =  5000000; break;
149
+      case SPI_QUARTER_SPEED: clock =  2500000; break;
150
+      case SPI_EIGHTH_SPEED:  clock =  1250000; break;
151
+      case SPI_SPEED_5:       clock =   625000; break;
152
+      case SPI_SPEED_6:       clock =   300000; break;
153
+      default:
154
+        clock = 4000000; // Default from the SPI library
155
+    }
156
+    spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
157
+
158
+    #if ENABLED(CUSTOM_SPI_PINS)
159
+      SPI.setMISO(MISO_PIN);
160
+      SPI.setMOSI(MOSI_PIN);
161
+      SPI.setSCLK(SCK_PIN);
162
+      SPI.setSSEL(SS_PIN);
163
+    #endif
164
+
165
+    SPI.begin();
166
+  }
167
+
168
+  /**
169
+   * @brief  Receives a single byte from the SPI port.
170
+   *
171
+   * @return Byte received
172
+   *
173
+   * @details
174
+   */
175
+  uint8_t spiRec() {
176
+    SPI.beginTransaction(spiConfig);
177
+    uint8_t returnByte = SPI.transfer(0xFF);
178
+    SPI.endTransaction();
179
+    return returnByte;
180
+  }
181
+
182
+  /**
183
+   * @brief  Receive a number of bytes from the SPI port to a buffer
184
+   *
185
+   * @param  buf   Pointer to starting address of buffer to write to.
186
+   * @param  nbyte Number of bytes to receive.
187
+   * @return Nothing
188
+   *
189
+   * @details Uses DMA
190
+   */
191
+  void spiRead(uint8_t* buf, uint16_t nbyte) {
192
+    if (nbyte == 0) return;
193
+    memset(buf, 0xFF, nbyte);
194
+    SPI.beginTransaction(spiConfig);
195
+    SPI.transfer(buf, nbyte);
196
+    SPI.endTransaction();
197
+  }
198
+
199
+  /**
200
+   * @brief  Send a single byte on SPI port
201
+   *
202
+   * @param  b Byte to send
203
+   *
204
+   * @details
205
+   */
206
+  void spiSend(uint8_t b) {
207
+    SPI.beginTransaction(spiConfig);
208
+    SPI.transfer(b);
209
+    SPI.endTransaction();
210
+  }
211
+
212
+  /**
213
+   * @brief  Write token and then write from 512 byte buffer to SPI (for SD card)
214
+   *
215
+   * @param  buf   Pointer with buffer start address
216
+   * @return Nothing
217
+   *
218
+   * @details Use DMA
219
+   */
220
+  void spiSendBlock(uint8_t token, const uint8_t* buf) {
221
+    uint8_t rxBuf[512];
222
+    SPI.beginTransaction(spiConfig);
223
+    SPI.transfer(token);
224
+    SPI.transfer((uint8_t*)buf, &rxBuf, 512);
225
+    SPI.endTransaction();
226
+  }
155 227
 
156 228
 #endif // SOFTWARE_SPI
157 229
 

+ 12
- 16
Marlin/src/gcode/feature/L6470/M906.cpp View File

@@ -39,22 +39,16 @@
39 39
  *
40 40
  * On L6474 this sets the TVAL register (same address).
41 41
  *
42
- * J - select which driver(s) to monitor on multi-driver axis
43
- *     0 - (default) monitor all drivers on the axis or E0
42
+ * I - select which driver(s) to change on multi-driver axis
43
+ *     0 - (default) all drivers on the axis or E0
44 44
  *     1 - monitor only X, Y, Z or E1
45 45
  *     2 - monitor only X2, Y2, Z2 or E2
46 46
  *     3 - monitor only Z3 or E3
47 47
  *     4 - monitor only E4
48 48
  *     5 - monitor only E5
49
- * Xxxx, Yxxx, Zxxx, Exxx - axis to be monitored with displacement
50
- *     xxx (1-255) is distance moved on either side of current position
51
- *
52
- * I - over current threshold
53
- *     optional - will report current value from driver if not specified
54
- *
55
- * K - value for KVAL_HOLD (0 - 255) (optional)
56
- *     optional - will report current value from driver if not specified
57
- *
49
+ * Xxxx, Yxxx, Zxxx, Exxx - axis to change (optional)
50
+ *     L6474 - current in mA (4A max)
51
+ *     All others - 0-255
58 52
  */
59 53
 
60 54
 /**
@@ -202,10 +196,12 @@ void L6470_report_current(L64XX &motor, const L64XX_axis_t axis) {
202 196
 
203 197
       const uint16_t MicroSteps = _BV(motor.GetParam(L6470_STEP_MODE) & 0x07); //NOMORE(MicroSteps, 16);
204 198
       SERIAL_ECHOLNPAIR("...MicroSteps: ", MicroSteps,
205
-                        "   ADC_OUT: ", L6470_ADC_out);
199
+                        "   ADC_OUT: ", L6470_ADC_out,
200
+                        "   Vs_compensation: NA");
201
+
202
+      SERIAL_EOL();
206 203
 
207
-      SERIAL_ECHOLNPGM("   Vs_compensation: NA\n"
208
-                       "...KVAL_HOLD: NA"
204
+      SERIAL_ECHOLNPGM("...KVAL_HOLD: NA"
209 205
                        "   KVAL_RUN : NA"
210 206
                        "   KVAL_ACC: NA"
211 207
                        "   KVAL_DEC: NA"
@@ -232,7 +228,7 @@ void GcodeSuite::M906() {
232 228
 
233 229
   L64xxManager.pause_monitor(true); // Keep monitor_driver() from stealing status
234 230
 
235
-  #define L6470_SET_KVAL_HOLD(Q) stepper##Q.SetParam(L6470_KVAL_HOLD, value)
231
+  #define L6470_SET_KVAL_HOLD(Q) (AXIS_IS_L64XX(Q) ? stepper##Q.setTVALCurrent(value) : stepper##Q.SetParam(L6470_KVAL_HOLD, uint8_t(value)))
236 232
 
237 233
   DEBUG_ECHOLNPGM("M906");
238 234
 
@@ -242,7 +238,7 @@ void GcodeSuite::M906() {
242 238
     const uint8_t index = parser.byteval('I');
243 239
   #endif
244 240
 
245
-  LOOP_XYZE(i) if (uint8_t value = parser.byteval(axis_codes[i])) {
241
+  LOOP_XYZE(i) if (uint16_t value = parser.intval(axis_codes[i])) {
246 242
 
247 243
     report_current = false;
248 244
 

+ 41
- 30
Marlin/src/pins/stm32/pins_STEVAL_3DP001V1.h View File

@@ -68,18 +68,10 @@
68 68
 //  #define Z_MIN_PROBE_PIN  16  // PA4
69 69
 //#endif
70 70
 
71
-#define SCK_PIN            13   // PB13    SPI_S
72
-#define MISO_PIN           12   // PB14    SPI_M
73
-#define MOSI_PIN           11   // PB15    SPI_M
74
-
75
-#define L6470_CHAIN_SCK_PIN  17   // PA5
76
-#define L6470_CHAIN_MISO_PIN 18   // PA6
77
-#define L6470_CHAIN_MOSI_PIN 19   // PA7
78
-#define L6470_CHAIN_SS_PIN   16   // PA4
79
-
80
-//#define SCK_PIN   L6470_CHAIN_SCK_PIN
81
-//#define MISO_PIN  L6470_CHAIN_MISO_PIN
82
-//#define MOSI_PIN  L6470_CHAIN_MOSI_PIN
71
+//
72
+// Filament runout
73
+//
74
+//#define FIL_RUNOUT_PIN     53   // PA3    BED_THE
83 75
 
84 76
 //
85 77
 // Steppers
@@ -124,19 +116,34 @@
124 116
 #define E4_CS_PIN          16  // PA4     SPI_CS
125 117
 #define E5_CS_PIN          16  // PA4     SPI_CS
126 118
 
119
+#if HAS_L64XX
120
+  #define L6470_CHAIN_SCK_PIN  17   // PA5
121
+  #define L6470_CHAIN_MISO_PIN 18   // PA6
122
+  #define L6470_CHAIN_MOSI_PIN 19   // PA7
123
+  #define L6470_CHAIN_SS_PIN   16   // PA4
124
+
125
+  //#define SCK_PIN        L6470_CHAIN_SCK_PIN
126
+  //#define MISO_PIN       L6470_CHAIN_MISO_PIN
127
+  //#define MOSI_PIN       L6470_CHAIN_MOSI_PIN
128
+#else
129
+  //#define SCK_PIN        13   // PB13    SPI_S
130
+  //#define MISO_PIN       12   // PB14    SPI_M
131
+  //#define MOSI_PIN       11   // PB15    SPI_M
132
+#endif
133
+
127 134
 /**
128
- * macro to reset/enable L6474 chips
135
+ * Macro to reset/enable L6474 stepper drivers
129 136
  *
130
- * IMPORTANT - to disable (bypass) a L6474, install the corresponding
131
- *             resistor (R11 - R17) and change the "V" to zero for the
132
- *             corresponding pin.
137
+ * IMPORTANT - To disable (bypass) L6474s, install the corresponding
138
+ *             resistors (R11 - R17) and change the "V" to "0" for the
139
+ *             corresponding pins here:
133 140
  */
134
-#define ENABLE_RESET_L64XX_CHIPS(V)   do{OUT_WRITE(X_ENABLE_PIN, V);\
135
-                                         OUT_WRITE(Y_ENABLE_PIN, V);\
136
-                                         OUT_WRITE(Z_ENABLE_PIN, V);\
137
-                                         OUT_WRITE(E0_ENABLE_PIN,V);\
138
-                                         OUT_WRITE(E1_ENABLE_PIN,V);\
139
-                                         OUT_WRITE(E2_ENABLE_PIN,V);\
141
+#define ENABLE_RESET_L64XX_CHIPS(V)   do{ OUT_WRITE(X_ENABLE_PIN, V); \
142
+                                          OUT_WRITE(Y_ENABLE_PIN, V); \
143
+                                          OUT_WRITE(Z_ENABLE_PIN, V); \
144
+                                          OUT_WRITE(E0_ENABLE_PIN,V); \
145
+                                          OUT_WRITE(E1_ENABLE_PIN,V); \
146
+                                          OUT_WRITE(E2_ENABLE_PIN,V); \
140 147
                                         }while(0)
141 148
 
142 149
 //
@@ -146,7 +153,7 @@
146 153
 #define TEMP_1_PIN          4   // Analog input 4,  digital pin 55   PA1     E2_THERMISTOR
147 154
 #define TEMP_2_PIN          5   // Analog input 5,  digital pin 56   PA2     E3_THERMISTOR
148 155
 #define TEMP_BED_PIN        0   // Analog input 0,  digital pin 51   PC2     BED_THERMISTOR_1
149
-#define TEMP_BED_1_PIN      1`  // Analog input 1,  digital pin 52   PC3     BED_THERMISTOR_2
156
+#define TEMP_BED_1_PIN      1   // Analog input 1,  digital pin 52   PC3     BED_THERMISTOR_2
150 157
 #define TEMP_BED_2_PIN      2   // Analog input 2,  digital pin 53   PA3     BED_THERMISTOR_3
151 158
 
152 159
 //
@@ -171,7 +178,7 @@
171 178
 #define LED_PIN            -1   // 9 // PE1 green LED   Heart beat
172 179
 #define PS_ON_PIN          -1
173 180
 #define KILL_PIN           -1
174
-#define PWR_LOSS           -1   // Power loss / nAC_FAULT
181
+#define POWER_LOSS_PIN     -1   // PWR_LOSS / nAC_FAULT
175 182
 
176 183
 //
177 184
 // LCD / Controller
@@ -189,11 +196,6 @@
189 196
 //#define BTN_ENC            52   // PC3     BED_THE
190 197
 
191 198
 //
192
-// Filament runout
193
-//
194
-//#define FIL_RUNOUT_PIN     53   // PA3    BED_THE
195
-
196
-//
197 199
 // Extension pins
198 200
 //
199 201
 //#define EXT0_PIN           49   // PB0     E2_HEAT
@@ -225,7 +227,10 @@
225 227
 // 21   // PA14  JTAG_TCK/SWCLK
226 228
 // 22   // PB3   JTAG_TDO/SWO
227 229
 
228
-// SDCARD
230
+//
231
+// SD support
232
+//
233
+//#define SDIO_SUPPORT
229 234
 // 23   // PC8   SDIO_D0
230 235
 // 24   // PC9   SDIO_D1
231 236
 // 25   // PA15  SD_CARD_DETECT
@@ -234,6 +239,12 @@
234 239
 // 28   // PC12  SDIO_CK
235 240
 // 29   // PD2   SDIO_CMD
236 241
 
242
+#define SOFTWARE_SPI            // Use soft SPI for onboard SD
243
+#define SDSS               27   // PC11  SDIO_D3
244
+#define SCK_PIN            28   // PC12  SDIO_CK
245
+#define MISO_PIN           23   // PC8   SDIO_D0
246
+#define MOSI_PIN           29   // PD2   SDIO_CMD
247
+
237 248
 // OTG
238 249
 // 30   // PA11  OTG_DM
239 250
 // 31   // PA12  OTG_DP

+ 1
- 1
buildroot/share/PlatformIO/variants/STEVAL_F401VE/hal_conf_custom.h View File

@@ -55,7 +55,7 @@ extern "C" {
55 55
 #define HAL_I2C_MODULE_ENABLED
56 56
 /* #define HAL_SMBUS_MODULE_ENABLED   */
57 57
 /* #define HAL_I2S_MODULE_ENABLED   */
58
-/* #define HAL_IWDG_MODULE_ENABLED   */
58
+#define HAL_IWDG_MODULE_ENABLED
59 59
 /* #define HAL_LTDC_MODULE_ENABLED   */
60 60
 /* #define HAL_DSI_MODULE_ENABLED   */
61 61
 #define HAL_PWR_MODULE_ENABLED

+ 310
- 0
buildroot/share/PlatformIO/variants/STEVAL_F401VE/variant.cpp View File

@@ -0,0 +1,310 @@
1
+/*
2
+ *******************************************************************************
3
+ * Copyright (c) 2017, STMicroelectronics
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are met:
8
+ *
9
+ * 1. Redistributions of source code must retain the above copyright notice,
10
+ *    this list of conditions and the following disclaimer.
11
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ *    this list of conditions and the following disclaimer in the documentation
13
+ *    and/or other materials provided with the distribution.
14
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
15
+ *    may be used to endorse or promote products derived from this software
16
+ *    without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ *******************************************************************************
29
+ */
30
+
31
+#include "pins_arduino.h"
32
+
33
+#ifdef __cplusplus
34
+extern "C" {
35
+#endif
36
+
37
+#if defined(ARDUINO_STEVAL)
38
+// Pin number
39
+// This array allows to wrap Arduino pin number(Dx or x)
40
+// to STM32 PinName (PX_n)
41
+const PinName digitalPin[] = {
42
+  PA_9,  // TX
43
+  PA_10, // RX
44
+
45
+  // WIFI
46
+  PD_3,  // CTS
47
+  PD_4,  // RTS
48
+  PD_5,  // TX
49
+  PD_6,  // RX
50
+  PB_5,  // WIFI_WAKEUP
51
+  PE_11, // WIFI_RESET
52
+  PE_12, // WIFI_BOOT
53
+
54
+  // STATUS_LED
55
+  PE_1,  //STATUS_LED
56
+
57
+  // SPI USER
58
+  PB_12, // SPI_CS
59
+  PB_15, // SPI_MOSI
60
+  PB_14, // SPI_MISO
61
+  PB_13, // SPI_SCK
62
+
63
+  // I2C USER
64
+  PB_7,  // SDA
65
+  PB_6,  // SCL
66
+
67
+  // SPI
68
+  PA_4,  // SPI_CS
69
+  PA_5,  // SPI_SCK
70
+  PA_6,  // SPI_MISO
71
+  PA_7,  // SPI_MOSI
72
+
73
+  // JTAG
74
+  PA_13, // JTAG_TMS/SWDIO
75
+  PA_14, // JTAG_TCK/SWCLK
76
+  PB_3,  // JTAG_TDO/SWO
77
+
78
+  // SDCARD
79
+  PC_8,  // SDIO_D0
80
+  PC_9,  // SDIO_D1
81
+  PA_15, // SD_CARD_DETECT
82
+  PC_10, // SDIO_D2
83
+  PC_11, // SDIO_D3
84
+  PC_12, // SDIO_CK
85
+  PD_2,  // SDIO_CMD
86
+
87
+  // OTG
88
+  PA_11, // OTG_DM
89
+  PA_12, // OTG_DP
90
+
91
+  // IR/PROBE
92
+  PD_1,  // IR_OUT
93
+  PC_1,  // IR_ON
94
+
95
+  // USER_PINS
96
+  PD_7,  // USER3
97
+  PB_9,  // USER1
98
+  PE_0,  // USER2
99
+  PB_4,  // USER4
100
+
101
+  // USERKET
102
+  PE_7,  // USER_BUTTON
103
+
104
+  // ENDSTOPS
105
+  PD_8,  // X_STOP
106
+  PD_9,  // Y_STOP
107
+  PD_10, // Z_STOP
108
+  PD_11, // U_STOP
109
+  PA_8,  // V_STOP
110
+  PD_0,  // W_STOP
111
+
112
+  // HEATERS
113
+  PD_13, // BED_HEAT_2
114
+  PD_14, // BED_HEAT_1
115
+  PD_15, // BED_HEAT_3
116
+  PC_7,  // E1_HEAT_PWM
117
+  PB_0,  // E2_HEAT_PWM
118
+  PB_1,  // E3_HEAT_PWM
119
+
120
+  // THERMISTOR
121
+  PC_2,  // BED_THERMISTOR_1
122
+  PC_3,  // BED_THERMISTOR_2
123
+  PA_3,  // BED_THERMISTOR_3
124
+  PA_0,  // E1_THERMISTOR
125
+  PA_1,  // E2_THERMISTOR
126
+  PA_2,  // E3_THERMISTOR
127
+
128
+  // FANS
129
+  PC_4,  // E1_FAN
130
+  PC_5,  // E2_FAN
131
+  PE_8,  // E3_FAN
132
+
133
+  // X_MOTOR
134
+  PE_13, // X_RESET
135
+  PE_14, // X_PWM
136
+  PE_15, // X_DIR
137
+
138
+  // Y_MOTOR
139
+  PE_10, // Y_RESET
140
+  PB_10, // Y_PWM
141
+  PE_9,  // Y_DIR
142
+
143
+  // Z_MOTOR
144
+  PC_15, // Z_RESET
145
+  PC_6,  // Z_PWM
146
+  PC_0,  // Z_DIR
147
+
148
+  // E1_MOTOR
149
+  PC_14, // E1_RESET
150
+  PC_13, // E1_DIR
151
+  PD_12, // E1_PWM
152
+
153
+  // E2_MOTOR
154
+  PE_4,  // E2_RESET
155
+  PE_5,  // E2_PWM
156
+  PE_6,  // E2_DIR
157
+
158
+  // E3_MOTOR
159
+  PE_3,  // E3_RESET
160
+  PE_2,  // E3_DIR
161
+  PB_8   // E3_PWM
162
+};
163
+#endif
164
+
165
+#ifdef __cplusplus
166
+}
167
+#endif
168
+
169
+// ----------------------------------------------------------------------------
170
+
171
+#ifdef __cplusplus
172
+extern "C" {
173
+#endif
174
+/**
175
+  * @brief  System Clock Configuration
176
+  *         The system Clock is configured as follow :
177
+  *            System Clock source            = PLL (HSI)
178
+  *            SYSCLK(Hz)                     = 84000000
179
+  *            HCLK(Hz)                       = 84000000
180
+  *            AHB Prescaler                  = 1
181
+  *            APB1 Prescaler                 = 2
182
+  *            APB2 Prescaler                 = 1
183
+  *            HSI Frequency(Hz)              = 16000000
184
+  *            PLL_M                          = 16
185
+  *            PLL_N                          = 336
186
+  *            PLL_P                          = 4
187
+  *            PLL_Q                          = 7
188
+  *            VDD(V)                         = 3.3
189
+  *            Main regulator output voltage  = Scale2 mode
190
+  *            Flash Latency(WS)              = 2
191
+  * @param  None
192
+  * @retval None
193
+  */
194
+WEAK void SystemClock_Config(void)
195
+{
196
+  RCC_OscInitTypeDef RCC_OscInitStruct = {};
197
+  RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
198
+
199
+  /* Configure the main internal regulator output voltage */
200
+  __HAL_RCC_PWR_CLK_ENABLE();
201
+  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
202
+
203
+  /* Initializes the CPU, AHB and APB busses clocks */
204
+  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
205
+  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
206
+  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
207
+  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
208
+  RCC_OscInitStruct.PLL.PLLM = 15;
209
+  RCC_OscInitStruct.PLL.PLLN = 144;
210
+  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
211
+  RCC_OscInitStruct.PLL.PLLQ = 5;
212
+  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
213
+    Error_Handler();
214
+  }
215
+  /* Initializes the CPU, AHB and APB busses clocks */
216
+  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
217
+                                | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
218
+  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
219
+  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
220
+  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
221
+  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
222
+
223
+  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
224
+    Error_Handler();
225
+  }
226
+}
227
+
228
+#ifdef __cplusplus
229
+}
230
+#endif
231
+
232
+
233
+// PA_0  54 // E1_THERMISTOR
234
+// PA_1  55 // E2_THERMISTOR
235
+// PA_2  56 // E3_THERMISTOR
236
+// PA_3  53 // BED_THERMISTOR_3
237
+// PA_4  16 // SPI_CS
238
+// PA_5  17 // SPI_SCK
239
+// PA_6  18 // SPI_MISO
240
+// PA_7  19 // SPI_MOSI
241
+// PA_8  43 // V_STOP
242
+// PA_9   0 //TX
243
+// PA_10  1 //RX
244
+// PA_11 30 //OTG_DM
245
+// PA_12 31 //OTG_DP
246
+// PA_13 20 // JTAG_TMS/SWDIO
247
+// PA_14 21 // JTAG_TCK/SWCLK
248
+// PA_15 25 // SD_CARD_DETECT
249
+// PB_0  49 // E2_HEAT_PWM
250
+// PB_1  50 // E3_HEAT_PWM
251
+// PB_3  22 // JTAG_TDO/SWO
252
+// PB_4  37 // USER4
253
+// PB_5   6 // WIFI_WAKEUP
254
+// PB_6  15 // SCL
255
+// PB_7  14 // SDA
256
+// PB_8  77 // E3_PWM
257
+// PB_9  35 // USER1
258
+// PB_10 64 // Y_PWM
259
+// PB_12 10 // SPI_CS
260
+// PB_13 13 // SPI_SCK
261
+// PB_14 12 // SPI_MISO
262
+// PB_15 11 // SPI_MOSI
263
+// PC_0  68 // Z_DIR
264
+// PC_1  33 //IR_ON
265
+// PC_2  51 // BED_THERMISTOR_1
266
+// PC_3  52 // BED_THERMISTOR_2
267
+// PC_4  57 // E1_FAN
268
+// PC_5  58 // E2_FAN
269
+// PC_6  67 // Z_PWM
270
+// PC_7  48 // E1_HEAT_PWM
271
+// PC_8  23 // SDIO_D0
272
+// PC_9  24 // SDIO_D1
273
+// PC_10 26 // SDIO_D2
274
+// PC_11 27 // SDIO_D3
275
+// PC_12 28 // SDIO_CK
276
+// PC_13 70 // E1_DIR
277
+// PC_14 69 // E1_RESET
278
+// PC_15 66 // Z_RESET
279
+// PD_0  44 // W_STOP
280
+// PD_1  32 //IR_OUT
281
+// PD_2  29 // SDIO_CMD
282
+// PD_3   2 // CTS
283
+// PD_4   3 // RTS
284
+// PD_5   4 // TX
285
+// PD_6   5 // RX
286
+// PD_7  34 // USER3
287
+// PD_8  39 // X_STOP
288
+// PD_9  40 // Y_STOP
289
+// PD_10 41 // Z_STOP
290
+// PD_11 42 // U_STOP
291
+// PD_12 71 // E1_PWM
292
+// PD_13 45 // BED_HEAT_2
293
+// PD_14 46 // BED_HEAT_1
294
+// PD_15 47 // BED_HEAT_3
295
+// PE_0  36 // USER2
296
+// PE_1   9 // STATUS_LED
297
+// PE_2  76 // E3_DIR
298
+// PE_3  75 // E3_RESET
299
+// PE_4  72 // E2_RESET
300
+// PE_5  73 // E2_PWM
301
+// PE_6  74 // E2_DIR
302
+// PE_7  38 // USER_BUTTON
303
+// PE_8  59 // E3_FAN
304
+// PE_9  65 // Y_DIR
305
+// PE_10 63 // Y_RESET
306
+// PE_11  7 // WIFI_RESET
307
+// PE_12  8 // WIFI_BOOT
308
+// PE_13 60 // X_RESET
309
+// PE_14 61 // X_PWM
310
+// PE_15 62 // X_DIR

Loading…
Cancel
Save