Skip to content

Commit e22cb69

Browse files
committed
fix[STM32][SPI]: ignore benign Tx-only OVR after async completion
1 parent 70bbd28 commit e22cb69

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

  • bsp/stm32/libraries/HAL_Drivers/drivers

bsp/stm32/libraries/HAL_Drivers/drivers/drv_spi.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ static rt_ssize_t spixfer(struct rt_spi_device *device, struct rt_spi_message *m
485485
#endif /* BSP_SPI_USING_DMA */
486486

487487
#ifdef BSP_SPI_USING_INT
488-
rt_bool_t int_eligible = (send_length >= BSP_SPI_INT_TRANS_MIN_LEN);
488+
rt_bool_t int_eligible = (send_length >= BSP_SPI_INT_TRANS_MIN_LEN);
489489
#if defined(BSP_SPI_TX_USING_INT)
490490
rt_bool_t use_tx_int = int_eligible && spi_drv->spi_dma_flag & RT_DEVICE_FLAG_INT_TX;
491491
#else
@@ -602,10 +602,29 @@ static rt_ssize_t spixfer(struct rt_spi_device *device, struct rt_spi_message *m
602602

603603
if (spi_handle->ErrorCode != HAL_SPI_ERROR_NONE)
604604
{
605-
state = HAL_ERROR;
606-
need_abort = RT_TRUE;
607-
LOG_E("SPI async transfer failed, error code: 0x%08x", spi_handle->ErrorCode);
608-
goto transfer_cleanup;
605+
rt_uint32_t err = spi_handle->ErrorCode;
606+
rt_bool_t tx_only = (message->send_buf != RT_NULL) && (message->recv_buf == RT_NULL);
607+
rt_bool_t ovr_only = ((err & HAL_SPI_ERROR_OVR) != 0U) && ((err & ~(HAL_SPI_ERROR_OVR | HAL_SPI_ERROR_ABORT)) == 0U);
608+
609+
/**
610+
* Ignore the expected OVR from a completed Tx-only transfer.
611+
*
612+
* In 2-line SPI mode, Tx-only transfer still receives data from
613+
* MISO. Since no RX buffer is provided, the received data is not
614+
* read and HAL may latch OVR after async Tx completion.
615+
*/
616+
if (tx_only && ovr_only && (spi_handle->Init.Direction == SPI_DIRECTION_2LINES) && (spi_handle->TxXferCount == 0U))
617+
{
618+
__HAL_SPI_CLEAR_OVRFLAG(spi_handle);
619+
spi_handle->ErrorCode = HAL_SPI_ERROR_NONE;
620+
}
621+
else
622+
{
623+
state = HAL_ERROR;
624+
need_abort = RT_TRUE;
625+
LOG_E("SPI async transfer failed, error code: 0x%08x", spi_handle->ErrorCode);
626+
goto transfer_cleanup;
627+
}
609628
}
610629
}
611630
#endif /* BSP_SPI_USING_IRQ */

0 commit comments

Comments
 (0)