This is an automated email from the ASF dual-hosted git repository.

simbit18 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 4cf1566657d3b558afd87000c37626be4c6ecb77
Author: Alan Carvalho de Assis <[email protected]>
AuthorDate: Fri Oct 9 11:41:12 2026 -0300

    boards/stm32f4discovery: Add board support to SCL3300 sensor
    
    This commit adds support to SCL3300 driver.
    
    Signed-off-by: Alan C. Assis <[email protected]>
    Assisted-by: Claude Code
---
 boards/arm/common/stm32/include/stm32_scl3300.h    | 83 ++++++++++++++++++++++
 boards/arm/common/stm32/src/CMakeLists.txt         |  4 ++
 boards/arm/common/stm32/src/Make.defs              |  4 ++
 boards/arm/common/stm32/src/stm32_scl3300.c        | 78 ++++++++++++++++++++
 .../stm32f4discovery/configs/scl3300/defconfig     | 57 +++++++++++++++
 .../stm32f4/stm32f4discovery/src/stm32_bringup.c   | 17 +++++
 .../arm/stm32f4/stm32f4discovery/src/stm32_spi.c   | 20 +++++-
 .../stm32f4discovery/src/stm32f4discovery.h        | 17 +++++
 8 files changed, 278 insertions(+), 2 deletions(-)

diff --git a/boards/arm/common/stm32/include/stm32_scl3300.h 
b/boards/arm/common/stm32/include/stm32_scl3300.h
new file mode 100644
index 00000000000..2dc639949cd
--- /dev/null
+++ b/boards/arm/common/stm32/include/stm32_scl3300.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+ * boards/arm/common/stm32/include/stm32_scl3300.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __BOARDS_ARM_COMMON_STM32_INCLUDE_STM32_SCL3300_H
+#define __BOARDS_ARM_COMMON_STM32_INCLUDE_STM32_SCL3300_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_scl3300_initialize
+ *
+ * Description:
+ *   Initialize and register the Murata SCL3300 inclinometer with the
+ *   default configuration (Mode 1, always on).
+ *
+ * Input Parameters:
+ *   devno     - The uORB topic instance and SPIDEV_ACCELEROMETER() index.
+ *   spi_busno - The SPI bus number.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_scl3300_initialize(int devno, int spi_busno);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BOARDS_ARM_COMMON_STM32_INCLUDE_STM32_SCL3300_H */
diff --git a/boards/arm/common/stm32/src/CMakeLists.txt 
b/boards/arm/common/stm32/src/CMakeLists.txt
index 50b724581eb..6175c5a0c30 100644
--- a/boards/arm/common/stm32/src/CMakeLists.txt
+++ b/boards/arm/common/stm32/src/CMakeLists.txt
@@ -86,6 +86,10 @@ if(CONFIG_SENSORS_MT6816)
   list(APPEND SRCS stm32_mt6816.c)
 endif()
 
+if(CONFIG_SENSORS_SCL3300)
+  list(APPEND SRCS stm32_scl3300.c)
+endif()
+
 if(CONFIG_SENSORS_ZEROCROSS)
   list(APPEND SRCS stm32_zerocross.c)
 endif()
diff --git a/boards/arm/common/stm32/src/Make.defs 
b/boards/arm/common/stm32/src/Make.defs
index e62d8f0e291..3d92678a36b 100644
--- a/boards/arm/common/stm32/src/Make.defs
+++ b/boards/arm/common/stm32/src/Make.defs
@@ -92,6 +92,10 @@ ifeq ($(CONFIG_SENSORS_MT6816),y)
   CSRCS += stm32_mt6816.c
 endif
 
+ifeq ($(CONFIG_SENSORS_SCL3300),y)
+  CSRCS += stm32_scl3300.c
+endif
+
 ifeq ($(CONFIG_INPUT_MPR121_KEYPAD),y)
   CSRCS += stm32_mpr121.c
 endif
