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 d7eb077bab0cd2e5953cdf28fe8940fac879c6f3
Author: raiden00pl <[email protected]>
AuthorDate: Wed Nov 25 18:09:55 2026 +0100

    boards/arm/common/stm32: Register the SocketCAN ports only once.
    
    Without NETDEV_LATEINIT the arch registers the ports in
    arm_netinitialize(), so stm32_cansock_setup() registered them twice.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: raiden00pl <[email protected]>
---
 boards/arm/common/stm32/src/stm32_cansock_setup.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/boards/arm/common/stm32/src/stm32_cansock_setup.c 
b/boards/arm/common/stm32/src/stm32_cansock_setup.c
index ce4eefe93db..5970dcda48b 100644
--- a/boards/arm/common/stm32/src/stm32_cansock_setup.c
+++ b/boards/arm/common/stm32/src/stm32_cansock_setup.c
@@ -65,6 +65,7 @@
 
 /* Enabled CAN instances */
 
+#ifdef CONFIG_NETDEV_LATEINIT
 static const uint8_t g_can_ports[] =
 {
 #if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_FDCAN1)
@@ -77,6 +78,7 @@ static const uint8_t g_can_ports[] =
   3,
 #endif
 };
+#endif
 
 /****************************************************************************
  * Public Functions
@@ -92,8 +94,10 @@ static const uint8_t g_can_ports[] =
 
 int stm32_cansock_setup(void)
 {
+#ifdef CONFIG_NETDEV_LATEINIT
   int ret;
   int i;
+#endif
 
 #ifdef BOARD_CAN_GPIO_STBY
   /* Enable the CAN transceiver */
@@ -102,6 +106,9 @@ int stm32_cansock_setup(void)
   stm32_gpiowrite(BOARD_CAN_GPIO_STBY, false);
 #endif
 
+#ifdef CONFIG_NETDEV_LATEINIT
+  /* Without NETDEV_LATEINIT, arm_netinitialize() registers the ports */
+
   for (i = 0; i < sizeof(g_can_ports); i++)
     {
       ret = CANSOCK_INITIALIZE(g_can_ports[i]);
@@ -112,6 +119,7 @@ int stm32_cansock_setup(void)
           return ret;
         }
     }
+#endif
 
   return OK;
 }

Reply via email to