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

xiaoxiang 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 4b5ad956c3 stm32h7/linum-stm32h753bi: Add support to eeprom using the 
i2c3
4b5ad956c3 is described below

commit 4b5ad956c35948fb552c04aea46c991dd0f28560
Author: Jorge Guzman <[email protected]>
AuthorDate: Tue Mar 5 23:35:34 2024 -0300

    stm32h7/linum-stm32h753bi: Add support to eeprom using the i2c3
    
    Signed-off-by: Jorge Guzman <[email protected]>
---
 .../arm/stm32h7/boards/linum-stm32h753bi/index.rst | 13 ++-
 .../linum-stm32h753bi/configs/eeprom/defconfig     | 60 ++++++++++++++
 .../arm/stm32h7/linum-stm32h753bi/include/board.h  | 26 +++---
 .../stm32h7/linum-stm32h753bi/src/CMakeLists.txt   |  4 +
 boards/arm/stm32h7/linum-stm32h753bi/src/Makefile  |  4 +
 .../linum-stm32h753bi/src/linum-stm32h753bi.h      | 12 +++
 .../arm/stm32h7/linum-stm32h753bi/src/stm32_at24.c | 96 ++++++++++++++++++++++
 .../stm32h7/linum-stm32h753bi/src/stm32_bringup.c  | 66 +++++++++++++++
 drivers/eeprom/i2c_xx24xx.c                        |  2 +-
 9 files changed, 267 insertions(+), 16 deletions(-)

diff --git 
a/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst 
b/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst
index f68cbe4642..76181522b7 100644
--- a/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst
+++ b/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst
@@ -225,7 +225,7 @@ The LINUM-STM32H753BI connects the EEPROM memory and the 
touchscreen sensor to I
 EEPROM MEMORY
 --------------
 
-EEPROM memory used is the 24LC256 with 256Kb.
+EEPROM memory used is the 24LC256 with 256Kb with the control bytes value 0x54.
 
 TOUCHSCREEN SENSOR
 ------------------
@@ -447,3 +447,14 @@ The SD card can then be mounted by the NSH commands::
     test_file.txt
     nsh> cat /mnt/test_file.txt
     Hello World!!
+
+eeprom
+------
+
+Use dd command to write and read data from EEPROM as below:::
+
+    nsh> dd if=/dev/console of=/dev/eeprom bs=1 count=35
+    Witte-Tech Linum-STM32H753BI board
+    nsh> dd if=/dev/eeprom of=/dev/console bs=4 count=35
+    Witte-Tech Linum-STM32H753BI board
+    nsh> 
\ No newline at end of file
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/configs/eeprom/defconfig 
b/boards/arm/stm32h7/linum-stm32h753bi/configs/eeprom/defconfig
new file mode 100644
index 0000000000..8b7973c831
--- /dev/null
+++ b/boards/arm/stm32h7/linum-stm32h753bi/configs/eeprom/defconfig
@@ -0,0 +1,60 @@
+#
+# 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_STANDARD_SERIAL is not set
+# CONFIG_STM32H7_USE_LEGACY_PINMAP is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="linum-stm32h753bi"
+CONFIG_ARCH_BOARD_LINUM_STM32H753BI=y
+CONFIG_ARCH_CHIP="stm32h7"
+CONFIG_ARCH_CHIP_STM32H753BI=y
+CONFIG_ARCH_CHIP_STM32H7=y
+CONFIG_ARCH_CHIP_STM32H7_CORTEXM7=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV7M_DCACHE=y
+CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y
+CONFIG_ARMV7M_DTCM=y
+CONFIG_ARMV7M_ICACHE=y
+CONFIG_BOARD_LOOPSPERMSEC=43103
+CONFIG_BUILTIN=y
+CONFIG_DEBUG_FEATURES=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DEV_ZERO=y
+CONFIG_EEPROM=y
+CONFIG_EXAMPLES_ALARM=y
+CONFIG_FS_PROCFS=y
+CONFIG_I2C=y
+CONFIG_I2C_EE_24XX=y
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INTELHEX_BINARY=y
+CONFIG_LIBM=y
+CONFIG_MM_REGIONS=4
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_DISABLE_IFUPDOWN=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_LINELEN=64
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=245760
+CONFIG_RAM_START=0x20010000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_RTC_ALARM=y
+CONFIG_RTC_DATETIME=y
+CONFIG_RTC_DRIVER=y
+CONFIG_SCHED_WAITPID=y
+CONFIG_START_DAY=6
+CONFIG_START_MONTH=12
+CONFIG_START_YEAR=2011
+CONFIG_STM32H7_I2C3=y
+CONFIG_STM32H7_PWR=y
+CONFIG_STM32H7_RTC=y
+CONFIG_STM32H7_USART1=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_TASK_NAME_SIZE=0
+CONFIG_USART1_SERIAL_CONSOLE=y
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/include/board.h 
b/boards/arm/stm32h7/linum-stm32h753bi/include/board.h
index 7471a016f9..aef2924950 100644
--- a/boards/arm/stm32h7/linum-stm32h753bi/include/board.h
+++ b/boards/arm/stm32h7/linum-stm32h753bi/include/board.h
@@ -382,21 +382,19 @@
 #define GPIO_OTGFS_DM  (GPIO_OTGFS_DM_0  | GPIO_SPEED_100MHz)
 #define GPIO_OTGFS_DP  (GPIO_OTGFS_DP_0  | GPIO_SPEED_100MHz)
 