diff --git a/boards/arm/common/stm32/src/stm32_scl3300.c 
b/boards/arm/common/stm32/src/stm32_scl3300.c
new file mode 100644
index 00000000000..cd10d2ba22a
--- /dev/null
+++ b/boards/arm/common/stm32/src/stm32_scl3300.c
@@ -0,0 +1,78 @@
+/****************************************************************************
+ * boards/arm/common/stm32/src/stm32_scl3300.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <nuttx/debug.h>
+
+#include <nuttx/sensors/scl3300.h>
+#include <nuttx/spi/spi.h>
+
+#include "stm32_spi.h"
+#include "stm32_scl3300.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_scl3300_initialize
+ *
+ * Description:
+ *   Initialize and register the Murata SCL3300 inclinometer with the
+ *   default configuration (Mode 1, always on).
+ *
+ * Input Parameters:
+ *   devno     - The uORB topic instance and SPIDEV_ACCELEROMETER() index.
+ *   spi_busno - The SPI bus number.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_scl3300_initialize(int devno, int spi_busno)
+{
+  struct spi_dev_s *spi;
+  int ret;
+
+  spi = stm32_spibus_initialize(spi_busno);
+  if (spi == NULL)
+    {
+      snerr("ERROR: Failed to initialize SPI%d\n", spi_busno);
+      return -ENODEV;
+    }
+
+  ret = scl3300_register(devno, spi, NULL);
+  if (ret < 0)
+    {
+      snerr("ERROR: Failed to register SCL3300 %d on SPI%d: %d\n",
+            devno, spi_busno, ret);
+    }
+
+  return ret;
+}
diff --git a/boards/arm/stm32f4/stm32f4discovery/configs/scl3300/defconfig 
b/boards/arm/stm32f4/stm32f4discovery/configs/scl3300/defconfig
new file mode 100644
index 00000000000..e12715c8c15
--- /dev/null
+++ b/boards/arm/stm32f4/stm32f4discovery/configs/scl3300/defconfig
@@ -0,0 +1,57 @@
+#
+# This file is autogenerated: PLEASE DO NOT EDIT IT.
+#
+# You can use "make menuconfig" to make any modifications to the installed 
.config file.
+# You can then do "make savedefconfig" to generate a new defconfig file that 
includes your
+# modifications.
+#
+# CONFIG_ARCH_FPU is not set
+# CONFIG_NSH_ARGCAT is not set
+# CONFIG_NSH_CMDOPT_HEXDUMP is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="stm32f4discovery"
+CONFIG_ARCH_BOARD_COMMON=y
+CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
+CONFIG_ARCH_BUTTONS=y
+CONFIG_ARCH_CHIP="stm32f4"
+CONFIG_ARCH_CHIP_STM32=y
+CONFIG_ARCH_CHIP_STM32F407VG=y
+CONFIG_ARCH_CHIP_STM32F4=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_BOARD_LOOPSPERMSEC=16717
+CONFIG_BUILTIN=y
+CONFIG_EXAMPLES_HELLO=y
+CONFIG_FS_PROCFS=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INTELHEX_BINARY=y
+CONFIG_LIBC_FLOATINGPOINT=y
+CONFIG_LINE_MAX=64
+CONFIG_MM_REGIONS=2
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=114688
+CONFIG_RAM_START=0x20000000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_SENSORS=y
+CONFIG_SENSORS_SCL3300=y
+CONFIG_START_DAY=6
+CONFIG_START_MONTH=12
+CONFIG_START_YEAR=2011
+CONFIG_STM32_JTAG_SW_ENABLE=y
+CONFIG_STM32_PWR=y
+CONFIG_STM32_SPI1=y
+CONFIG_STM32_USART2=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_SYSTEM_SENSORTEST=y
+CONFIG_UORB=y
+CONFIG_UORB_LISTENER=y
+CONFIG_USART2_RXBUFSIZE=128
+CONFIG_USART2_SERIAL_CONSOLE=y
+CONFIG_USART2_TXBUFSIZE=128
+CONFIG_USENSOR=y
diff --git a/boards/arm/stm32f4/stm32f4discovery/src/stm32_bringup.c 
b/boards/arm/stm32f4/stm32f4discovery/src/stm32_bringup.c
index 7a8dec8f346..d6fd03eb589 100644
--- a/boards/arm/stm32f4/stm32f4discovery/src/stm32_bringup.c
+++ b/boards/arm/stm32f4/stm32f4discovery/src/stm32_bringup.c
@@ -67,6 +67,10 @@
 #include "stm32_mt6816.h"
 #endif
 
+#ifdef CONFIG_SENSORS_SCL3300
+#include "stm32_scl3300.h"
+#endif
+
 #ifdef CONFIG_INPUT_MPR121_KEYPAD
 #include "stm32_mpr121.h"
 #endif
@@ -282,6 +286,18 @@ int stm32_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_SENSORS_SCL3300
+  /* Initialize the SCL3300 inclinometer on SPI1 as
+   * /dev/uorb/sensor_inclinometer<SCL3300_DEVNO>
+   */
+
+  ret = board_scl3300_initialize(SCL3300_DEVNO, 1);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: board_scl3300_initialize failed: %d\n", ret);
+    }
+#endif
+
 #ifdef CONFIG_SENSORS_LIS3DSH_UORB
   /* Initialize the on-board LIS3DSH accelerometer as a uORB sensor on SPI1 */
 
