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

commit c75e12c0d806adf110d8e6822c2a6f3c075d1f7b
Author: raiden00pl <[email protected]>
AuthorDate: Mon Oct 12 10:02:57 2026 +0200

    boards/arm: register CAN in the common STM32 board init
    
    Call stm32_can_setup() and stm32_cansock_setup() from
    stm32_common_initialize() when the CAN or FDCAN character driver or
    SocketCAN support is enabled, and remove these calls from the Nucleo
    boards.
    
    A failed CAN setup is logged and the initialization continues. The
    nucleo-f722ze, nucleo-f746zg, nucleo-f767zi and nucleo-l476rg bringup
    returned an error in this case.
    
    Signed-off-by: raiden00pl <[email protected]>
    Assisted-by: Claude Code
---
 boards/arm/common/stm32/src/board_common.c         | 41 ++++++++++++++++++++++
 .../arm/stm32c0/nucleo-c092rc/src/stm32_bringup.c  | 22 ------------
 .../arm/stm32f3/nucleo-f302r8/src/stm32_bringup.c  | 22 ------------
 boards/arm/stm32f3/nucleo-f303re/src/stm32_boot.c  | 11 ------
 .../arm/stm32f4/nucleo-f446re/src/stm32_bringup.c  | 22 ------------
 .../arm/stm32f7/nucleo-f722ze/src/stm32_bringup.c  | 25 -------------
 .../arm/stm32f7/nucleo-f746zg/src/stm32_bringup.c  | 25 -------------
 .../arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c  | 25 -------------
 .../arm/stm32g4/nucleo-g431rb/src/stm32_bringup.c  | 22 ------------
 .../arm/stm32h5/nucleo-h563zi/src/stm32_bringup.c  | 12 -------
 .../arm/stm32l4/nucleo-l476rg/src/stm32_bringup.c  | 10 ------
 11 files changed, 41 insertions(+), 196 deletions(-)

diff --git a/boards/arm/common/stm32/src/board_common.c 
b/boards/arm/common/stm32/src/board_common.c
index b9b7fcd772f..660513ec28b 100644
--- a/boards/arm/common/stm32/src/board_common.c
+++ b/boards/arm/common/stm32/src/board_common.c
@@ -33,10 +33,31 @@
 
 #include <arch/board/board.h>
 
+/* The STM32H7 FDCAN driver has its own SocketCAN interface */
+
+#if (defined(CONFIG_STM32_CAN_CHARDRIVER) || \
+     defined(CONFIG_STM32_FDCAN_CHARDRIVER)) && \
+    !defined(CONFIG_STM32_HAVE_FDCAN_H7)
+#  define HAVE_CAN_SETUP
+#endif
+
+#if (defined(CONFIG_STM32_CAN_SOCKET) || defined(CONFIG_STM32_FDCAN_SOCKET)) 
&& \
+    !defined(CONFIG_STM32_HAVE_FDCAN_H7)
+#  define HAVE_CANSOCK_SETUP
+#endif
+
 #if defined(CONFIG_STM32_IWDG) || defined(CONFIG_STM32_WWDG)
 #  include "stm32_wdg.h"
 #endif
 
+#ifdef HAVE_CAN_SETUP
+#  include "stm32_can_setup.h"
+#endif
+
+#ifdef HAVE_CANSOCK_SETUP
+#  include "stm32_cansock_setup.h"
+#endif
+
 #include "board_common.h"
 
 /****************************************************************************
@@ -107,6 +128,26 @@ int stm32_common_initialize(void)
   stm32_wwdginitialize("/dev/watchdog1");
 #endif
 
+#ifdef HAVE_CAN_SETUP
+  /* Register the CAN character drivers */
+
+  ret = stm32_can_setup();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: stm32_can_setup() failed: %d\n", ret);
+    }
+#endif
+
+#ifdef HAVE_CANSOCK_SETUP
+  /* Initialize the SocketCAN interfaces */
+
+  ret = stm32_cansock_setup();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: stm32_cansock_setup() failed: %d\n", ret);
+    }
+#endif
+
   UNUSED(ret);
   return OK;
 }
