You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/10/18 06:16:24 UTC

[4/5] incubator-mynewt-core git commit: stm32f4 hal spi slave; when SS drops, don't enable SPI until contents of DR have been replaced. Fix the state when user of SPI slave calls TX while SS is low.

stm32f4 hal spi slave; when SS drops, don't enable SPI until contents
of DR have been replaced. Fix the state when user of SPI slave calls TX
while SS is low.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/7534cf93
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7534cf93
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7534cf93

Branch: refs/heads/develop
Commit: 7534cf934c8ba1e06ecc76792df247752d9cbf6f
Parents: fb86231
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Oct 17 23:11:26 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Oct 17 23:15:07 2016 -0700

----------------------------------------------------------------------
 hw/mcu/stm/stm32f4xx/src/hal_spi.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7534cf93/hw/mcu/stm/stm32f4xx/src/hal_spi.c
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_spi.c b/hw/mcu/stm/stm32f4xx/src/hal_spi.c
index 2d968e1..c0de992 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_spi.c
+++ b/hw/mcu/stm/stm32f4xx/src/hal_spi.c
@@ -55,6 +55,7 @@ struct stm32f4_hal_spi {
 static struct stm32f4_spi_stat {
     uint32_t irq;
     uint32_t ss_irq;
+    uint32_t tx;
 } spi_stat;
 
 static void spi_irq_handler(struct stm32f4_hal_spi *spi);
@@ -207,7 +208,6 @@ spi_ss_isr(void *arg)
     ss = hal_gpio_read(spi->cfg->ss_pin);
     if (ss == 0 && !spi->selected) {
         reg = spi->handle.Instance->CR1;
-        reg |= SPI_CR1_SPE;
         reg &= ~SPI_CR1_SSI;
         spi->handle.Instance->CR1 = reg;
         if (spi->tx_in_prog) {
@@ -659,12 +659,14 @@ hal_spi_txrx_noblock(int spi_num, void *txbuf, void *rxbuf, int len)
     STM32F4_HAL_SPI_RESOLVE(spi_num, spi);
 
     __HAL_DISABLE_INTERRUPTS(sr);
+    spi_stat.tx++;
     rc = -1;
     if (!spi->slave) {
         rc = HAL_SPI_TransmitReceive_IT(&spi->handle, txbuf, rxbuf, len);
     } else {
         spi->tx_in_prog = 1;
         if (spi->selected) {
+            spi->handle.State = HAL_SPI_STATE_READY;
             rc = HAL_SPI_TransmitReceive_IT(&spi->handle, txbuf, rxbuf, len);
         } else {
             rc = 0;
@@ -750,6 +752,7 @@ uint16_t hal_spi_tx_val(int spi_num, uint16_t val)
         len = sizeof(uint16_t);
     }
     __HAL_DISABLE_INTERRUPTS(sr);
+    spi_stat.tx++;
     rc = HAL_SPI_TransmitReceive(&spi->handle,(uint8_t *)&val,
                                  (uint8_t *)&retval, len,
                                  STM32F4_HAL_SPI_TIMEOUT);
@@ -801,6 +804,7 @@ hal_spi_txrx(int spi_num, void *txbuf, void *rxbuf, int len)
         goto err;
     }
     __HAL_DISABLE_INTERRUPTS(sr);
+    spi_stat.tx++;
     __HAL_SPI_ENABLE(&spi->handle);
     rc = HAL_SPI_TransmitReceive(&spi->handle, (uint8_t *)txbuf,
                                  (uint8_t *)rxbuf, len,