1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 16:55:36 +03:00

Merge pull request #7439 from jflyper/bfdev-stdperiph-sdcard-quick-fix-after-shard-SPI

[SDCARD] Quick fix: Discard excess/bogus data in DR at prologue of spiTransferByte
This commit is contained in:
Michael Keller 2019-01-22 18:08:18 +13:00 committed by GitHub
commit eb2e2d2eb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -55,9 +55,11 @@
#define PP_CALL(macro, ...) macro(__VA_ARGS__)
#if !defined(UNUSED)
#define UNUSED(x) (void)(x)
#define UNUSED(x) (void)(x) // Variables and parameters that are not used
#endif
#define DISCARD(x) (void)(x) // To explicitly ignore result of x (usually an I/O register access).
#define STATIC_ASSERT(condition, name) _Static_assert((condition), #name)

View file

@ -113,6 +113,8 @@ uint8_t spiTransferByte(SPI_TypeDef *instance, uint8_t txByte)
{
uint16_t spiTimeout = 1000;
DISCARD(instance->DR);
while (SPI_I2S_GetFlagStatus(instance, SPI_I2S_FLAG_TXE) == RESET)
if ((spiTimeout--) == 0)
return spiTimeoutUserCallback(instance);
@ -152,7 +154,7 @@ bool spiTransfer(SPI_TypeDef *instance, const uint8_t *txData, uint8_t *rxData,
uint16_t spiTimeout = 1000;
uint8_t b;
instance->DR;
DISCARD(instance->DR);
while (len--) {
b = txData ? *(txData++) : 0xFF;
while (SPI_I2S_GetFlagStatus(instance, SPI_I2S_FLAG_TXE) == RESET) {