summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authoryulei <yuleiz@gmail.com>2019-12-13 09:20:04 +0800
committerFlorian Didron <fdidron@users.noreply.github.com>2020-01-09 08:57:11 +0900
commit5f9e60bd95351062ad2c211a4f9ca40a7e936595 (patch)
tree68991fe9d70fb464b6a11290b7f875251ecdf4c7 /drivers
parent20f465bfb677b2ec5438ece6914bc3963e802bff (diff)
fixed I2C driver support for stm32f4 (#7526)
* correct i2c driver for stm32f4 * update pin mode definitions * update macro definition
Diffstat (limited to 'drivers')
-rw-r--r--drivers/arm/i2c_master.c3
-rw-r--r--drivers/arm/i2c_master.h24
2 files changed, 16 insertions, 11 deletions
diff --git a/drivers/arm/i2c_master.c b/drivers/arm/i2c_master.c
index 18068d3a6d..5a03b9f306 100644
--- a/drivers/arm/i2c_master.c
+++ b/drivers/arm/i2c_master.c
@@ -60,8 +60,7 @@ __attribute__((weak)) void i2c_init(void) {
palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_INPUT);
chThdSleepMilliseconds(10);
-
-#ifdef USE_I2CV1
+#if defined(USE_GPIOV1)
palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
#else
diff --git a/drivers/arm/i2c_master.h b/drivers/arm/i2c_master.h
index a8ed66403a..9bb5f13c01 100644
--- a/drivers/arm/i2c_master.h
+++ b/drivers/arm/i2c_master.h
@@ -27,7 +27,7 @@
#include "ch.h"
#include <hal.h>
-#if defined(STM32F1XX) || defined(STM32F1xx) || defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32L0xx) || defined(STM32L1xx)
+#if defined(STM32F1XX) || defined(STM32F1xx) || defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32F4XX) || defined(STM32L0xx) || defined(STM32L1xx)
# define USE_I2CV1
#endif
@@ -51,6 +51,20 @@
# define I2C1_SDA 7
#endif
+#if defined(STM32F1XX) || defined(STM32F1xx)
+# define USE_GPIOV1
+#endif
+
+#ifndef USE_GPIOV1
+// The default PAL alternate modes are used to signal that the pins are used for I2C
+# ifndef I2C1_SCL_PAL_MODE
+# define I2C1_SCL_PAL_MODE 4
+# endif
+# ifndef I2C1_SDA_PAL_MODE
+# define I2C1_SDA_PAL_MODE 4
+# endif
+#endif
+
#ifdef USE_I2CV1
# ifndef I2C1_OPMODE
# define I2C1_OPMODE OPMODE_I2C
@@ -62,14 +76,6 @@
# define I2C1_DUTY_CYCLE STD_DUTY_CYCLE /* FAST_DUTY_CYCLE_2 */
# endif
#else
-// The default PAL alternate modes are used to signal that the pins are used for I2C
-# ifndef I2C1_SCL_PAL_MODE
-# define I2C1_SCL_PAL_MODE 4
-# endif
-# ifndef I2C1_SDA_PAL_MODE
-# define I2C1_SDA_PAL_MODE 4
-# endif
-
// The default timing values below configures the I2C clock to 400khz assuming a 72Mhz clock
// For more info : https://www.st.com/en/embedded-software/stsw-stm32126.html
# ifndef I2C1_TIMINGR_PRESC