diff --git a/boards/arm/stm32c0/nucleo-c092rc/src/stm32_bringup.c 
b/boards/arm/stm32c0/nucleo-c092rc/src/stm32_bringup.c
index 6c3f4eda847..1a47d5184d5 100644
--- a/boards/arm/stm32c0/nucleo-c092rc/src/stm32_bringup.c
+++ b/boards/arm/stm32c0/nucleo-c092rc/src/stm32_bringup.c
@@ -55,8 +55,6 @@
 
 #include "nucleo-c092rc.h"
 #include "board_common.h"
-#include "stm32_can_setup.h"
-#include "stm32_cansock_setup.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -152,26 +150,6 @@ int stm32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_STM32_FDCAN_CHARDRIVER
-  /* Initialize CAN and register the CAN driver. */
-
-  ret = stm32_can_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_fdcan_setup failed: %d\n", ret);
-    }
-#endif
-
-#ifdef CONFIG_STM32_FDCAN_SOCKET
-  /* Initialize CAN socket interface */
-
-  ret = stm32_cansock_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_cansock_setup failed: %d\n", ret);
-    }
-#endif
-
 #ifdef CONFIG_SENSORS_QENCODER
   /* Initialize and register the qencoder driver - TIM3 */
 
diff --git a/boards/arm/stm32f3/nucleo-f302r8/src/stm32_bringup.c 
b/boards/arm/stm32f3/nucleo-f302r8/src/stm32_bringup.c
index bac0e07171e..0124964659b 100644
--- a/boards/arm/stm32f3/nucleo-f302r8/src/stm32_bringup.c
+++ b/boards/arm/stm32f3/nucleo-f302r8/src/stm32_bringup.c
@@ -51,8 +51,6 @@
 
 #include "nucleo-f302r8.h"
 #include "board_common.h"
-#include "stm32_can_setup.h"
-#include "stm32_cansock_setup.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -175,26 +173,6 @@ int stm32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_STM32_CAN_CHARDRIVER
-  /* Initialize CAN and register the CAN driver. */
-
-  ret = stm32_can_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
-    }
-#endif
-
-#ifdef CONFIG_STM32_CAN_SOCKET
-  /* Initialize CAN socket interface */
-
-  ret = stm32_cansock_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_cansock_setup failed: %d\n", ret);
-    }
-#endif
-
   UNUSED(ret);
   return OK;
 }
diff --git a/boards/arm/stm32f3/nucleo-f303re/src/stm32_boot.c 
b/boards/arm/stm32f3/nucleo-f303re/src/stm32_boot.c
index b9594df78c4..4d611ae7dc4 100644
--- a/boards/arm/stm32f3/nucleo-f303re/src/stm32_boot.c
+++ b/boards/arm/stm32f3/nucleo-f303re/src/stm32_boot.c
@@ -35,7 +35,6 @@
 
 #include "nucleo-f303re.h"
 #include "board_common.h"
-#include "stm32_can_setup.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -167,16 +166,6 @@ void board_late_initialize(void)
     }
 #endif
 
-#ifdef CONFIG_STM32_CAN_CHARDRIVER
-  /* Initialize CAN and register the CAN driver. */
-
-  ret = stm32_can_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
-    }
-#endif
-
   UNUSED(ret);
 }
 #endif /* CONFIG_BOARD_LATE_INITIALIZE */
diff --git a/boards/arm/stm32f4/nucleo-f446re/src/stm32_bringup.c 
b/boards/arm/stm32f4/nucleo-f446re/src/stm32_bringup.c
index cabda7fed9a..0d801644835 100644
--- a/boards/arm/stm32f4/nucleo-f446re/src/stm32_bringup.c
+++ b/boards/arm/stm32f4/nucleo-f446re/src/stm32_bringup.c
@@ -69,8 +69,6 @@
 #endif
 #include "nucleo-f446re.h"
 #include "board_common.h"