@@ -666,6 +682,7 @@ int stm32_bringup(void)
 
 #if defined(CONFIG_RNDIS) && !defined(CONFIG_RNDIS_COMPOSITE)
   uint8_t mac[6];
+
   mac[0] = 0xa0; /* TODO */
   mac[1] = (CONFIG_NETINIT_MACADDR_2 >> (8 * 0)) & 0xff;
   mac[2] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 3)) & 0xff;
diff --git a/boards/arm/stm32f4/stm32f4discovery/src/stm32_spi.c 
b/boards/arm/stm32f4/stm32f4discovery/src/stm32_spi.c
index c55d078d508..c464a3d8b5a 100644
--- a/boards/arm/stm32f4/stm32f4discovery/src/stm32_spi.c
+++ b/boards/arm/stm32f4/stm32f4discovery/src/stm32_spi.c
@@ -70,8 +70,17 @@ void weak_function stm32_spidev_initialize(void)
 #endif
 
 #if defined(CONFIG_STM32_SPI1) && (defined(CONFIG_SENSORS_LIS3MDL) || \
-    defined(CONFIG_SENSORS_LIS3DSH_UORB) || defined(CONFIG_LIS3DSH))
-  stm32_configgpio(GPIO_CS_MEMS);    /* MEMS chip select */
+    defined(CONFIG_SENSORS_LIS3DSH_UORB) || defined(CONFIG_LIS3DSH) || \
+    defined(CONFIG_SENSORS_SCL3300))
+  /* MEMS chip select.  Also driven high with the SCL3300 so that the
+   * on-board LIS3DSH, which shares SPI1, never drives MISO.
+   */
+
+  stm32_configgpio(GPIO_CS_MEMS);
+#endif
+
+#if defined(CONFIG_STM32_SPI1) && defined(CONFIG_SENSORS_SCL3300)
+  stm32_configgpio(GPIO_SCL3300_CS);  /* SCL3300 chip select */
 #endif
 
 #if defined(CONFIG_STM32_SPI1) && defined(CONFIG_CL_MFRC522)
@@ -205,6 +214,13 @@ void stm32_spi1select(struct spi_dev_s *dev, uint32_t 
devid,
     }
 #endif
 
+#if defined(CONFIG_SENSORS_SCL3300)
+  if (devid == SPIDEV_ACCELEROMETER(SCL3300_DEVNO))
+    {
+      stm32_gpiowrite(GPIO_SCL3300_CS, !selected);
+    }
+#endif
+
 #if defined(CONFIG_CL_MFRC522)
   if (devid == SPIDEV_CONTACTLESS(0))
     {
diff --git a/boards/arm/stm32f4/stm32f4discovery/src/stm32f4discovery.h 
b/boards/arm/stm32f4/stm32f4discovery/src/stm32f4discovery.h
index 2989dc8bc33..c0f531409ad 100644
--- a/boards/arm/stm32f4/stm32f4discovery/src/stm32f4discovery.h
+++ b/boards/arm/stm32f4/stm32f4discovery/src/stm32f4discovery.h
@@ -303,6 +303,23 @@
 #define GPIO_CS_MFRC522      (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
                             GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN3)
 
+/* Murata SCL3300 inclinometer on SPI1 (PA5 SCK, PA6 MISO, PA7 MOSI) with
+ * chip select on PC4.  It uses SPIDEV_ACCELEROMETER(SCL3300_DEVNO) and
+ * the uORB topics sensor_inclinometer<SCL3300_DEVNO> and
+ * sensor_accel<SCL3300_DEVNO>.  Instance 0 belongs to the on-board MEMS
+ * (LIS3DSH) when its driver is enabled, so the SCL3300 moves to 1.
+ */
+
+#define GPIO_SCL3300_CS   (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
+                           GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN4)
+
+#if defined(CONFIG_SENSORS_LIS3MDL) || defined(CONFIG_SENSORS_LIS3DSH_UORB) || 
\
+    defined(CONFIG_LIS3DSH)
+#  define SCL3300_DEVNO   1
+#else
+#  define SCL3300_DEVNO   0
+#endif
+
 /* Use same pins as ENC28J60 to W5500 */
 
 #define GPIO_W5500_CS      (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\

Reply via email to