Skip to content

Commit b9e53e9

Browse files
committed
revert(spi): drop board-specific workarounds
1 parent 4b38d5a commit b9e53e9

3 files changed

Lines changed: 5 additions & 50 deletions

File tree

libraries/SPI/src/SPI.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
SPIClass SPI;
1515

16-
void SPIClass::configSpi(const SPISettings &settings, bool force)
16+
void SPIClass::configSpi(const SPISettings &settings)
1717
{
18-
if (force || _spiSettings != settings) {
18+
if (_spiSettings != settings) {
1919
_spiSettings = settings;
2020

2121
uint32_t clock = settings.getClockFreq();
@@ -79,7 +79,7 @@ void SPIClass::begin(SPIBusMode busMode)
7979
SPI_MODE0,
8080
busMode
8181
);
82-
configSpi(defaultSettings, true);
82+
configSpi(defaultSettings);
8383
}
8484

8585
/**

libraries/SPI/src/SPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class SPIClass : public HardwareSPI {
135135
/* Current SPISettings */
136136
SPISettings _spiSettings = SPISettings();
137137

138-
void configSpi(const SPISettings &settings, bool force = false);
138+
void configSpi(const SPISettings &settings);
139139
};
140140

141141
extern SPIClass SPI;

libraries/SPI/src/utility/spi_com.c

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,6 @@
2020
extern "C" {
2121
#endif
2222

23-
#if defined(USE_HALV2_DRIVER)
24-
/* HAL v2 polling APIs use HAL_GetTick() for their timeout. On the current
25-
* Arduino C5 clock path that tick is not guaranteed to advance while polling,
26-
* so use the Arduino microsecond clock to bound LL polling instead. */
27-
static bool spi_transfer_timed_out(uint32_t start_us)
28-
{
29-
return (SPI_TRANSFER_TIMEOUT != HAL_MAX_DELAY)
30-
&& ((uint32_t)(micros() - start_us) >= (SPI_TRANSFER_TIMEOUT * 1000UL));
31-
}
32-
#endif
33-
3423
/* Private Functions */
3524
/**
3625
* @brief return clock freq of an SPI instance
@@ -575,22 +564,13 @@ spi_status_e spi_transfer(spi_t *obj, const uint8_t *tx_buffer, uint8_t *rx_buff
575564
{
576565
spi_status_e ret = SPI_OK;
577566
uint32_t tickstart, size = len;
578-
#if defined(USE_HALV2_DRIVER)
579-
uint32_t start_us;
580-
#endif
581-
if (obj == NULL || obj->spi == NP) {
582-
return SPI_ERROR;
583-
}
584567
SPI_TypeDef *_SPI = obj->spi;
585568
uint8_t *tx_buf = (uint8_t *)tx_buffer;
586569

587570
if (len == 0) {
588571
ret = SPI_ERROR;
589572
} else {
590573
tickstart = HAL_GetTick();
591-
#if defined(USE_HALV2_DRIVER)
592-
start_us = micros();
593-
#endif
594574

595575
#if defined(SPI_CR2_TSIZE)
596576
/* Start transfer */
@@ -601,32 +581,14 @@ spi_status_e spi_transfer(spi_t *obj, const uint8_t *tx_buffer, uint8_t *rx_buff
601581

602582
while (size--) {
603583
#if defined(SPI_SR_TXP)
604-
#if defined(USE_HALV2_DRIVER)
605-
while (!LL_SPI_IsActiveFlag_TXP(_SPI)) {
606-
if (spi_transfer_timed_out(start_us)) {
607-
ret = SPI_TIMEOUT;
608-
goto spi_transfer_end;
609-
}
610-
}
611-
#else
612584
while (!LL_SPI_IsActiveFlag_TXP(_SPI));
613-
#endif
614585
#else
615586
while (!LL_SPI_IsActiveFlag_TXE(_SPI));
616587
#endif
617588
LL_SPI_TransmitData8(_SPI, tx_buf ? *tx_buf++ : 0XFF);
618589

619590
#if defined(SPI_SR_RXP)
620-
#if defined(USE_HALV2_DRIVER)
621-
while (!LL_SPI_IsActiveFlag_RXP(_SPI)) {
622-
if (spi_transfer_timed_out(start_us)) {
623-
ret = SPI_TIMEOUT;
624-
goto spi_transfer_end;
625-
}
626-
}
627-
#else
628591
while (!LL_SPI_IsActiveFlag_RXP(_SPI));
629-
#endif
630592
#else
631593
while (!LL_SPI_IsActiveFlag_RXNE(_SPI));
632594
#endif
@@ -636,24 +598,17 @@ spi_status_e spi_transfer(spi_t *obj, const uint8_t *tx_buffer, uint8_t *rx_buff
636598
LL_SPI_ReceiveData8(_SPI);
637599
}
638600
if ((SPI_TRANSFER_TIMEOUT != HAL_MAX_DELAY) &&
639-
#if defined(USE_HALV2_DRIVER)
640-
(spi_transfer_timed_out(start_us))) {
641-
#else
642601
(HAL_GetTick() - tickstart >= SPI_TRANSFER_TIMEOUT)) {
643-
#endif
644602
ret = SPI_TIMEOUT;
645603
break;
646604
}
647605
}
648606

649607
#if defined(SPI_IFCR_EOTC)
650-
spi_transfer_end:
651608
// Add a delay before disabling SPI otherwise last-bit/last-clock may be truncated
652609
// See https://github.com/stm32duino/Arduino_Core_STM32/issues/1294
653610
// Computed delay is half SPI clock
654-
if (ret == SPI_OK) {
655-
delayMicroseconds(obj->disable_delay);
656-
}
611+
delayMicroseconds(obj->disable_delay);
657612

658613
/* Close transfer */
659614
/* Clear flags */

0 commit comments

Comments
 (0)