stm32f401rc-rs485: Add eeprom support
This commit is contained in:
parent
e0df6dd22e
commit
ce4c70690f
7 changed files with 216 additions and 10 deletions
|
|
@ -126,6 +126,31 @@ SDA PB7
|
|||
SCL PB8
|
||||
====== =====
|
||||
|
||||
Users can enable EERPOM support on STM32F4-RS485 by following below configuration:
|
||||
|
||||
- Configure basic nsh::
|
||||
|
||||
./tools/configure.sh -l stm32f401rc-rs485:nsh
|
||||
|
||||
- Enable the following configs::
|
||||
|
||||
CONFIG_DEV_ZERO=y
|
||||
CONFIG_EEPROM=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_I2C=y
|
||||
CONFIG_I2C_EE_24XX=y
|
||||
CONFIG_STM32_I2C1=y
|
||||
|
||||
- Build and flash the STM32F4-RS485.
|
||||
- Use dd command to write and read data from EEPROM as below::
|
||||
|
||||
nsh> dd if=/dev/zero of=/dev/eeprom
|
||||
nsh: dd: write failed: 1
|
||||
nsh> dd if=/dev/console of=/dev/eeprom bs=1 count=4
|
||||
(type "Hello")
|
||||
nsh> dd if=/dev/eeprom of=/dev/console bs=4 count=1
|
||||
Hellonsh>
|
||||
|
||||
Temperature Sensor
|
||||
==================
|
||||
|
||||
|
|
|
|||
|
|
@ -306,18 +306,10 @@ extern "C"
|
|||
*/
|
||||
|
||||
#define GPIO_I2C1_SCL GPIO_I2C1_SCL_2
|
||||
#define GPIO_I2C1_SDA GPIO_I2C1_SDA_2
|
||||
#define GPIO_I2C1_SCL_GPIO \
|
||||
(GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN8)
|
||||
#define GPIO_I2C1_SDA_GPIO \
|
||||
(GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN9)
|
||||
#define GPIO_I2C1_SDA GPIO_I2C1_SDA_1
|
||||
|
||||
#define GPIO_I2C2_SCL GPIO_I2C2_SCL_1
|
||||
#define GPIO_I2C2_SDA GPIO_I2C2_SDA_1
|
||||
#define GPIO_I2C2_SCL_GPIO \
|
||||
(GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN10)
|
||||
#define GPIO_I2C2_SDA_GPIO \
|
||||
(GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN11)
|
||||
#define GPIO_I2C2_SDA GPIO_I2C2_SDA_2
|
||||
|
||||
/* SPI
|
||||
*
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ if(CONFIG_STM32_SDIO)
|
|||
list(APPEND SRCS stm32_sdio.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_STM32_CONFIG_I2C_EE_24XXEEPROM)
|
||||
list(APPEND SRCS stm32_at24.c)
|
||||
endif()
|
||||
|
||||
target_sources(board PRIVATE ${SRCS})
|
||||
|
||||
if(CONFIG_ARCH_CHIP_STM32F401RC)
|
||||
|
|
|
|||
|
|
@ -43,6 +43,10 @@ ifeq ($(CONFIG_STM32_SDIO),y)
|
|||
CSRCS += stm32_sdio.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_I2C_EE_24XX),y)
|
||||
CSRCS += stm32_at24.c
|
||||
endif
|
||||
|
||||
DEPPATH += --dep-path board
|
||||
VPATH += :board
|
||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
|
||||
|
|
|
|||
95
boards/arm/stm32/stm32f401rc-rs485/src/stm32_at24.c
Normal file
95
boards/arm/stm32/stm32f401rc-rs485/src/stm32_at24.c
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/****************************************************************************
|
||||
* boards/arm/stm32/stm32f401rc-rs485/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 "stm32f401rc-rs485.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define AT24_I2C_BUS 1 /* EEPROM chip is configured to use I2C1 */
|
||||
|
||||
/****************************************************************************
|
||||
* 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, 0x50, path, EEPROM_AT24CM02, 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;
|
||||
}
|
||||
|
||||
|
|
@ -51,6 +51,59 @@
|
|||
* Public 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)
|
||||
{
|
||||
stm32_i2c_register(1);
|
||||
#if 0
|
||||
stm32_i2c_register(1);
|
||||
stm32_i2c_register(2);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
# define stm32_i2ctool()
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_bringup
|
||||
*
|
||||
|
|
@ -79,6 +132,19 @@ 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
|
||||
|
||||
#ifdef CONFIG_INPUT_BUTTONS
|
||||
/* Register the BUTTON driver */
|
||||
|
||||
|
|
|
|||
|
|
@ -346,4 +346,24 @@ int stm32_mcp2515initialize(const char *devpath);
|
|||
int stm32_sdio_initialize(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_i2cbus_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize one I2C bus
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct i2c_master_s *stm32_i2cbus_initialize(int port);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_at24_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the EEPROM for 24XX driver.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int stm32_at24_init(char *path);
|
||||
|
||||
#endif /* __BOARDS_ARM_STM32_STM32F401RC_RS485_SRC_STM32F401RC_RS485_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue