File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,17 @@ extern HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(SPI_HandleTypeDef *hspi);
81
81
#define HAS_32BIT_SPI_TRANSFERS 1
82
82
#endif // SPI_DATASIZE_X
83
83
84
+ /**
85
+ * Flush RX FIFO/input register of SPI interface and clear overrun flag.
86
+ */
87
+ static inline void spi_flush_rx (spi_t * obj )
88
+ {
89
+ #if defined(SPI_FLAG_FRLVL )
90
+ HAL_SPIEx_FlushRxFifo (& (SPI_S (obj )-> handle ));
91
+ #endif
92
+ LL_SPI_ClearFlag_OVR (SPI_INST (obj ));
93
+ }
94
+
84
95
void spi_get_capabilities (PinName ssel , bool slave , spi_capabilities_t * cap )
85
96
{
86
97
if (slave ) {
@@ -1373,10 +1384,15 @@ void spi_abort_asynch(spi_t *obj)
1373
1384
NVIC_DisableIRQ (irq_n );
1374
1385
1375
1386
// clean-up
1376
- __HAL_SPI_DISABLE ( handle );
1387
+ LL_SPI_Disable ( SPI_INST ( obj ) );
1377
1388
HAL_SPI_DeInit (handle );
1378
1389
HAL_SPI_Init (handle );
1379
- __HAL_SPI_ENABLE (handle );
1390
+ // cleanup input buffer
1391
+ spi_flush_rx (obj );
1392
+ // enable SPI back if it isn't 3-wire mode
1393
+ if (handle -> Init .Direction != SPI_DIRECTION_1LINE ) {
1394
+ LL_SPI_Enable (SPI_INST (obj ));
1395
+ }
1380
1396
}
1381
1397
1382
1398
#endif //DEVICE_SPI_ASYNCH
You can’t perform that action at this time.
0 commit comments