From 20c11e918f2da048c12c765d625ed5bccd2afdad Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sat, 6 Jan 2018 17:10:32 -0600 Subject: [PATCH] configs/stm32f103-minimum: Add AT24 EEPROM support on STM32F103-Minimum board --- configs/stm32f103-minimum/Kconfig | 30 +++++++++++++++ configs/stm32f103-minimum/src/Makefile | 6 +++ configs/stm32f103-minimum/src/stm32_bringup.c | 11 ++++++ .../stm32f103-minimum/src/stm32f103_minimum.h | 37 +++++++++++++++++++ 4 files changed, 84 insertions(+) diff --git a/configs/stm32f103-minimum/Kconfig b/configs/stm32f103-minimum/Kconfig index 9771d9e76b..c96e8902fc 100644 --- a/configs/stm32f103-minimum/Kconfig +++ b/configs/stm32f103-minimum/Kconfig @@ -5,6 +5,36 @@ if ARCH_BOARD_STM32F103_MINIMUM +config STM32F103MINIMUM_AT24_BLOCKMOUNT + bool "AT24 Serial EEPROM auto-mount" + default n + depends on NSH_ARCHINIT && STM32_I2C1 && MTD_AT24XX + ---help--- + Automatically initialize the AT24 I2C EEPROM driver when NSH starts. + +choice + prompt "AT24 serial EPPROM configuration" + default STM32F103MINIMUM_AT24_FTL + depends on STM32F103MINIMUM_AT24_BLOCKMOUNT + +config STM32F103MINIMUM_AT24_FTL + bool "Create AT24 block driver" + ---help--- + Create the MTD driver for the AT24 and "wrap" the AT24 as a standard + block driver that could then, for example, be mounted using FAT or + any other file system. Any file system may be used, but there will + be no wear-leveling. + +config STM32F103MINIMUM_AT24_NXFFS + bool "Create AT24 NXFFS file system" + depends on FS_NXFFS + ---help--- + Create the MTD driver for the AT24 and mount the AT24 device as + a wear-leveling, NuttX FLASH file system (NXFFS). The downside of + NXFFS is that it can be very slow. + +endchoice # AT24 serial EPPROM configuration + config STM32F103MINIMUM_FLASH bool "MTD driver for external 4Mbyte W25Q32FV FLASH on SPI1" default n diff --git a/configs/stm32f103-minimum/src/Makefile b/configs/stm32f103-minimum/src/Makefile index 0784c5b21b..d2a4afcfbe 100644 --- a/configs/stm32f103-minimum/src/Makefile +++ b/configs/stm32f103-minimum/src/Makefile @@ -85,6 +85,12 @@ ifeq ($(CONFIG_MTD_W25),y) CSRCS += stm32_w25.c endif +ifeq ($(CONFIG_MTD_AT24XX),y) +ifeq ($(CONFIG_STM32_I2C1),y) +CSRCS += stm32_at24.c +endif +endif + ifeq ($(CONFIG_AUDIO_TONE),y) CSRCS += stm32_tone.c endif diff --git a/configs/stm32f103-minimum/src/stm32_bringup.c b/configs/stm32f103-minimum/src/stm32_bringup.c index b41282ceb2..dec8bea5e1 100644 --- a/configs/stm32f103-minimum/src/stm32_bringup.c +++ b/configs/stm32f103-minimum/src/stm32_bringup.c @@ -188,6 +188,17 @@ int stm32_bringup(void) } #endif +#ifdef HAVE_AT24 + /* Initialize the AT24 driver */ + + ret = stm32_at24_automount(AT24_MINOR); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_at24_automount failed: %d\n", ret); + return ret; + } +#endif /* HAVE_AT24 */ + #ifdef CONFIG_PWM /* Initialize PWM and register the PWM device. */ diff --git a/configs/stm32f103-minimum/src/stm32f103_minimum.h b/configs/stm32f103-minimum/src/stm32f103_minimum.h index 88a5f701cf..17db4be949 100644 --- a/configs/stm32f103-minimum/src/stm32f103_minimum.h +++ b/configs/stm32f103-minimum/src/stm32f103_minimum.h @@ -44,6 +44,43 @@ #include #include +#define HAVE_AT24 1 + +/* AT24 Serial EEPROM */ + +#define AT24_I2C_BUS 1 /* AT24C256 connected to I2C1 */ +#define AT24_MINOR 0 + +#if !defined(CONFIG_MTD_AT24XX) || !defined(CONFIG_STM32_I2C1) +# undef HAVE_AT24 +#endif + +/* Can't support AT24 features if mountpoints are disabled or if we were not + * asked to mount the AT25 part + */ + +#if defined(CONFIG_DISABLE_MOUNTPOINT) || \ + !defined(CONFIG_STM32F103MINIMUM_AT24_BLOCKMOUNT) +# undef HAVE_AT24 +#endif + +/* If we are going to mount the AT24, then they user must also have told + * us what to do with it by setting one of these. + */ + +#ifndef CONFIG_FS_NXFFS +# undef CONFIG_STM32F103MINIMUM_AT24_NXFFS +#endif + +#if !defined(CONFIG_STM32F103MINIMUM_AT24_FTL) && \ + !defined(CONFIG_STM32F103MINIMUM_AT24_NXFFS) +# undef HAVE_AT24 +#endif + +#ifndef HAVE_AT24 +#error "HAVE_AT24 is not defined!\n" +#endif + /************************************************************************************ * Pre-processor Definitions ************************************************************************************/