-/* SDMMC1 Pin mapping
- * CLK - PC12
- * CMD - PD2
- *  D0 - PC8
- *  D1 - PC9
- *  D2 - PC10
- *  D3 - PC11
- */
+/* SDMMC1 - Used SD Card memory */
+
+#define GPIO_SDMMC1_CK   (GPIO_SDMMC1_CK_0  | GPIO_SPEED_100MHz) /* PC12 */
+#define GPIO_SDMMC1_CMD  (GPIO_SDMMC1_CMD_0 | GPIO_SPEED_100MHz) /* PD2 */
+#define GPIO_SDMMC1_D0   (GPIO_SDMMC1_D0_0  | GPIO_SPEED_100MHz) /* PC8 */
+#define GPIO_SDMMC1_D1   (GPIO_SDMMC1_D1_0  | GPIO_SPEED_100MHz) /* PC9 */
+#define GPIO_SDMMC1_D2   (GPIO_SDMMC1_D2_0  | GPIO_SPEED_100MHz) /* PC10 */
+#define GPIO_SDMMC1_D3   (GPIO_SDMMC1_D3_0  | GPIO_SPEED_100MHz) /* PC11 */
+
+/* I2C3 - Used by eeprom memory */
 
-#define GPIO_SDMMC1_CK   (GPIO_SDMMC1_CK_0  | GPIO_SPEED_100MHz)
-#define GPIO_SDMMC1_CMD  (GPIO_SDMMC1_CMD_0 | GPIO_SPEED_100MHz)
-#define GPIO_SDMMC1_D0   (GPIO_SDMMC1_D0_0  | GPIO_SPEED_100MHz)
-#define GPIO_SDMMC1_D1   (GPIO_SDMMC1_D1_0  | GPIO_SPEED_100MHz)
-#define GPIO_SDMMC1_D2   (GPIO_SDMMC1_D2_0  | GPIO_SPEED_100MHz)
-#define GPIO_SDMMC1_D3   (GPIO_SDMMC1_D3_0  | GPIO_SPEED_100MHz)
+#define GPIO_I2C3_SCL (GPIO_I2C3_SCL_2 | GPIO_SPEED_100MHz) /* PH7 */
+#define GPIO_I2C3_SDA (GPIO_I2C3_SDA_2 | GPIO_SPEED_100MHz) /* PH8 */
 
 /****************************************************************************
  * Public Data
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/CMakeLists.txt 
b/boards/arm/stm32h7/linum-stm32h753bi/src/CMakeLists.txt
index ede0805ab5..eaf07d1b28 100644
--- a/boards/arm/stm32h7/linum-stm32h753bi/src/CMakeLists.txt
+++ b/boards/arm/stm32h7/linum-stm32h753bi/src/CMakeLists.txt
@@ -44,6 +44,10 @@ if(CONFIG_FAT_DMAMEMORY)
   list(APPEND SRCS stm32_dma_alloc.c)
 endif()
 
+if(CONFIG_I2C_EE_24XX)
+  list(APPEND SRCS stm32_at24.c)
+endif()
+
 target_sources(board PRIVATE ${SRCS})
 
 set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/Makefile 
b/boards/arm/stm32h7/linum-stm32h753bi/src/Makefile
index e251e13a8b..e745de7f75 100644
--- a/boards/arm/stm32h7/linum-stm32h753bi/src/Makefile
+++ b/boards/arm/stm32h7/linum-stm32h753bi/src/Makefile
@@ -42,6 +42,10 @@ ifeq ($(CONFIG_FAT_DMAMEMORY),y)
 CSRCS += stm32_dma_alloc.c
 endif
 
+ifeq ($(CONFIG_I2C_EE_24XX),y)
+CSRCS += stm32_at24.c
+endif
+
 ifeq ($(CONFIG_BOARDCTL),y)
 CSRCS += stm32_appinitialize.c
 endif
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/linum-stm32h753bi.h 
b/boards/arm/stm32h7/linum-stm32h753bi/src/linum-stm32h753bi.h
index cfb6a69cdb..697e6c645f 100644
--- a/boards/arm/stm32h7/linum-stm32h753bi/src/linum-stm32h753bi.h
+++ b/boards/arm/stm32h7/linum-stm32h753bi/src/linum-stm32h753bi.h
@@ -160,4 +160,16 @@ int stm32_dma_alloc_init(void);
 int stm32_sdio_initialize(void);
 #endif
 
+/****************************************************************************
+ * Name: stm32_at24_init
+ *
+ * Description:
+ *   Initialize and register the EEPROM for 24XX  driver.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_I2C_EE_24XX
+int stm32_at24_init(char *path);
+#endif
+
 #endif /* __BOARDS_ARM_STM32H7_LINUM_STM32H753BI_SRC_LINUM_STM32H753BI_H */
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_at24.c 
b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_at24.c
new file mode 100644
index 0000000000..0558479a01
--- /dev/null
+++ b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_at24.c
@@ -0,0 +1,96 @@
+/****************************************************************************
+ * boards/arm/stm32h7/linum-stm32h753bi/src/stm32_at24.c
+ *
+ * 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 <sys/mount.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/i2c/i2c_master.h>
+#include <nuttx/eeprom/i2c_xx24xx.h>
+#include "stm32_i2c.h"
+
+#include "linum-stm32h753bi.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define AT24_I2C_BUS     3  /* EEPROM chip is configured to use I2C3 */
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_at24_init
+ *
+ * Description:
+ *   Initialize and configure the AT24 serial EEPROM
+ *
+ ****************************************************************************/
+
+int stm32_at24_init(char *path)
+{
+  FAR struct i2c_master_s *i2c;
+  static bool initialized = false;
+  int ret;
+
+  /* Have we already initialized? */
+
+  if (!initialized)
+    {
+      /* No.. Get the I2C bus driver */
+
+      finfo("Initialize I2C%d\n", AT24_I2C_BUS);
+      i2c = stm32_i2cbus_initialize(AT24_I2C_BUS);
+      if (!i2c)
+        {
+          ferr("ERROR: Failed to initialize I2C%d\n", AT24_I2C_BUS);
+          return -ENODEV;
+        }
+
+      /* Now bind the I2C interface to the AT24 I2C EEPROM driver */
+
+      finfo("Bind the AT24 EEPROM driver to I2C%d\n", AT24_I2C_BUS);
+      ret = ee24xx_initialize(i2c, 0x54, path, EEPROM_24XX256, false);
+      if (ret < 0)
+        {
+          ferr("ERROR: Failed to bind I2C%d to the AT24 EEPROM driver\n",
+               AT24_I2C_BUS);
+          return -ENODEV;
+        }
+
+      /* Now we are initialized */
+
+      initialized = true;
+    }
+
+  return OK;
+}
+
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c 
b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c
index a36ee12d19..0fc5f6ee3f 100644
--- a/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c
+++ b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c
@@ -32,6 +32,7 @@
 #include <nuttx/kmalloc.h>
 
 #include "stm32_gpio.h"
