Skip to content

Commit 62af625

Browse files
authored
STM32F1Minor SPI fixes, systick_callback for HAL compatibility (#19565)
1 parent cf61562 commit 62af625

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

Marlin/src/HAL/STM32/HAL.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ uint16_t HAL_adc_result;
6363
void HAL_init() {
6464
FastIO_init();
6565

66-
#if ENABLED(SDSUPPORT) && DISABLED(SDIO_SUPPORT)
66+
#if ENABLED(SDSUPPORT) && DISABLED(SDIO_SUPPORT) && (defined(SDSS) && SDSS != -1)
6767
OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
6868
#endif
6969

@@ -122,9 +122,14 @@ extern "C" {
122122

123123
// TODO: Make sure this doesn't cause any delay
124124
void HAL_adc_start_conversion(const uint8_t adc_pin) { HAL_adc_result = analogRead(adc_pin); }
125-
126125
uint16_t HAL_adc_get_result() { return HAL_adc_result; }
127126

127+
// Reset the system (to initiate a firmware flash)
128128
void flashFirmware(const int16_t) { NVIC_SystemReset(); }
129129

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+
130135
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC

Marlin/src/HAL/STM32/HAL.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,8 @@ uint16_t HAL_adc_get_result();
177177

178178
#define PLATFORM_M997_SUPPORT
179179
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();

Marlin/src/HAL/STM32/HAL_SPI.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,9 @@ static SPISettings spiConfig;
132132
* @details Only configures SS pin since stm32duino creates and initialize the SPI object
133133
*/
134134
void spiBegin() {
135-
#if !PIN_EXISTS(SS)
136-
#error "SS_PIN not defined!"
135+
#if PIN_EXISTS(SS)
136+
OUT_WRITE(SS_PIN, HIGH);
137137
#endif
138-
139-
OUT_WRITE(SS_PIN, HIGH);
140138
}
141139

142140
// Configure SPI for specified SPI speed
@@ -173,9 +171,7 @@ static SPISettings spiConfig;
173171
* @details
174172
*/
175173
uint8_t spiRec() {
176-
SPI.beginTransaction(spiConfig);
177174
uint8_t returnByte = SPI.transfer(0xFF);
178-
SPI.endTransaction();
179175
return returnByte;
180176
}
181177

@@ -191,9 +187,7 @@ static SPISettings spiConfig;
191187
void spiRead(uint8_t* buf, uint16_t nbyte) {
192188
if (nbyte == 0) return;
193189
memset(buf, 0xFF, nbyte);
194-
SPI.beginTransaction(spiConfig);
195190
SPI.transfer(buf, nbyte);
196-
SPI.endTransaction();
197191
}
198192

199193
/**
@@ -204,9 +198,7 @@ static SPISettings spiConfig;
204198
* @details
205199
*/
206200
void spiSend(uint8_t b) {
207-
SPI.beginTransaction(spiConfig);
208201
SPI.transfer(b);
209-
SPI.endTransaction();
210202
}
211203

212204
/**
@@ -219,10 +211,8 @@ static SPISettings spiConfig;
219211
*/
220212
void spiSendBlock(uint8_t token, const uint8_t* buf) {
221213
uint8_t rxBuf[512];
222-
SPI.beginTransaction(spiConfig);
223214
SPI.transfer(token);
224215
SPI.transfer((uint8_t*)buf, &rxBuf, 512);
225-
SPI.endTransaction();
226216
}
227217

228218
#endif // SOFTWARE_SPI

0 commit comments

Comments
 (0)