You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2021/07/29 21:28:51 UTC

[mynewt-core] branch master updated: hw/bus/spi_hal: Fix bus_spi_write_read

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

vipulrahane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 024ef38  hw/bus/spi_hal: Fix bus_spi_write_read
     new 5450a93  Merge pull request #2644 from kasjer/kasjer/fix-spi_hal-bus_write_read
024ef38 is described below

commit 024ef3818446701d3c8a7ccdc70ecb4f74efd03a
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Mon Jul 26 09:17:42 2021 +0200

    hw/bus/spi_hal: Fix bus_spi_write_read
    
    Function bus_spi_write_read() was calling hal_spi_txrx()
    with NULL for txbuf for transactions involving more then 16 bytes.
    NULL pointer is not valid for this function.
    When code was build with SPI_HAL_USE_NOBLOCK enabled, zeroed receive buffer
    was already used as argument for transmit buffer.
    Same approach is now used when SPI_HAL_USE_NOBLOCK is not set.
    
    For data reads 0xFF is used for MOSI line just to be consistent.
    Some places used 0 some had 0xFF now 0xFF is used as it was
    originally.
---
 hw/bus/drivers/spi_hal/src/spi_hal.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/bus/drivers/spi_hal/src/spi_hal.c b/hw/bus/drivers/spi_hal/src/spi_hal.c
index 1404456..5832fee 100644
--- a/hw/bus/drivers/spi_hal/src/spi_hal.c
+++ b/hw/bus/drivers/spi_hal/src/spi_hal.c
@@ -212,7 +212,7 @@ bus_spi_write_read(struct bus_dev *bdev, struct bus_node *bnode,
 #if MYNEWT_VAL(SPI_HAL_USE_NOBLOCK)
     if (wlength + rlength <= sizeof(buf)) {
         memcpy(buf, wbuf, wlength);
-        memset(buf + wlength, 0, rlength);
+        memset(buf + wlength, 0xFF, rlength);
         rc = hal_spi_txrx_noblock(dev->spi_dev.cfg.spi_num, buf, buf, wlength + rlength);
         if (rc == 0) {
             os_sem_pend(&dev->sem, OS_TIMEOUT_NEVER);
@@ -222,7 +222,7 @@ bus_spi_write_read(struct bus_dev *bdev, struct bus_node *bnode,
         rc = hal_spi_txrx_noblock(dev->spi_dev.cfg.spi_num, (uint8_t *)wbuf, NULL, wlength);
         if (rc == 0) {
             os_sem_pend(&dev->sem, OS_TIMEOUT_NEVER);
-            memset(rbuf, 0, rlength);
+            memset(rbuf, 0xFF, rlength);
             rc = hal_spi_txrx_noblock(dev->spi_dev.cfg.spi_num, rbuf, rbuf, rlength);
             if (rc == 0) {
                 os_sem_pend(&dev->sem, OS_TIMEOUT_NEVER);
@@ -239,7 +239,8 @@ bus_spi_write_read(struct bus_dev *bdev, struct bus_node *bnode,
     } else {
         rc = hal_spi_txrx(dev->spi_dev.cfg.spi_num, (uint8_t *)wbuf, NULL, wlength);
         if (rc == 0) {
-            rc = hal_spi_txrx(dev->spi_dev.cfg.spi_num, NULL, rbuf, rlength);
+            memset(rbuf, 0xFF, rlength);
+            rc = hal_spi_txrx(dev->spi_dev.cfg.spi_num, rbuf, rbuf, rlength);
         }
     }
 #endif