+#include "stm32_i2c.h"
 
 #include "linum-stm32h753bi.h"
 
@@ -48,6 +49,58 @@
  * 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_STM32H7_I2C3
+  stm32_i2c_register(3);
+#endif
+#ifdef CONFIG_STM32H7_I2C4
+  stm32_i2c_register(4);
+#endif
+}
+#endif
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -142,5 +195,18 @@ int stm32_bringup(void)
     }
 #endif
 
+#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
+  stm32_i2ctool();
+#endif
+
+#ifdef CONFIG_I2C_EE_24XX
+  ret = stm32_at24_init("/dev/eeprom");
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "Failed to initialize EEPROM HX24LCXXB: %d\n", ret);
+      return ret;
+    }
+#endif
+
   return OK;
 }
diff --git a/drivers/eeprom/i2c_xx24xx.c b/drivers/eeprom/i2c_xx24xx.c
index 722cfe5afb..959545da86 100644
--- a/drivers/eeprom/i2c_xx24xx.c
+++ b/drivers/eeprom/i2c_xx24xx.c
@@ -873,7 +873,7 @@ int ee24xx_initialize(FAR struct i2c_master_s *bus, uint8_t 
devaddr,
         }
     }
 
-  finfo("EEPROM device %s, %d bytes, %d per page, addrlen %d, %s\n",
+  finfo("EEPROM device %s, %" PRIu32 " bytes, %d per page, addrlen %d, %s\n",
         devname, eedev->size, eedev->pgsize, eedev->addrlen,
         eedev->readonly ? "readonly" : "");
 

Reply via email to