Sfoglia il codice sorgente

Minor SPI fixes, systick_callback for STM32F1 HAL compatibility (#19565)

Victor Oliveira 4 anni fa
parent
commit
ec5b78d18b

+ 7
- 2
Marlin/src/HAL/STM32/HAL.cpp Vedi File

63
 void HAL_init() {
63
 void HAL_init() {
64
   FastIO_init();
64
   FastIO_init();
65
 
65
 
66
-  #if ENABLED(SDSUPPORT) && DISABLED(SDIO_SUPPORT)
66
+  #if ENABLED(SDSUPPORT) && DISABLED(SDIO_SUPPORT) && (defined(SDSS) && SDSS != -1)
67
     OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
67
     OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
68
   #endif
68
   #endif
69
 
69
 
122
 
122
 
123
 // TODO: Make sure this doesn't cause any delay
123
 // TODO: Make sure this doesn't cause any delay
124
 void HAL_adc_start_conversion(const uint8_t adc_pin) { HAL_adc_result = analogRead(adc_pin); }
124
 void HAL_adc_start_conversion(const uint8_t adc_pin) { HAL_adc_result = analogRead(adc_pin); }
125
-
126
 uint16_t HAL_adc_get_result() { return HAL_adc_result; }
125
 uint16_t HAL_adc_get_result() { return HAL_adc_result; }
127
 
126
 
127
+// Reset the system (to initiate a firmware flash)
128
 void flashFirmware(const int16_t) { NVIC_SystemReset(); }
128
 void flashFirmware(const int16_t) { NVIC_SystemReset(); }
129
 
129
 
130
+// Maple Compatibility
131
+systickCallback_t systick_user_callback;
132
+void systick_attach_callback(systickCallback_t cb) { systick_user_callback = cb; }
133
+void HAL_SYSTICK_Callback() { if (systick_user_callback) systick_user_callback(); }
134
+
130
 #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
135
 #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC

+ 5
- 0
Marlin/src/HAL/STM32/HAL.h Vedi File

177
 
177
 
178
 #define PLATFORM_M997_SUPPORT
178
 #define PLATFORM_M997_SUPPORT
179
 void flashFirmware(const int16_t);
179
 void flashFirmware(const int16_t);
180
+
181
+// Maple Compatibility
182
+typedef void (*systickCallback_t)(void);
183
+void systick_attach_callback(systickCallback_t cb);
184
+void HAL_SYSTICK_Callback();

+ 2
- 12
Marlin/src/HAL/STM32/HAL_SPI.cpp Vedi File

132
    * @details Only configures SS pin since stm32duino creates and initialize the SPI object
132
    * @details Only configures SS pin since stm32duino creates and initialize the SPI object
133
    */
133
    */
134
   void spiBegin() {
134
   void spiBegin() {
135
-    #if !PIN_EXISTS(SS)
136
-      #error "SS_PIN not defined!"
135
+    #if PIN_EXISTS(SS)
136
+      OUT_WRITE(SS_PIN, HIGH);
137
     #endif
137
     #endif
138
-
139
-    OUT_WRITE(SS_PIN, HIGH);
140
   }
138
   }
141
 
139
 
142
   // Configure SPI for specified SPI speed
140
   // Configure SPI for specified SPI speed
173
    * @details
171
    * @details
174
    */
172
    */
175
   uint8_t spiRec() {
173
   uint8_t spiRec() {
176
-    SPI.beginTransaction(spiConfig);
177
     uint8_t returnByte = SPI.transfer(0xFF);
174
     uint8_t returnByte = SPI.transfer(0xFF);
178
-    SPI.endTransaction();
179
     return returnByte;
175
     return returnByte;
180
   }
176
   }
181
 
177
 
191
   void spiRead(uint8_t* buf, uint16_t nbyte) {
187
   void spiRead(uint8_t* buf, uint16_t nbyte) {
192
     if (nbyte == 0) return;
188
     if (nbyte == 0) return;
193
     memset(buf, 0xFF, nbyte);
189
     memset(buf, 0xFF, nbyte);
194
-    SPI.beginTransaction(spiConfig);
195
     SPI.transfer(buf, nbyte);
190
     SPI.transfer(buf, nbyte);
196
-    SPI.endTransaction();
197
   }
191
   }
198
 
192
 
199
   /**
193
   /**
204
    * @details
198
    * @details
205
    */
199
    */
206
   void spiSend(uint8_t b) {
200
   void spiSend(uint8_t b) {
207
-    SPI.beginTransaction(spiConfig);
208
     SPI.transfer(b);
201
     SPI.transfer(b);
209
-    SPI.endTransaction();
210
   }
202
   }
211
 
203
 
212
   /**
204
   /**
219
    */
211
    */
220
   void spiSendBlock(uint8_t token, const uint8_t* buf) {
212
   void spiSendBlock(uint8_t token, const uint8_t* buf) {
221
     uint8_t rxBuf[512];
213
     uint8_t rxBuf[512];
222
-    SPI.beginTransaction(spiConfig);
223
     SPI.transfer(token);
214
     SPI.transfer(token);
224
     SPI.transfer((uint8_t*)buf, &rxBuf, 512);
215
     SPI.transfer((uint8_t*)buf, &rxBuf, 512);
225
-    SPI.endTransaction();
226
   }
216
   }
227
 
217
 
228
 #endif // SOFTWARE_SPI
218
 #endif // SOFTWARE_SPI

Loading…
Annulla
Salva