-#include "stm32_can_setup.h"
-#include "stm32_cansock_setup.h"
 
 /****************************************************************************
  * Public Functions
@@ -191,26 +189,6 @@ int stm32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_STM32_CAN_CHARDRIVER
-  /* Initialize CAN and register the CAN driver. */
-
-  ret = stm32_can_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
-    }
-#endif
-
-#ifdef CONFIG_STM32_CAN_SOCKET
-  /* Initialize CAN socket interface */
-
-  ret = stm32_cansock_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_cansock_setup failed: %d\n", ret);
-    }
-#endif
-
 #ifdef CONFIG_VIDEO_FB
   /* Initialize and register the framebuffer driver */
 
diff --git a/boards/arm/stm32f7/nucleo-f722ze/src/stm32_bringup.c 
b/boards/arm/stm32f7/nucleo-f722ze/src/stm32_bringup.c
index 4ffd648e7d6..11542dbccea 100644
--- a/boards/arm/stm32f7/nucleo-f722ze/src/stm32_bringup.c
+++ b/boards/arm/stm32f7/nucleo-f722ze/src/stm32_bringup.c
@@ -40,14 +40,6 @@
 
 #include "stm32_i2c.h"
 
-#ifdef CONFIG_STM32_CAN_CHARDRIVER
-#  include "stm32_can_setup.h"
-#endif
-
-#ifdef CONFIG_STM32_CAN_SOCKET
-#  include "stm32_cansock_setup.h"
-#endif
-
 #ifdef CONFIG_STM32_ROMFS
 #  include "stm32_romfs.h"
 #endif
@@ -238,23 +230,6 @@ int stm32_bringup(void)
 
 #endif
 
-#ifdef CONFIG_STM32_CAN_CHARDRIVER
-  ret = stm32_can_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32f7_can_setup failed: %d\n", ret);
-      return ret;
-    }
-#endif
-
-#ifdef CONFIG_STM32_CAN_SOCKET
-  ret = stm32_cansock_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_cansock_setup failed: %d\n", ret);
-    }
-#endif
-
 #if defined(CONFIG_I2C) && defined(CONFIG_STM32_I2C1)
   i2c_bus = 1;
   i2c = stm32_i2cbus_initialize(i2c_bus);
diff --git a/boards/arm/stm32f7/nucleo-f746zg/src/stm32_bringup.c 
b/boards/arm/stm32f7/nucleo-f746zg/src/stm32_bringup.c
index 2028404da7d..1f98b475326 100644
--- a/boards/arm/stm32f7/nucleo-f746zg/src/stm32_bringup.c
+++ b/boards/arm/stm32f7/nucleo-f746zg/src/stm32_bringup.c
@@ -40,14 +40,6 @@
 
 #include "stm32_i2c.h"
 
-#ifdef CONFIG_STM32_CAN_CHARDRIVER
-#  include "stm32_can_setup.h"
-#endif
-
-#ifdef CONFIG_STM32_CAN_SOCKET
-#  include "stm32_cansock_setup.h"
-#endif
-
 #ifdef CONFIG_STM32_ROMFS
 #  include "stm32_romfs.h"
 #endif
@@ -242,23 +234,6 @@ int stm32_bringup(void)
 
 #endif
 
-#ifdef CONFIG_STM32_CAN_CHARDRIVER
-  ret = stm32_can_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32f7_can_setup failed: %d\n", ret);
-      return ret;
-    }
-#endif
-
-#ifdef CONFIG_STM32_CAN_SOCKET
-  ret = stm32_cansock_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_cansock_setup failed: %d\n", ret);
-    }
-#endif
-
 #if defined(CONFIG_I2C) && defined(CONFIG_STM32_I2C1)
   i2c_bus = 1;
   i2c = stm32_i2cbus_initialize(i2c_bus);
diff --git a/boards/arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c 
b/boards/arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c
index 3d666441cb9..32a4a90558c 100644
--- a/boards/arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c
+++ b/boards/arm/stm32f7/nucleo-f767zi/src/stm32_bringup.c
@@ -40,14 +40,6 @@
 
 #include "stm32_i2c.h"
 
