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:21 UTC

[1/5] incubator-mynewt-core git commit: spitest; also set the slave baudrate, so that GPIO io speed can be matched. Drop the default baudrate.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 4cd926638 -> 3c8b7f436


spitest; also set the slave baudrate, so that GPIO io speed can
be matched. Drop the default baudrate.


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/3c8b7f43
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3c8b7f43
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3c8b7f43

Branch: refs/heads/develop
Commit: 3c8b7f436c9eebb0014d005e5e960f9ee2b63494
Parents: 7534cf9
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Oct 17 23:14:05 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Oct 17 23:15:07 2016 -0700

----------------------------------------------------------------------
 apps/spitest/src/main.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3c8b7f43/apps/spitest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/spitest/src/main.c b/apps/spitest/src/main.c
index a7652ef..0059bc5 100755
--- a/apps/spitest/src/main.c
+++ b/apps/spitest/src/main.c
@@ -60,6 +60,8 @@ struct os_sem g_test_sem;
 /* For LED toggling */
 int g_led_pin;
 
+#define SPI_BAUDRATE 500
+
 #if MYNEWT_VAL(SPI_MASTER) || MYNEWT_VAL(SPI_0_MASTER)
 #define SPI_MASTER 1
 #endif
@@ -147,7 +149,7 @@ sblinky_spi_cfg(int spi_num)
 
     my_spi.data_order = HAL_SPI_MSB_FIRST;
     my_spi.data_mode = HAL_SPI_MODE0;
-    my_spi.baudrate = 8000;
+    my_spi.baudrate = SPI_BAUDRATE;
     my_spi.word_size = HAL_SPI_WORD_SIZE_8BIT;
     spi_id = 0;
     hal_spi_config(spi_id, &my_spi);
@@ -191,7 +193,7 @@ sblinky_spi_cfg(int spi_num)
 
     my_spi.data_order = HAL_SPI_MSB_FIRST;
     my_spi.data_mode = HAL_SPI_MODE0;
-    my_spi.baudrate = 0;
+    my_spi.baudrate =  SPI_BAUDRATE;
     my_spi.word_size = HAL_SPI_WORD_SIZE_8BIT;
     spi_id = SPI_SLAVE_ID;
     hal_spi_config(spi_id, &my_spi);
@@ -311,6 +313,9 @@ task1_handler(void *arg)
 #endif
 
 #ifdef SPI_SLAVE
