This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new cb2242fcb7a boards/arm: register I2C character drivers in the common
STM32 board init
cb2242fcb7a is described below
commit cb2242fcb7a821c8b32ef199217e21615748a724
Author: raiden00pl <[email protected]>
AuthorDate: Wed Oct 14 14:12:23 2026 +0200
boards/arm: register I2C character drivers in the common STM32 board init
Register /dev/i2cN for every enabled STM32 I2C instance in
stm32_common_initialize() when CONFIG_I2C_DRIVER is set and drop the
per-board copies of this code on the Nucleo boards.
Assisted-by: Claude Code
Signed-off-by: raiden00pl <[email protected]>
---
.../guides/chip-specific/stm32_nucleo.rst | 2 +
boards/arm/common/stm32/src/board_common.c | 78 +++++++++++++++++++
.../arm/stm32f0/nucleo-f072rb/src/stm32_bringup.c | 30 --------
boards/arm/stm32f4/nucleo-f429zi/src/stm32_boot.c | 44 -----------
.../arm/stm32f7/nucleo-f722ze/src/stm32_bringup.c | 23 +-----
.../arm/stm32f7/nucleo-f746zg/src/stm32_bringup.c | 23 +-----
.../arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c | 23 +-----
.../arm/stm32g0/nucleo-g070rb/src/stm32_bringup.c | 61 ---------------
.../arm/stm32h7/nucleo-h723zg/src/stm32_bringup.c | 66 ----------------
.../arm/stm32h7/nucleo-h743zi/src/stm32_bringup.c | 62 ---------------
boards/arm/stm32l1/nucleo-l152re/src/stm32_boot.c | 48 ------------
.../arm/stm32l4/nucleo-l432kc/src/stm32_bringup.c | 52 -------------
.../arm/stm32l4/nucleo-l452re/src/stm32_bringup.c | 30 --------
.../arm/stm32l4/nucleo-l476rg/src/stm32_bringup.c | 59 --------------
.../arm/stm32l4/nucleo-l496zg/src/stm32_bringup.c | 51 -------------
.../stm32u5/nucleo-u5a5zj-q/src/stm32_bringup.c | 89 ++++++----------------
16 files changed, 117 insertions(+), 624 deletions(-)
diff --git a/Documentation/guides/chip-specific/stm32_nucleo.rst
b/Documentation/guides/chip-specific/stm32_nucleo.rst
index 5d895711bac..d6fcf439c6e 100644
--- a/Documentation/guides/chip-specific/stm32_nucleo.rst
+++ b/Documentation/guides/chip-specific/stm32_nucleo.rst
@@ -43,6 +43,8 @@ CAN ``CONFIG_STM32_CAN_CHARDRIVER`` ``/dev/can0``,
``/dev/can1``,
``CONFIG_STM32_FDCAN_CHARDRIVER`` ... in instance order
SocketCAN ``CONFIG_STM32_CAN_SOCKET`` interfaces for all enabled
``CONFIG_STM32_FDCAN_SOCKET`` instances
+I2C ``CONFIG_I2C_DRIVER`` ``/dev/i2cN`` for every enabled
+ ``CONFIG_STM32_I2CN``
========= ================================== ================================
The file systems are not mounted when ``CONFIG_DISABLE_MOUNTPOINT`` is
diff --git a/boards/arm/common/stm32/src/board_common.c
b/boards/arm/common/stm32/src/board_common.c
index 660513ec28b..5073460b892 100644
--- a/boards/arm/common/stm32/src/board_common.c
+++ b/boards/arm/common/stm32/src/board_common.c
@@ -46,10 +46,30 @@
# define HAVE_CANSOCK_SETUP
#endif
+#if defined(CONFIG_I2C_DRIVER) && \
+ (defined(CONFIG_STM32_I2C1) || defined(CONFIG_STM32_I2C2) || \
+ defined(CONFIG_STM32_I2C3) || defined(CONFIG_STM32_I2C4) || \
+ defined(CONFIG_STM32_I2C5) || defined(CONFIG_STM32_I2C6))
+# define HAVE_I2C_DRIVER
+#endif
+
#if defined(CONFIG_STM32_IWDG) || defined(CONFIG_STM32_WWDG)
# include "stm32_wdg.h"
#endif
+/* Per-family I2C headers until all STM32 I2C drivers are unified */
+
+#ifdef HAVE_I2C_DRIVER
+# include <nuttx/i2c/i2c_master.h>
+# if defined(CONFIG_ARCH_CHIP_STM32L4)
+# include "stm32l4_i2c.h"
+# elif defined(CONFIG_ARCH_CHIP_STM32WB)
+# include "stm32wb_i2c.h"
+# else
+# include "stm32_i2c.h"
+# endif
+#endif
+
#ifdef HAVE_CAN_SETUP
# include "stm32_can_setup.h"
#endif
@@ -78,6 +98,41 @@
# define PROCFS_MOUNTPOINT "/proc"
#endif
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_i2c_register
+ *
+ * Description:
+ * Register the I2C character driver /dev/i2c[bus] for one I2C bus.
+ *
+ ****************************************************************************/
+
+#ifdef HAVE_I2C_DRIVER
+static void stm32_i2c_register(int bus)
+{
+ struct i2c_master_s *i2c;
+ int ret;
+
+ i2c = stm32_i2cbus_initialize(bus);
+ if (i2c == NULL)
+ {
+ syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus);
+ return;
+ }
+
+ ret = i2c_register(i2c, bus);
+ if (ret < 0)
+ {
+ syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
+ bus, ret);
+ stm32_i2cbus_uninitialize(i2c);
+ }
+}
+#endif
+
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -128,6 +183,29 @@ int stm32_common_initialize(void)
stm32_wwdginitialize("/dev/watchdog1");
#endif
+#ifdef HAVE_I2C_DRIVER
+ /* Register the I2C character drivers */
+
+# ifdef CONFIG_STM32_I2C1
+ stm32_i2c_register(1);
+# endif
+# ifdef CONFIG_STM32_I2C2
+ stm32_i2c_register(2);
+# endif
+# ifdef CONFIG_STM32_I2C3
+ stm32_i2c_register(3);
+# endif
+# ifdef CONFIG_STM32_I2C4
+ stm32_i2c_register(4);
+# endif
+# ifdef CONFIG_STM32_I2C5
+ stm32_i2c_register(5);
+# endif
+# ifdef CONFIG_STM32_I2C6
+ stm32_i2c_register(6);
+# endif
+#endif
+
#ifdef HAVE_CAN_SETUP
/* Register the CAN character drivers */
diff --git a/boards/arm/stm32f0/nucleo-f072rb/src/stm32_bringup.c
b/boards/arm/stm32f0/nucleo-f072rb/src/stm32_bringup.c
index 09e6d99ed58..b92eb1653ae 100644
--- a/boards/arm/stm32f0/nucleo-f072rb/src/stm32_bringup.c
+++ b/boards/arm/stm32f0/nucleo-f072rb/src/stm32_bringup.c
@@ -30,10 +30,8 @@
#include <nuttx/debug.h>
#include <nuttx/fs/fs.h>
-#include <nuttx/i2c/i2c_master.h>
#include <nuttx/usb/cdcacm.h>
-#include "stm32_i2c.h"
#include "nucleo-f072rb.h"
#include "board_common.h"
@@ -41,11 +39,6 @@
* Pre-processor Definitions
****************************************************************************/
-#undef HAVE_I2C_DRIVER
-#if defined(CONFIG_STM32_I2C1) && defined(CONFIG_I2C_DRIVER)
-# define HAVE_I2C_DRIVER 1
-#endif
-
#if defined(CONFIG_CDCACM) && !defined(CONFIG_CDCACM_COMPOSITE)
# define HAVE_CDCACM 1
#endif
@@ -67,9 +60,6 @@
int stm32_bringup(void)
{
-#ifdef HAVE_I2C_DRIVER
- struct i2c_master_s *i2c;
-#endif
int ret;
/* Initialize the board features common to all STM32 boards */
@@ -81,26 +71,6 @@ int stm32_bringup(void)
ret);
}
-#ifdef HAVE_I2C_DRIVER
- /* Get the I2C lower half instance */
-
- i2c = stm32_i2cbus_initialize(1);
- if (i2c == NULL)
- {
- i2cerr("ERROR: Initialize I2C1: %d\n", ret);
- }
- else
- {
- /* Register the I2C character driver */
-
- ret = i2c_register(i2c, 1);
- if (ret < 0)
- {
- i2cerr("ERROR: Failed to register I2C1 device: %d\n", ret);
- }
- }
-#endif
-
#ifdef HAVE_CDCACM
ret = cdcacm_initialize(0, NULL);
if (ret < 0)
diff --git a/boards/arm/stm32f4/nucleo-f429zi/src/stm32_boot.c
b/boards/arm/stm32f4/nucleo-f429zi/src/stm32_boot.c
index fcfbe649548..d948dd81b20 100644
--- a/boards/arm/stm32f4/nucleo-f429zi/src/stm32_boot.c
+++ b/boards/arm/stm32f4/nucleo-f429zi/src/stm32_boot.c
@@ -47,48 +47,8 @@
#include "stm32_amg88xx.h"
#endif
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
-# include "stm32_i2c.h"
-#endif
-
#include "board_common.h"
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: stm32_i2c_register
- *
- * Description:
- * Register one I2C drivers for the I2C tool.
- *
- ****************************************************************************/
-
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
-static void stm32_i2c_register(int bus)
-{
- struct i2c_master_s *i2c;
- int ret;
-
- i2c = stm32_i2cbus_initialize(bus);
- if (i2c == NULL)
- {
- syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus);
- }
- else
- {
- ret = i2c_register(i2c, bus);
- if (ret < 0)
- {
- syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
- bus, ret);
- stm32_i2cbus_uninitialize(i2c);
- }
- }
-}
-#endif
-
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -239,10 +199,6 @@ void board_late_initialize(void)
}
#endif
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
- stm32_i2c_register(1);
-#endif
-
#ifdef CONFIG_SENSORS_AMG88XX
board_amg88xx_initialize(1);
#endif
diff --git a/boards/arm/stm32f7/nucleo-f722ze/src/stm32_bringup.c
b/boards/arm/stm32f7/nucleo-f722ze/src/stm32_bringup.c
index 11542dbccea..8cf5bfb6f09 100644
--- a/boards/arm/stm32f7/nucleo-f722ze/src/stm32_bringup.c
+++ b/boards/arm/stm32f7/nucleo-f722ze/src/stm32_bringup.c
@@ -72,12 +72,9 @@
int stm32_bringup(void)
{
int ret;
-#ifdef CONFIG_I2C
- int i2c_bus;
- struct i2c_master_s *i2c;
#ifdef CONFIG_MPU60X0_I2C
+ struct i2c_master_s *i2c;
struct mpu_config_s *mpu_config;
-#endif
#endif
/* Initialize the board features common to all STM32 boards */
@@ -230,25 +227,14 @@ int stm32_bringup(void)
#endif
-#if defined(CONFIG_I2C) && defined(CONFIG_STM32_I2C1)
- i2c_bus = 1;
- i2c = stm32_i2cbus_initialize(i2c_bus);
+#ifdef CONFIG_MPU60X0_I2C
+ i2c = stm32_i2cbus_initialize(1);
if (i2c == NULL)
{
- syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", i2c_bus);
+ syslog(LOG_ERR, "ERROR: Failed to get I2C1 interface\n");
}
else
{
-#if defined(CONFIG_SYSTEM_I2CTOOL)
- ret = i2c_register(i2c, i2c_bus);
- if (ret < 0)
- {
- syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
- i2c_bus, ret);
- }
-#endif
-
-#ifdef CONFIG_MPU60X0_I2C
mpu_config = kmm_zalloc(sizeof(struct mpu_config_s));
if (mpu_config == NULL)
{
@@ -260,7 +246,6 @@ int stm32_bringup(void)
mpu_config->addr = 0x68;
mpu60x0_register("/dev/imu0", mpu_config);
}
-#endif
}
#endif
diff --git a/boards/arm/stm32f7/nucleo-f746zg/src/stm32_bringup.c
b/boards/arm/stm32f7/nucleo-f746zg/src/stm32_bringup.c
index 1f98b475326..947096cae93 100644
--- a/boards/arm/stm32f7/nucleo-f746zg/src/stm32_bringup.c
+++ b/boards/arm/stm32f7/nucleo-f746zg/src/stm32_bringup.c
@@ -76,12 +76,9 @@
int stm32_bringup(void)
{
int ret;
-#ifdef CONFIG_I2C
- int i2c_bus;
- struct i2c_master_s *i2c;
#ifdef CONFIG_MPU60X0_I2C
+ struct i2c_master_s *i2c;
struct mpu_config_s *mpu_config;
-#endif
#endif
/* Initialize the board features common to all STM32 boards */
@@ -234,25 +231,14 @@ int stm32_bringup(void)
#endif
-#if defined(CONFIG_I2C) && defined(CONFIG_STM32_I2C1)
- i2c_bus = 1;
- i2c = stm32_i2cbus_initialize(i2c_bus);
+#ifdef CONFIG_MPU60X0_I2C
+ i2c = stm32_i2cbus_initialize(1);
if (i2c == NULL)
{
- syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", i2c_bus);
+ syslog(LOG_ERR, "ERROR: Failed to get I2C1 interface\n");
}
else
{
-#if defined(CONFIG_SYSTEM_I2CTOOL)
- ret = i2c_register(i2c, i2c_bus);
- if (ret < 0)
- {
- syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
- i2c_bus, ret);
- }
-#endif
-
-#ifdef CONFIG_MPU60X0_I2C
mpu_config = kmm_zalloc(sizeof(struct mpu_config_s));
if (mpu_config == NULL)
{
@@ -264,7 +250,6 @@ int stm32_bringup(void)
mpu_config->addr = 0x68;
mpu60x0_register("/dev/imu0", mpu_config);
}
-#endif
}
#endif
diff --git a/boards/arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c
b/boards/arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c
index 32a4a90558c..22791370366 100644
--- a/boards/arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c
+++ b/boards/arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c
@@ -96,13 +96,10 @@ int stm32_bringup(void)
}
#endif
-#ifdef CONFIG_I2C
- int i2c_bus;
- struct i2c_master_s *i2c;
#ifdef CONFIG_MPU60X0_I2C
+ struct i2c_master_s *i2c;
struct mpu_config_s *mpu_config;
#endif
-#endif
#ifdef CONFIG_STM32_ROMFS
/* Mount the romfs partition */
@@ -245,25 +242,14 @@ int stm32_bringup(void)
#endif
-#if defined(CONFIG_I2C) && defined(CONFIG_STM32_I2C1)
- i2c_bus = 1;
- i2c = stm32_i2cbus_initialize(i2c_bus);
+#ifdef CONFIG_MPU60X0_I2C
+ i2c = stm32_i2cbus_initialize(1);
if (i2c == NULL)
{
- syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", i2c_bus);
+ syslog(LOG_ERR, "ERROR: Failed to get I2C1 interface\n");
}
else
{
-#if defined(CONFIG_SYSTEM_I2CTOOL)
- ret = i2c_register(i2c, i2c_bus);
- if (ret < 0)
- {
- syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
- i2c_bus, ret);
- }
-#endif
-
-#ifdef CONFIG_MPU60X0_I2C
mpu_config = kmm_zalloc(sizeof(struct mpu_config_s));
if (mpu_config == NULL)
{
@@ -275,7 +261,6 @@ int stm32_bringup(void)
mpu_config->addr = 0x68;
mpu60x0_register("/dev/imu0", mpu_config);
}
-#endif
}
#endif
diff --git a/boards/arm/stm32g0/nucleo-g070rb/src/stm32_bringup.c
b/boards/arm/stm32g0/nucleo-g070rb/src/stm32_bringup.c
index a7b6c885f33..808197bac5b 100644
--- a/boards/arm/stm32g0/nucleo-g070rb/src/stm32_bringup.c
+++ b/boards/arm/stm32g0/nucleo-g070rb/src/stm32_bringup.c
@@ -34,7 +34,6 @@
#include <nuttx/leds/userled.h>
#include "nucleo-g070rb.h"
-#include "stm32_i2c.h"
#include "board_common.h"
/****************************************************************************
@@ -55,62 +54,6 @@
# define HAVE_DAC2 1
#endif
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: stm32_i2c_register
- *
- * Description:
- * Register one I2C drivers for the I2C tool.
- *
- ****************************************************************************/
-
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
-static void stm32_i2c_register(int bus)
-{
- struct i2c_master_s *i2c;
- int ret;
-
- i2c = stm32_i2cbus_initialize(bus);
- if (i2c == NULL)
- {
- syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus);
- }
- else
- {
- ret = i2c_register(i2c, bus);
- if (ret < 0)
- {
- syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
- bus, ret);
- stm32_i2cbus_uninitialize(i2c);
- }
- }
-}
-#endif
-
-/****************************************************************************
- * Name: stm32_i2ctool
- *
- * Description:
- * Register I2C drivers for the I2C tool.
- *
- ****************************************************************************/
-
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
-static void stm32_i2ctool(void)
-{
-#ifdef CONFIG_STM32_I2C1
- stm32_i2c_register(1);
-#endif
-#ifdef CONFIG_STM32_I2C2
- stm32_i2c_register(2);
-#endif
-}
-#endif
-
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -150,10 +93,6 @@ int stm32_bringup(void)
}
#endif
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
- stm32_i2ctool();
-#endif
-
#ifdef CONFIG_INPUT_BUTTONS
/* Register the BUTTON driver */
diff --git a/boards/arm/stm32h7/nucleo-h723zg/src/stm32_bringup.c
b/boards/arm/stm32h7/nucleo-h723zg/src/stm32_bringup.c
index 428304e6cf6..b34e0916cf0 100644
--- a/boards/arm/stm32h7/nucleo-h723zg/src/stm32_bringup.c
+++ b/boards/arm/stm32h7/nucleo-h723zg/src/stm32_bringup.c
@@ -51,68 +51,6 @@
#include "stm32.h"
#include "board_common.h"
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: stm32_i2c_register
- *
- * Description:
- * Register one I2C drivers for the I2C tool.
- *
- ****************************************************************************/
-
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
-static void stm32_i2c_register(int bus)
-{
- struct i2c_master_s *i2c;
- int ret;
-
- i2c = stm32_i2cbus_initialize(bus);
- if (i2c == NULL)
- {
- syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus);
- }
- else
- {
- ret = i2c_register(i2c, bus);
- if (ret < 0)
- {
- syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
- bus, ret);
- stm32_i2cbus_uninitialize(i2c);
- }
- }
-}
-#endif
-
-/****************************************************************************
- * Name: stm32_i2ctool
- *
- * Description:
- * Register I2C drivers for the I2C tool.
- *
- ****************************************************************************/
-
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
-static void stm32_i2ctool(void)
-{
-#ifdef CONFIG_STM32_I2C1
- stm32_i2c_register(1);
-#endif
-#ifdef CONFIG_STM32_I2C2
- stm32_i2c_register(2);
-#endif
-#ifdef CONFIG_STM32_I2C3
- stm32_i2c_register(3);
-#endif
-#ifdef CONFIG_STM32_I2C4
- stm32_i2c_register(4);
-#endif
-}
-#endif
-
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -143,10 +81,6 @@ int stm32_bringup(void)
UNUSED(ret);
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
- stm32_i2ctool();
-#endif
-
#ifdef CONFIG_INPUT_BUTTONS
/* Register the BUTTON driver */
diff --git a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_bringup.c
b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_bringup.c
index 913ab2abe50..1d95309411c 100644
--- a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_bringup.c
+++ b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_bringup.c
@@ -175,64 +175,6 @@ static int stm32_capture_setup(void)
}
#endif
-/****************************************************************************
- * Name: stm32_i2c_register
- *
- * Description:
- * Register one I2C drivers for the I2C tool.
- *
- ****************************************************************************/
-
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
-static void stm32_i2c_register(int bus)
-{
- struct i2c_master_s *i2c;
- int ret;
-
- i2c = stm32_i2cbus_initialize(bus);
- if (i2c == NULL)
- {
- syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus);
- }
- else
- {
- ret = i2c_register(i2c, bus);
- if (ret < 0)
- {
- syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
- bus, ret);
- stm32_i2cbus_uninitialize(i2c);
- }
- }
-}
-#endif
-
-/****************************************************************************
- * Name: stm32_i2ctool
- *
- * Description:
- * Register I2C drivers for the I2C tool.
- *
- ****************************************************************************/
-
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
-static void stm32_i2ctool(void)
-{
-#ifdef CONFIG_STM32_I2C1
- stm32_i2c_register(1);
-#endif
-#ifdef CONFIG_STM32_I2C2
- stm32_i2c_register(2);
-#endif
-#ifdef CONFIG_STM32_I2C3
- stm32_i2c_register(3);
-#endif
-#ifdef CONFIG_STM32_I2C4
- stm32_i2c_register(4);
-#endif
-}
-#endif
-
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -266,10 +208,6 @@ int stm32_bringup(void)
UNUSED(ret);
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
- stm32_i2ctool();
-#endif
-
#ifdef CONFIG_STM32_ROMFS
/* Mount the romfs partition */
diff --git a/boards/arm/stm32l1/nucleo-l152re/src/stm32_boot.c
b/boards/arm/stm32l1/nucleo-l152re/src/stm32_boot.c
index ef9740ea9c4..c6a7930e81d 100644
--- a/boards/arm/stm32l1/nucleo-l152re/src/stm32_boot.c
+++ b/boards/arm/stm32l1/nucleo-l152re/src/stm32_boot.c
@@ -35,8 +35,6 @@
#include <nuttx/leds/userled.h>
#include <arch/board/board.h>
-#include "stm32_i2c.h"
-
#include "nucleo-l152re.h"
#include "board_common.h"
@@ -108,12 +106,6 @@ void stm32_boardinitialize(void)
void board_late_initialize(void)
{
int ret;
-#ifdef CONFIG_STM32_I2C1
- struct i2c_master_s *i2c1;
-#endif
-#ifdef CONFIG_STM32_I2C2
- struct i2c_master_s *i2c2;
-#endif
/* Initialize the board features common to all STM32 boards */
@@ -124,46 +116,6 @@ void board_late_initialize(void)
ret);
}
-#ifdef CONFIG_STM32_I2C1
- /* Get the I2C lower half instance */
-
- i2c1 = stm32_i2cbus_initialize(1);
- if (i2c1 == NULL)
- {
- i2cerr("ERROR: Initialize I2C1: %d\n", ret);
- }
- else
- {
- /* Register the I2C character driver */
-
- ret = i2c_register(i2c1, 1);
- if (ret < 0)
- {
- i2cerr("ERROR: Failed to register I2C1 device: %d\n", ret);
- }
- }
-#endif
-
-#ifdef CONFIG_STM32_I2C2
- /* Get the I2C lower half instance */
-
- i2c2 = stm32_i2cbus_initialize(2);
- if (i2c2 == NULL)
- {
- i2cerr("ERROR: Initialize I2C2: %d\n", ret);
- }
- else
- {
- /* Register the I2C character driver */
-
- ret = i2c_register(i2c2, 2);
- if (ret < 0)
- {
- i2cerr("ERROR: Failed to register I2C2 device: %d\n", ret);
- }
- }
-#endif
-
#ifdef CONFIG_STM32_SPI
stm32_spiinitialize();
#endif
diff --git a/boards/arm/stm32l4/nucleo-l432kc/src/stm32_bringup.c
b/boards/arm/stm32l4/nucleo-l432kc/src/stm32_bringup.c
index dd99dab8afd..a619fd7b13f 100644
--- a/boards/arm/stm32l4/nucleo-l432kc/src/stm32_bringup.c
+++ b/boards/arm/stm32l4/nucleo-l432kc/src/stm32_bringup.c
@@ -42,7 +42,6 @@
#include <stm32.h>
#include <stm32l4_uart.h>
-#include <stm32l4_i2c.h>
#include <arch/board/board.h>
@@ -59,11 +58,6 @@
* Pre-processor Definitions
****************************************************************************/
-#undef HAVE_I2C_DRIVER
-#if (defined(CONFIG_STM32_I2C1) || defined(CONFIG_STM32_I2C3)) &&
defined(CONFIG_I2C_DRIVER)
-# define HAVE_I2C_DRIVER 1
-#endif
-
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -84,12 +78,6 @@ int stm32_bringup(void)
#ifdef HAVE_RTC_DRIVER
struct rtc_lowerhalf_s *rtclower;
#endif
-#ifdef CONFIG_STM32_I2C1
- struct i2c_master_s *i2c1;
-#endif
-#ifdef CONFIG_STM32_I2C3
- struct i2c_master_s *i2c3;
-#endif
#ifdef CONFIG_SENSORS_QENCODER
int index;
char buf[9];
@@ -148,46 +136,6 @@ int stm32_bringup(void)
}
#endif
-#ifdef CONFIG_STM32_I2C1
- /* Get the I2C lower half instance */
-
- i2c1 = stm32_i2cbus_initialize(1);
- if (i2c1 == NULL)
- {
- i2cerr("ERROR: Initialize I2C1: %d\n", ret);
- }
- else
- {
- /* Register the I2C character driver */
-
- ret = i2c_register(i2c1, 1);
- if (ret < 0)
- {
- i2cerr("ERROR: Failed to register I2C1 device: %d\n", ret);
- }
- }
-#endif
-
-#ifdef CONFIG_STM32_I2C3
- /* Get the I2C lower half instance */
-
- i2c3 = stm32_i2cbus_initialize(3);
- if (i2c3 == NULL)
- {
- i2cerr("ERROR: Initialize I2C3: %d\n", ret);
- }
- else
- {
- /* Register the I2C character driver */
-
- ret = i2c_register(i2c3, 3);
- if (ret < 0)
- {
- i2cerr("ERROR: Failed to register I2C3 device: %d\n", ret);
- }
- }
-#endif
-
#ifdef CONFIG_SPI_DRIVER
stm32_spiregister();
/* If called it during board_init,
diff --git a/boards/arm/stm32l4/nucleo-l452re/src/stm32_bringup.c
b/boards/arm/stm32l4/nucleo-l452re/src/stm32_bringup.c
index 01d59511480..618aa39eea9 100644
--- a/boards/arm/stm32l4/nucleo-l452re/src/stm32_bringup.c
+++ b/boards/arm/stm32l4/nucleo-l452re/src/stm32_bringup.c
@@ -30,12 +30,10 @@
#include <nuttx/debug.h>
#include <nuttx/input/buttons.h>
-#include <nuttx/i2c/i2c_master.h>
#include <nuttx/leds/userled.h>
#include <nuttx/board.h>
#include <nuttx/fs/fs.h>
-#include "stm32l4_i2c.h"
#include "nucleo-l452re.h"
#include <arch/board/board.h>
@@ -46,11 +44,6 @@
* Pre-processor Definitions
****************************************************************************/
-#undef HAVE_I2C_DRIVER
-#if defined(CONFIG_STM32_I2C1) && defined(CONFIG_I2C_DRIVER)
-# define HAVE_I2C_DRIVER 1
-#endif
-
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -68,9 +61,6 @@
int stm32_bringup(void)
{
-#ifdef HAVE_I2C_DRIVER
- struct i2c_master_s *i2c;
-#endif
int ret;
/* Initialize the board features common to all STM32 boards */
@@ -100,26 +90,6 @@ int stm32_bringup(void)
#endif
#endif /* CONFIG_INPUT_BUTTONS */
-#ifdef HAVE_I2C_DRIVER
- /* Get the I2C lower half instance */
-
- i2c = stm32_i2cbus_initialize(1);
- if (i2c == NULL)
- {
- i2cerr("ERROR: Initialize I2C1: %d\n", ret);
- }
- else
- {
- /* Register the I2C character driver */
-
- ret = i2c_register(i2c, 1);
- if (ret < 0)
- {
- i2cerr("ERROR: Failed to register I2C1 device: %d\n", ret);
- }
- }
-#endif
-
#ifdef CONFIG_DAC
ainfo("Initializing DAC\n");
diff --git a/boards/arm/stm32l4/nucleo-l476rg/src/stm32_bringup.c
b/boards/arm/stm32l4/nucleo-l476rg/src/stm32_bringup.c
index 4125db1cb17..4804921212b 100644
--- a/boards/arm/stm32l4/nucleo-l476rg/src/stm32_bringup.c
+++ b/boards/arm/stm32l4/nucleo-l476rg/src/stm32_bringup.c
@@ -51,8 +51,6 @@
# include "stm32l4_rtc.h"
#endif
-#include "stm32l4_i2c.h"
-
#ifdef CONFIG_SENSORS_BMP280
#include "stm32_bmp280.h"
#endif
@@ -83,59 +81,6 @@
# define MMCSD_MINOR 0
#endif
-/****************************************************************************
- * Name: stm32_i2c_register
- *
- * Description:
- * Register one I2C drivers for the I2C tool.
- *
- ****************************************************************************/
-
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
-static void stm32_i2c_register(int bus)
-{
- struct i2c_master_s *i2c;
- int ret;
-
- i2c = stm32_i2cbus_initialize(bus);
- if (i2c == NULL)
- {
- syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus);
- }
- else
- {
- ret = i2c_register(i2c, bus);
- if (ret < 0)
- {
- syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
- bus, ret);
- stm32_i2cbus_uninitialize(i2c);
- }
- }
-}
-#endif
-
-/****************************************************************************
- * Name: stm32_i2ctool
- *
- * Description:
- * Register I2C drivers for the I2C tool.
- *
- ****************************************************************************/
-
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
-static void stm32_i2ctool(void)
-{
- stm32_i2c_register(1);
-#if 0
- stm32_i2c_register(1);
- stm32_i2c_register(2);
-#endif
-}
-#else
-# define stm32_i2ctool()
-#endif
-
/****************************************************************************
* Name: stm32_bringup
*
@@ -153,10 +98,6 @@ int stm32_bringup(void)
struct rtc_lowerhalf_s *rtclower;
#endif
-#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
- stm32_i2ctool();
-#endif
-
#ifdef CONFIG_SENSORS_QENCODER
int index;
char buf[9];
diff --git a/boards/arm/stm32l4/nucleo-l496zg/src/stm32_bringup.c
b/boards/arm/stm32l4/nucleo-l496zg/src/stm32_bringup.c
index e513261b52a..a110e40a1b2 100644
--- a/boards/arm/stm32l4/nucleo-l496zg/src/stm32_bringup.c
+++ b/boards/arm/stm32l4/nucleo-l496zg/src/stm32_bringup.c
@@ -34,26 +34,8 @@
#include <nuttx/fs/fs.h>
#include <nuttx/leds/userled.h>
-#include "stm32l4_i2c.h"
#include "board_common.h"
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-#if defined(CONFIG_STM32_I2C1)
-struct i2c_master_s *i2c1;
-#endif
-#if defined(CONFIG_STM32_I2C2)
-struct i2c_master_s *i2c2;
-#endif
-#if defined(CONFIG_STM32_I2C3)
-struct i2c_master_s *i2c3;
-#endif
-#if defined(CONFIG_STM32_I2C4)
-struct i2c_master_s *i2c4;
-#endif
-
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -155,39 +137,6 @@ int stm32_bringup(void)
}
#endif
-#if defined(CONFIG_I2C)
- /* Configure I2C */
-
- /* REVISIT: this is ugly! */
-
-#if defined(CONFIG_STM32_I2C1)
- i2c1 = stm32_i2cbus_initialize(1);
-#endif
-#if defined(CONFIG_STM32_I2C2)
- i2c2 = stm32_i2cbus_initialize(2);
-#endif
-#if defined(CONFIG_STM32_I2C3)
- i2c3 = stm32_i2cbus_initialize(3);
-#endif
-#if defined(CONFIG_STM32_I2C4)
- i2c4 = stm32_i2cbus_initialize(4);
-#endif
-#ifdef CONFIG_I2C_DRIVER
-#if defined(CONFIG_STM32_I2C1)
- i2c_register(i2c1, 1);
-#endif
-#if defined(CONFIG_STM32_I2C2)
- i2c_register(i2c2, 2);
-#endif
-#if defined(CONFIG_STM32_I2C3)
- i2c_register(i2c3, 3);
-#endif
-#if defined(CONFIG_STM32_I2C4)
- i2c_register(i2c4, 4);
-#endif
-#endif
-#endif /* CONFIG_I2C */
-
UNUSED(ret);
return OK;
}
diff --git a/boards/arm/stm32u5/nucleo-u5a5zj-q/src/stm32_bringup.c
b/boards/arm/stm32u5/nucleo-u5a5zj-q/src/stm32_bringup.c
index 6cb3990df16..c7fc27ebe79 100644
--- a/boards/arm/stm32u5/nucleo-u5a5zj-q/src/stm32_bringup.c
+++ b/boards/arm/stm32u5/nucleo-u5a5zj-q/src/stm32_bringup.c
@@ -41,27 +41,14 @@
#include <stm32_spi.h>
-#if defined(CONFIG_I2C)
-
-#include "stm32_i2c.h"
-struct i2c_master_s *i2c1_m;
-struct i2c_master_s *i2c2_m;
-# ifdef CONFIG_RTC_DSXXXX
-# include <nuttx/timers/rtc.h>
-# include <nuttx/timers/ds3231.h>
-# endif /* CONFIG_RTC_DSXXXX */
-
-#endif /* CONFIG_I2C */
+#ifdef CONFIG_RTC_DSXXXX
+# include <nuttx/timers/rtc.h>
+# include <nuttx/timers/ds3231.h>
+# include "stm32_i2c.h"
+#endif
#include "board_common.h"
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-#define DEVNO_ZERO 0
-#define DEVNO_ONE 1
-#define DEVNO_TWO 2
-
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -90,6 +77,9 @@ int up_rtc_initialize(void)
int stm32_bringup(void)
{
+#ifdef CONFIG_RTC_DSXXXX
+ struct i2c_master_s *i2c;
+#endif
int ret;
/* Initialize the board features common to all STM32 boards */
@@ -101,57 +91,28 @@ int stm32_bringup(void)
ret);
}
-#if defined(CONFIG_I2C)
- i2c1_m = stm32_i2cbus_initialize(1);
- if (i2c1_m == NULL)
- {
- syslog(LOG_ERR, "ERROR: Failed to init i2c controller\n");
- return(-1);
- }
-
- ret = i2c_register(i2c1_m, DEVNO_ONE);
- if (ret < 0)
- {
- syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
- DEVNO_ONE, ret);
- stm32_i2cbus_uninitialize(i2c1_m);
- return -1;
- }
-
-#if defined(STM32_I2C2)
- i2c2_m = stm32_i2cbus_initialize(2);
- if (i2c2_m == NULL)
- {
- syslog(LOG_ERR, "ERROR: Failed to init i2c controller\n");
- return(-1);
- }
-
- ret = i2c_register(i2c2_m, DEVNO_TWO);
- if (ret < 0)
- {
- syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
- DEVNO_TWO, ret);
- stm32_i2cbus_uninitialize(i2c1_m);
- stm32_i2cbus_uninitialize(i2c2_m);
- return -1;
- }
-#endif /* STM32_I2C2 */
-#endif /* CONFIG_I2C */
-
-#if defined(CONFIG_RTC) && defined(CONFIG_RTC_EXTERNAL) &&
defined(CONFIG_RTC_DSXXXX)
- ret = dsxxxx_rtc_initialize(i2c1_m);
- if (ret < 0)
+#ifdef CONFIG_RTC_DSXXXX
+ i2c = stm32_i2cbus_initialize(1);
+ if (i2c == NULL)
{
- syslog(LOG_ERR, "ERROR: dsxxxx_rtc_initialize() failed: %d\n", ret);
+ syslog(LOG_ERR, "ERROR: Failed to get I2C1 interface\n");
}
else
{
- /* Synchronize the system time to the RTC time */
-
- syslog(LOG_INFO, "INFO: clock sync\n");
- clock_synchronize(NULL);
+ ret = dsxxxx_rtc_initialize(i2c);
+ if (ret < 0)
+ {
+ syslog(LOG_ERR, "ERROR: dsxxxx_rtc_initialize() failed: %d\n",
+ ret);
+ }
+ else
+ {
+ /* Synchronize the system time to the RTC time */
+
+ clock_synchronize(NULL);
+ }
}
-#endif /* CONFIG_RTC */
+#endif
UNUSED(ret);
return OK;