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);

Reply via email to