+int prev_len;
+uint8_t prev_buf[32];
+
 void
 task1_handler(void *arg)
 {
@@ -347,6 +352,7 @@ task1_handler(void *arg)
             assert(rc == 0);
         } else {
             /* transmit back what we just received */
+            memcpy(prev_buf, g_spi_tx_buf, 32);
             memset(g_spi_tx_buf, 0xaa, 32);
             memcpy(g_spi_tx_buf, g_spi_rx_buf, spi_cb_obj.txlen);
             rc = hal_spi_txrx_noblock(SPI_SLAVE_ID, g_spi_tx_buf, g_spi_rx_buf,


[5/5] incubator-mynewt-core git commit: stm32f4 spi; match GPIO IO speed setting to SPI baudrate.

Posted by ma...@apache.org.
stm32f4 spi; match GPIO IO speed setting to SPI baudrate.


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/4b468ce3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4b468ce3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4b468ce3

Branch: refs/heads/develop
Commit: 4b468ce31c5874335e2a0b056032f3a5fdf71504
Parents: eeb5ac0
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Oct 17 15:51:57 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 | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b468ce3/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 5033c42..2d968e1 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_spi.c
+++ b/hw/mcu/stm/stm32f4xx/src/hal_spi.c
@@ -488,7 +488,13 @@ hal_spi_config(int spi_num, struct hal_spi_settings *settings)
 
     gpio.Mode = GPIO_MODE_AF_PP;
     gpio.Pull = GPIO_NOPULL;
-    gpio.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+    if (settings->baudrate <= 2000) {
+        gpio.Speed = GPIO_SPEED_FREQ_LOW;
+    } else if (settings->baudrate <= 12500) {
+        gpio.Speed = GPIO_SPEED_FREQ_MEDIUM;
+    } else {
+        gpio.Speed = GPIO_SPEED_FREQ_HIGH;
+    }
 
     /* Enable the clocks for this SPI */
     switch (spi_num) {
@@ -665,7 +671,7 @@ hal_spi_txrx_noblock(int spi_num, void *txbuf, void *rxbuf, int len)
             spi->handle.pTxBuffPtr = txbuf;
             spi->handle.TxXferSize = len;
             spi->handle.pRxBuffPtr = rxbuf;
-            spi->handle.RxXferSize  = len;
+            spi->handle.RxXferSize = len;
         }
     }
     __HAL_ENABLE_INTERRUPTS(sr);


[3/5] incubator-mynewt-core git commit: stm32f4 spi; simplify code by having SPI run NSS with HW, but without actually assigning pin. This simplifies code.

Posted by ma...@apache.org.
stm32f4 spi; simplify code by having SPI run NSS with HW, but without
actually assigning pin. This simplifies code.


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/eeb5ac06
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/eeb5ac06
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/eeb5ac06

Branch: refs/heads/develop
Commit: eeb5ac06adb8ba519ec376620ad485d5fc86550d
Parents: 4cd9266
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Oct 17 13:39:31 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 | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eeb5ac06/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 d0ea436..5033c42 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_spi.c
+++ b/hw/mcu/stm/stm32f4xx/src/hal_spi.c
@@ -157,7 +157,6 @@ spim_irq_handler(struct stm32f4_hal_spi *spi)
     HAL_SPI_IRQHandler(&spi->handle);
 
     if (spi->handle.TxXferCount == 0 && spi->handle.RxXferCount == 0) {
-        spi->handle.Instance->CR1 &= ~(SPI_CR1_SSI | SPI_CR1_SPE);
         if (spi->txrx_cb_func) {
             spi->txrx_cb_func(spi->txrx_cb_arg, spi->handle.TxXferSize);
         }
@@ -202,11 +201,15 @@ spi_ss_isr(void *arg)
     int ss;
     int len;
     int rc;
+    uint16_t reg;
 
     spi_stat.ss_irq++;
     ss = hal_gpio_read(spi->cfg->ss_pin);
     if (ss == 0 && !spi->selected) {
-        spi->handle.Instance->CR1 |= (SPI_CR1_SSI | SPI_CR1_SPE);
+        reg = spi->handle.Instance->CR1;
+        reg |= SPI_CR1_SPE;
+        reg &= ~SPI_CR1_SSI;
+        spi->handle.Instance->CR1 = reg;
         if (spi->tx_in_prog) {
             rc = HAL_SPI_TransmitReceive_IT(&spi->handle,
               spi->handle.pTxBuffPtr, spi->handle.pRxBuffPtr,
@@ -218,7 +221,10 @@ spi_ss_isr(void *arg)
         spi->selected = 1;
     }
     if (ss == 1 && spi->selected) {
-        spi->handle.Instance->CR1 &= ~(SPI_CR1_SSI | SPI_CR1_SPE);
+        reg = spi->handle.Instance->CR1;
+        reg &= ~SPI_CR1_SPE;
+        reg |= SPI_CR1_SSI;
+        spi->handle.Instance->CR1 = reg;
         len = spi->handle.RxXferSize - spi->handle.RxXferCount;
         if (spi->tx_in_prog && len) {
             spi->tx_in_prog = 0;
@@ -448,9 +454,6 @@ hal_spi_disable(int spi_num)
     rc = 0;
     STM32F4_HAL_SPI_RESOLVE(spi_num, spi);
 
-    if (!spi->slave) {
-        spi->handle.Instance->CR1 &= ~SPI_CR1_SSI;
-    }
     /* XXX power down */
 err:
     return rc;
@@ -476,7 +479,7 @@ hal_spi_config(int spi_num, struct hal_spi_settings *settings)
     cfg = spi->cfg;
 
     if (!spi->slave) {
-        spi->handle.Init.NSS = SPI_NSS_SOFT;
+        spi->handle.Init.NSS = SPI_NSS_HARD_OUTPUT;
         spi->handle.Init.Mode = SPI_MODE_MASTER;
     } else {
         spi->handle.Init.NSS = SPI_NSS_SOFT;
@@ -627,14 +630,11 @@ hal_spi_config(int spi_num, struct hal_spi_settings *settings)
     if (rc != 0) {
         goto err;
     }
-    if (!spi->slave) {
+    if (spi->slave) {
         spi->handle.Instance->CR1 &= ~SPI_CR1_SSI;
-    } else {
         rc = hal_gpio_irq_init(cfg->ss_pin, spi_ss_isr, spi, GPIO_TRIG_BOTH,
           GPIO_PULL_UP);
-        if (hal_gpio_read(cfg->ss_pin) == 0) {
-            spi_ss_isr(spi);
-        }
+        spi_ss_isr(spi);
     }
     __HAL_ENABLE_INTERRUPTS(sr);
     return (0);
@@ -655,7 +655,6 @@ hal_spi_txrx_noblock(int spi_num, void *txbuf, void *rxbuf, int len)
     __HAL_DISABLE_INTERRUPTS(sr);
     rc = -1;
     if (!spi->slave) {
-        spi->handle.Instance->CR1 |= (SPI_CR1_SSI | SPI_CR1_SPE);
         rc = HAL_SPI_TransmitReceive_IT(&spi->handle, txbuf, rxbuf, len);
     } else {
         spi->tx_in_prog = 1;
@@ -745,11 +744,9 @@ uint16_t hal_spi_tx_val(int spi_num, uint16_t val)
         len = sizeof(uint16_t);
     }
     __HAL_DISABLE_INTERRUPTS(sr);
-    spi->handle.Instance->CR1 |= (SPI_CR1_SSI | SPI_CR1_SPE);
     rc = HAL_SPI_TransmitReceive(&spi->handle,(uint8_t *)&val,
                                  (uint8_t *)&retval, len,
                                  STM32F4_HAL_SPI_TIMEOUT);
-    spi->handle.Instance->CR1 &= ~(SPI_CR1_SSI | SPI_CR1_SPE);
     __HAL_ENABLE_INTERRUPTS(sr);
     if (rc != HAL_OK) {
         retval = 0xFFFF;
@@ -798,11 +795,10 @@ hal_spi_txrx(int spi_num, void *txbuf, void *rxbuf, int len)
         goto err;
     }
     __HAL_DISABLE_INTERRUPTS(sr);
-    spi->handle.Instance->CR1 |= (SPI_CR1_SSI | SPI_CR1_SPE);
+    __HAL_SPI_ENABLE(&spi->handle);
     rc = HAL_SPI_TransmitReceive(&spi->handle, (uint8_t *)txbuf,
                                  (uint8_t *)rxbuf, len,
                                  STM32F4_HAL_SPI_TIMEOUT);
-    spi->handle.Instance->CR1 &= ~(SPI_CR1_SSI | SPI_CR1_SPE);
     __HAL_ENABLE_INTERRUPTS(sr);
     if (rc != HAL_OK) {
         rc = -1;
@@ -828,7 +824,7 @@ hal_spi_abort(int spi_num)
     __HAL_DISABLE_INTERRUPTS(sr);
     spi->handle.State = HAL_SPI_STATE_READY;
     __HAL_SPI_DISABLE_IT(&spi->handle, SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR);
-    spi->handle.Instance->CR1 &= ~(SPI_CR1_SSI | SPI_CR1_SPE);
+    spi->handle.Instance->CR1 &= ~SPI_CR1_SPE;
     __HAL_ENABLE_INTERRUPTS(sr);
 err:
     return rc;


[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.

Posted by ma...@apache.org.
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,


[2/5] incubator-mynewt-core git commit: stm32f4 SDK; when transmitting as slave, write first byte to DR right away, without waiting for TXE.

Posted by ma...@apache.org.
stm32f4 SDK; when transmitting as slave, write first byte to DR
right away, without waiting for TXE.


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/fb862311
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/fb862311
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/fb862311

Branch: refs/heads/develop
Commit: fb8623112f12b48fcb7cddb91118a6bc734f19bd
Parents: 4b468ce
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Oct 17 23:08:48 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Oct 17 23:15:07 2016 -0700

----------------------------------------------------------------------
 .../ext/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c   | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fb862311/hw/mcu/stm/stm32f4xx/src/ext/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/src/ext/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c b/hw/mcu/stm/stm32f4xx/src/ext/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c
index 5d1a139..84f9597 100644
--- a/hw/mcu/stm/stm32f4xx/src/ext/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c
+++ b/hw/mcu/stm/stm32f4xx/src/ext/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c
@@ -1100,6 +1100,9 @@ HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, u
     __HAL_SPI_ENABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_ERR));
   }
 
+  if ((hspi->Instance->CR1 & SPI_CR1_MSTR) == 0) {
+      hspi->TxISR(hspi);
+  }
   /* Check if the SPI is already enabled */
   if((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE)
   {
@@ -1277,6 +1280,9 @@ HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT(SPI_HandleTypeDef *hspi, uint8_t *p
   /* Enable TXE, RXNE and ERR interrupt */
   __HAL_SPI_ENABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR));
 
+  if ((hspi->Instance->CR1 & SPI_CR1_MSTR) == 0) {
+      hspi->TxISR(hspi);
+  }
   /* Check if the SPI is already enabled */
   if((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE)
   {