diff --git a/src/esp32/esp32_spi_master.c b/src/esp32/esp32_spi_master.c index 5cd1870..e19f2f8 100644 --- a/src/esp32/esp32_spi_master.c +++ b/src/esp32/esp32_spi_master.c @@ -264,7 +264,8 @@ static void esp32_spi_get_rx_data(spi_dev_t *dev, uint8_t *data, size_t skip, if (skip > 0) { skip--; } else { - data[i++] = byte; + if (data != NULL) data[i] = byte; + ++i; } w >>= 8; } @@ -314,7 +315,7 @@ static bool mgos_spi_run_txn_fd(struct mgos_spi *c, const void *tx_data, } esp32_spi_get_rx_data(dev, rxdp, 0, dlen); txdp += dlen; - rxdp += dlen; + if (rxdp != NULL) rxdp += dlen; } return true; diff --git a/src/stm32/stm32_spi_master_gspi.c b/src/stm32/stm32_spi_master_gspi.c index de077f8..e7d43bf 100644 --- a/src/stm32/stm32_spi_master_gspi.c +++ b/src/stm32/stm32_spi_master_gspi.c @@ -102,6 +102,7 @@ bool stm32_gspi_run_txn_fd(struct mgos_spi *c, const struct mgos_spi_txn *txn) { size_t len = txn->fd.len; const uint8_t *tx_data = (const uint8_t *) txn->fd.tx_data; uint8_t *rx_data = (uint8_t *) txn->fd.rx_data; + bool discard_rx = (txn->fd.rx_data == NULL); volatile uint8_t *drp = (volatile uint8_t *) &c->regs->DR; if (c->debug) { @@ -128,7 +129,7 @@ bool stm32_gspi_run_txn_fd(struct mgos_spi *c, const struct mgos_spi_txn *txn) { if (c->debug) { LOG(LL_DEBUG, ("read 0x%02x", byte)); } - *rx_data++ = byte; + if (!discard_rx) *rx_data++ = byte; } len--; }