You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/08/19 15:53:26 UTC
incubator-mynewt-core git commit: add complete definitions of hal_spi
(GPIO config). Switch I2C to stm32f4_ naming vs stm32_ naming.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/sterly_refactor a213939a8 -> 5768f08b9
add complete definitions of hal_spi (GPIO config). Switch I2C to stm32f4_ naming vs stm32_ naming.
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/5768f08b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5768f08b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5768f08b
Branch: refs/heads/sterly_refactor
Commit: 5768f08b95617c62473b4d6fba95243ba31e8312
Parents: a213939
Author: Sterling Hughes <st...@apache.org>
Authored: Fri Aug 19 08:53:12 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Fri Aug 19 08:53:12 2016 -0700
----------------------------------------------------------------------
.../include/mcu/stm32f4xx_mynewt_hal.h | 10 ++++-
hw/mcu/stm/stm32f4xx/src/hal_i2c.c | 26 +++++------
hw/mcu/stm/stm32f4xx/src/hal_spi.c | 45 +++++++++++++++++++-
3 files changed, 65 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5768f08b/hw/mcu/stm/stm32f4xx/include/mcu/stm32f4xx_mynewt_hal.h
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/include/mcu/stm32f4xx_mynewt_hal.h b/hw/mcu/stm/stm32f4xx/include/mcu/stm32f4xx_mynewt_hal.h
index 244d4f2..33e82c6 100644
--- a/hw/mcu/stm/stm32f4xx/include/mcu/stm32f4xx_mynewt_hal.h
+++ b/hw/mcu/stm/stm32f4xx/include/mcu/stm32f4xx_mynewt_hal.h
@@ -24,6 +24,7 @@
#include "stm32f4xx_hal_dma.h"
#include "stm32f4xx_hal_gpio.h"
#include "stm32f4xx_hal_i2c.h"
+#include "stm32f4xx_hal_spi.h"
/* Helper functions to enable/disable interrupts. */
#define __HAL_DISABLE_INTERRUPTS(x) \
@@ -42,10 +43,17 @@
int hal_gpio_init_stm(int pin, GPIO_InitTypeDef *cfg);
-struct stm32_hal_i2c_cfg {
+struct stm32f4_hal_i2c_cfg {
int sda_pin;
int scl_pin;
I2C_InitTypeDef *i2c_settings;
};
+struct stm32f4_hal_spi_cfg {
+ int sck_pin;
+ int miso_pin;
+ int mosi_pin;
+ SPI_InitTypeDef *spi_settings;
+};
+
#endif /* __MCU_STM32F4_MYNEWT_HAL_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5768f08b/hw/mcu/stm/stm32f4xx/src/hal_i2c.c
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_i2c.c b/hw/mcu/stm/stm32f4xx/src/hal_i2c.c
index dd257bf..3e65c70 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_i2c.c
+++ b/hw/mcu/stm/stm32f4xx/src/hal_i2c.c
@@ -34,31 +34,31 @@
#define STM32F4_HAL_I2C_TIMEOUT (1000)
-struct stm32_hal_i2c {
+struct stm32f4_hal_i2c {
I2C_HandleTypeDef handle;
};
#define STM32_HAL_I2C_MAX (3)
#ifdef I2C1
-struct stm32_hal_i2c hal_i2c1;
+struct stm32f4_hal_i2c hal_i2c1;
#else
#define __HAL_RCC_I2C1_CLK_ENABLE()
#endif
#ifdef I2C2
-struct stm32_hal_i2c hal_i2c2;
+struct stm32f4_hal_i2c hal_i2c2;
#else
#define __HAL_RCC_I2C2_CLK_ENABLE()
#endif
#ifdef I2C3
-struct stm32_hal_i2c hal_i2c3;
+struct stm32f4_hal_i2c hal_i2c3;
#else
#define __HAL_RCC_I2C3_CLK_ENABLE()
#endif
-struct stm32_hal_i2c *stm32_hal_i2cs[STM32_HAL_I2C_MAX] = {
+struct stm32f4_hal_i2c *stm32f4_hal_i2cs[STM32_HAL_I2C_MAX] = {
#ifdef I2C1
&hal_i2c1,
#else
@@ -81,7 +81,7 @@ struct stm32_hal_i2c *stm32_hal_i2cs[STM32_HAL_I2C_MAX] = {
rc = EINVAL; \
goto err; \
} \
- (__v) = stm32_hal_i2cs[(__n)]; \
+ (__v) = stm32f4_hal_i2cs[(__n)]; \
if ((__v) == NULL) { \
rc = EINVAL; \
goto err; \
@@ -91,13 +91,13 @@ int
hal_i2c_init(uint8_t i2c_num, void *usercfg)
{
GPIO_InitTypeDef pcf;
- struct stm32_hal_i2c *i2c;
- struct stm32_hal_i2c_cfg *cfg;
+ struct stm32f4_hal_i2c *i2c;
+ struct stm32f4_hal_i2c_cfg *cfg;
int rc;
STM32_HAL_I2C_RESOLVE(i2c_num, i2c);
- cfg = (struct stm32_hal_i2c_cfg *) usercfg;
+ cfg = (struct stm32f4_hal_i2c_cfg *) usercfg;
assert(cfg != NULL);
pcf.Mode = GPIO_MODE_OUTPUT_PP;
@@ -151,7 +151,7 @@ err:
int
hal_i2c_master_write(uint8_t i2c_num, struct hal_i2c_master_data *pdata)
{
- struct stm32_hal_i2c *i2c;
+ struct stm32f4_hal_i2c *i2c;
int rc;
STM32_HAL_I2C_RESOLVE(i2c_num, i2c);
@@ -170,7 +170,7 @@ err:
int
hal_i2c_master_read(uint8_t i2c_num, struct hal_i2c_master_data *pdata)
{
- struct stm32_hal_i2c *i2c;
+ struct stm32f4_hal_i2c *i2c;
int rc;
STM32_HAL_I2C_RESOLVE(i2c_num, i2c);
@@ -195,7 +195,7 @@ hal_i2c_master_begin(uint8_t i2c_num)
int
hal_i2c_master_end(uint8_t i2c_num)
{
- struct stm32_hal_i2c *i2c;
+ struct stm32f4_hal_i2c *i2c;
int rc;
STM32_HAL_I2C_RESOLVE(i2c_num, i2c);
@@ -210,7 +210,7 @@ err:
int
hal_i2c_master_probe(uint8_t i2c_num, uint8_t address)
{
- struct stm32_hal_i2c *i2c;
+ struct stm32f4_hal_i2c *i2c;
int rc;
STM32_HAL_I2C_RESOLVE(i2c_num, i2c);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5768f08b/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 017ef26..314a24a 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_spi.c
+++ b/hw/mcu/stm/stm32f4xx/src/hal_spi.c
@@ -29,6 +29,7 @@
#include "stm32f4xx_hal_dma.h"
#include "stm32f4xx_hal_spi.h"
#include "stm32f4xx_hal_gpio.h"
+#include "stm32f4xx_hal_gpio_ex.h"
#include "stm32f4xx_hal_rcc.h"
#include "mcu/stm32f4xx_mynewt_hal.h"
@@ -117,10 +118,12 @@ struct stm32f4_hal_spi *stm32f4_hal_spis[STM32F4_HAL_SPI_MAX] = {
}
int
-hal_spi_init(uint8_t spi_num, void *cfg)
+hal_spi_init(uint8_t spi_num, void *usercfg)
{
struct stm32f4_hal_spi *spi;
+ struct stm32f4_hal_spi_cfg *cfg;
SPI_InitTypeDef *init;
+ GPIO_InitTypeDef pcf;
int rc;
/* Allow user to specify default init settings for the SPI.
@@ -129,35 +132,68 @@ hal_spi_init(uint8_t spi_num, void *cfg)
*/
STM32F4_HAL_SPI_RESOLVE(spi_num, spi);
- init = (SPI_InitTypeDef *) cfg;
+ cfg = (struct stm32f4_hal_spi_cfg *) usercfg;
+
+ init = (SPI_InitTypeDef *) cfg->spi_settings;
if (init != NULL) {
memcpy(&spi->handle.Init, init, sizeof(SPI_InitTypeDef));
} else {
/* Provide default initialization of SPI */
}
+ pcf.Mode = GPIO_MODE_AF_PP;
+ pcf.Pull = GPIO_NOPULL;
+ pcf.Speed = GPIO_SPEED_FREQ_HIGH;
+
/* Enable the clocks for this SPI */
switch (spi_num) {
case 0:
__HAL_RCC_SPI1_CLK_ENABLE();
+ pcf.Alternate = GPIO_AF5_SPI1;
break;
case 1:
__HAL_RCC_SPI2_CLK_ENABLE();
+ pcf.Alternate = GPIO_AF5_SPI2;
break;
case 2:
__HAL_RCC_SPI3_CLK_ENABLE();
+ pcf.Alternate = GPIO_AF6_SPI3;
break;
case 3:
__HAL_RCC_SPI4_CLK_ENABLE();
+#ifdef SPI4
+ pcf.Alternate = GPIO_AF5_SPI4;
+#endif
break;
case 4:
__HAL_RCC_SPI5_CLK_ENABLE();
+#ifdef SPI5
+ pcf.Alternate = GPIO_AF5_SPI5;
+#endif
break;
case 5:
__HAL_RCC_SPI6_CLK_ENABLE();
+#ifdef SPI6
+ pcf.Alternate = GPIO_AF5_SPI6;
+#endif
break;
}
+ rc = hal_gpio_init_stm(cfg->sck_pin, &pcf);
+ if (rc != 0) {
+ goto err;
+ }
+
+ rc = hal_gpio_init_stm(cfg->miso_pin, &pcf);
+ if (rc != 0) {
+ goto err;
+ }
+
+ rc = hal_gpio_init_stm(cfg->mosi_pin, &pcf);
+ if (rc != 0) {
+ goto err;
+ }
+
return (0);
err:
return (rc);
@@ -266,11 +302,16 @@ hal_spi_config(uint8_t spi_num, struct hal_spi_settings *settings)
init->BaudRatePrescaler = prescaler;
+ /* Disable, Init, Enable */
+ __HAL_SPI_DISABLE(&spi->handle);
+
rc = HAL_SPI_Init(&spi->handle);
if (rc != 0) {
goto err;
}
+ __HAL_SPI_ENABLE(&spi->handle);
+
return (0);
err:
return (rc);