This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 1777878cb42 drivers/spi: extend spi_transfer for protocol backend use
1777878cb42 is described below

commit 1777878cb42d5de3ea883f3198a742694778de42
Author: p-szafonimateusz <[email protected]>
AuthorDate: Tue Jul 14 15:12:40 2026 +0200

    drivers/spi: extend spi_transfer for protocol backend use
    
    Let a sequence with keepcs bypass the lower-half exchangeseqs, which
    de-selects at the end of the sequence, and propagate SPI_EXCHANGE
    errors instead of silently reporting OK.
    
    Signed-off-by: p-szafonimateusz <[email protected]>
---
 drivers/spi/spi_transfer.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi_transfer.c b/drivers/spi/spi_transfer.c
index 9c49be5307c..2a00a10ed57 100644
--- a/drivers/spi/spi_transfer.c
+++ b/drivers/spi/spi_transfer.c
@@ -64,7 +64,11 @@ int spi_transfer(FAR struct spi_dev_s *spi, FAR struct 
spi_sequence_s *seq)
 
   DEBUGASSERT(spi != NULL && seq != NULL && seq->trans != NULL);
 
-  if (spi->ops->exchangeseqs)
+  /* Lower-half exchangeseqs implementations de-select at the end of the
+   * sequence, so a sequence that keeps CS must use the generic loop.
+   */
+
+  if (spi->ops->exchangeseqs && !seq->keepcs)
     {
       /* -ENOTSUP means: not handled, use the generic loop below */
 
@@ -149,7 +153,13 @@ int spi_transfer(FAR struct spi_dev_s *spi, FAR struct 
spi_sequence_s *seq)
 
       /* Perform the transfer */
 
-      SPI_EXCHANGE(spi, trans->txbuffer, trans->rxbuffer, trans->nwords);
+      ret = SPI_EXCHANGE(spi, trans->txbuffer, trans->rxbuffer,
+                         trans->nwords);
+      if (ret < 0)
+        {
+          spierr("ERROR: SPI_EXCHANGE failed: %d\n", ret);
+          break;
+        }
 
       /* Possibly de-select the SPI device after the transfer */
 

Reply via email to