-#ifdef CONFIG_STM32_CAN_CHARDRIVER
-#  include "stm32_can_setup.h"
-#endif
-
-#ifdef CONFIG_STM32_CAN_SOCKET
-#  include "stm32_cansock_setup.h"
-#endif
-
 #ifdef CONFIG_STM32_ROMFS
 #  include "stm32_romfs.h"
 #endif
@@ -253,23 +245,6 @@ int stm32_bringup(void)
 
 #endif
 
-#ifdef CONFIG_STM32_CAN_CHARDRIVER
-  ret = stm32_can_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32f7_can_setup failed: %d\n", ret);
-      return ret;
-    }
-#endif
-
-#ifdef CONFIG_STM32_CAN_SOCKET
-  ret = stm32_cansock_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_cansock_setup failed: %d\n", ret);
-    }
-#endif
-
 #if defined(CONFIG_I2C) && defined(CONFIG_STM32_I2C1)
   i2c_bus = 1;
   i2c = stm32_i2cbus_initialize(i2c_bus);
diff --git a/boards/arm/stm32g4/nucleo-g431rb/src/stm32_bringup.c 
b/boards/arm/stm32g4/nucleo-g431rb/src/stm32_bringup.c
index dbbcf6dc97e..4137154a4c9 100644
--- a/boards/arm/stm32g4/nucleo-g431rb/src/stm32_bringup.c
+++ b/boards/arm/stm32g4/nucleo-g431rb/src/stm32_bringup.c
@@ -46,8 +46,6 @@
 
 #include "nucleo-g431rb.h"
 #include "board_common.h"
-#include "stm32_can_setup.h"
-#include "stm32_cansock_setup.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -161,26 +159,6 @@ int stm32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_STM32_FDCAN_CHARDRIVER
-  /* Initialize CAN and register the CAN driver. */
-
-  ret = stm32_can_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_fdcan_setup failed: %d\n", ret);
-    }
-#endif
-
-#ifdef CONFIG_STM32_FDCAN_SOCKET
-  /* Initialize CAN socket interface */
-
-  ret = stm32_cansock_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_cansock_setup failed: %d\n", ret);
-    }
-#endif
-
   UNUSED(ret);
   return OK;
 }
diff --git a/boards/arm/stm32h5/nucleo-h563zi/src/stm32_bringup.c 
b/boards/arm/stm32h5/nucleo-h563zi/src/stm32_bringup.c
index 7bfe6d24ad6..f903ea339fc 100644
--- a/boards/arm/stm32h5/nucleo-h563zi/src/stm32_bringup.c
+++ b/boards/arm/stm32h5/nucleo-h563zi/src/stm32_bringup.c
@@ -39,8 +39,6 @@
 
 #include "board_common.h"
 
-#include "stm32_can_setup.h"
-
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
@@ -119,16 +117,6 @@ int stm32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_STM32_FDCAN_CHARDRIVER
-  /* Initialize CAN and register the CAN driver. */
-
-  ret = stm32_can_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
-    }
-#endif
-
 #ifdef CONFIG_STM32_SPI
   /* Cannot call at board init because irq_attach would be called before
    * before irq_initialize is called.
diff --git a/boards/arm/stm32l4/nucleo-l476rg/src/stm32_bringup.c 
b/boards/arm/stm32l4/nucleo-l476rg/src/stm32_bringup.c
index e3e8fcee608..faa66fd46d6 100644
--- a/boards/arm/stm32l4/nucleo-l476rg/src/stm32_bringup.c
+++ b/boards/arm/stm32l4/nucleo-l476rg/src/stm32_bringup.c
@@ -66,7 +66,6 @@
 #endif
 
 #include "board_common.h"
-#include "stm32_can_setup.h"
 
 /****************************************************************************
  * Private Data
@@ -276,15 +275,6 @@ int stm32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_CAN
-  ret = stm32_can_setup();
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
-      return ret;
-    }
-#endif
-
   /* Initialize MMC and register the MMC driver. */
 
 #ifdef HAVE_MMCSD_SPI

Reply via email to