summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-11-01 07:50:35 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-11-01 07:50:35 -0600
commit9741311259ee5434987dc8c9918f29e355d22c4f (patch)
treedfee89d28f7e4e17937f0d047ec69f8be4d44998
parent8d05d097e7089f3a4ce15e29cf3b7701580665b2 (diff)
downloadnuttx-9741311259ee5434987dc8c9918f29e355d22c4f.tar.gz
nuttx-9741311259ee5434987dc8c9918f29e355d22c4f.tar.bz2
nuttx-9741311259ee5434987dc8c9918f29e355d22c4f.zip
The Mikroe STM32 F4 board now uses /dev/config for configuration data storage. From Ken Pettit
-rw-r--r--apps/ChangeLog.txt3
-rw-r--r--apps/platform/mikroe-stm32f4/Kconfig10
-rw-r--r--apps/platform/mikroe-stm32f4/mikroe_configdata.c66
-rw-r--r--nuttx/ChangeLog2
-rw-r--r--nuttx/configs/mikroe-stm32f4/Kconfig46
-rw-r--r--nuttx/configs/mikroe-stm32f4/src/up_nsh.c41
6 files changed, 127 insertions, 41 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index 949ae7414..4c831693a 100644
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -718,4 +718,5 @@
data. From Ken Pettit (2013-10-30).
* apps/nshlib/nsh_dbgcmds.c and others: Add skip= and count=
options to the hexdump command. From Ken Pettit (2013-11-1).
-
+ * apps/platrorm/mikroe-stm32f4: Now uses /dev/config for configuration
+ data storage. From Ken Pettit (2013-11-1).
diff --git a/apps/platform/mikroe-stm32f4/Kconfig b/apps/platform/mikroe-stm32f4/Kconfig
index 55a1475bd..a26765ccf 100644
--- a/apps/platform/mikroe-stm32f4/Kconfig
+++ b/apps/platform/mikroe-stm32f4/Kconfig
@@ -12,7 +12,7 @@ choice
default MIKROE_STM32F4_CONFIGDATA_PART
config MIKROE_STM32F4_CONFIGDATA_PART
- bool "Dedicated FLASH partition"
+ bool "Dedicated FLASH partition using /dev/config"
config MIKROE_STM32F4_CONFIGDATA_FS
bool "File system file"
@@ -32,14 +32,6 @@ config MIKROE_STM32F4_CONFIGDATA_FILENAME
endif
-if MIKROE_STM32F4_CONFIGDATA_PART
-
-config MIKROE_STM32F4_CONFIGDATA_PART_SIZE
- int "Size (in erase blocks) of configuration data partition"
- default 2
-
-endif
-
endif
endif
diff --git a/apps/platform/mikroe-stm32f4/mikroe_configdata.c b/apps/platform/mikroe-stm32f4/mikroe_configdata.c
index 5147a95c9..957bc0985 100644
--- a/apps/platform/mikroe-stm32f4/mikroe_configdata.c
+++ b/apps/platform/mikroe-stm32f4/mikroe_configdata.c
@@ -46,6 +46,8 @@
#include <debug.h>
#include <apps/platform/configdata.h>
+#include <nuttx/fs/ioctl.h>
+#include <nuttx/configdata.h>
#ifdef CONFIG_PLATFORM_CONFIGDATA
@@ -108,6 +110,11 @@ int platform_setconfig(enum config_data_e id, int instance,
#ifdef CONFIG_MIKROE_STM32F4_CONFIGDATA_FS
FILE* fd;
#endif
+#if CONFIG_MIKROE_STM32F4_CONFIGDATA_PART
+ struct config_data_s config;
+ int ret;
+ int fd;
+#endif
switch (id)
{
@@ -137,9 +144,29 @@ int platform_setconfig(enum config_data_e id, int instance,
fclose(fd);
return OK;
-#elif CONFIG_MIKROE_STM32F4_CONFIGDATA_PART
-# error This configuration not supported yet!
-#elif CONFIG_MIKROE_STM32F4_CONFIGDATA_ROM
+#elif CONFIG_MIKROE_STM32F4_CONFIGDATA_PART
+
+ /* Try to open the /dev/config device file */
+
+ if ((fd = open("/dev/config", O_RDOK)) == -1)
+ {
+ /* Error opening the config device */
+
+ return -1;
+ }
+
+ /* Setup structure for the SETCONFIG ioctl */
+
+ config.id = (enum config_data_e)id;
+ config.instance = instance;
+ config.configdata = (FAR uint8_t *) configdata;
+ config.len = datalen;
+
+ ret = ioctl(fd, CFGDIOC_SETCONFIG, (unsigned long) &config);
+ close(fd);
+ return ret;
+
+#elif CONFIG_MIKROE_STM32F4_CONFIGDATA_ROM
/* We are reading from a read-only system, so nothing to do. */
@@ -194,12 +221,17 @@ int platform_getconfig(enum config_data_e id, int instance,
size_t bytes;
enum config_data_e saved_id;
int saved_instance;
-#elif CONFIG_MIKROE_STM32F4_CONFIGDATA_ROM
+#elif CONFIG_MIKROE_STM32F4_CONFIGDATA_ROM
static const uint8_t touch_cal_data[] = {
- 0x9a, 0x2f, 0x00, 0x00,
+ 0x9a, 0x2f, 0x00, 0x00,
0x40, 0xbc, 0x69, 0xfe, 0x70, 0x2e, 0x00,
0x00, 0xb8, 0x2d, 0xdb, 0xff };
#endif
+#if CONFIG_MIKROE_STM32F4_CONFIGDATA_PART
+ struct config_data_s config;
+ int ret;
+ int fd;
+#endif
switch (id)
{
@@ -240,7 +272,29 @@ int platform_getconfig(enum config_data_e id, int instance,
return OK;
-#elif CONFIG_MIKROE_STM32F4_CONFIGDATA_ROM
+#elif CONFIG_MIKROE_STM32F4_CONFIGDATA_PART
+
+ /* Try to open the /dev/config device file */
+
+ if ((fd = open("/dev/config", O_RDOK)) == -1)
+ {
+ /* Error opening the config device */
+
+ return -1;
+ }
+
+ /* Setup structure for the SETCONFIG ioctl */
+
+ config.id = (enum config_data_e)id;
+ config.instance = instance;
+ config.configdata = configdata;
+ config.len = datalen;
+
+ ret = ioctl(fd, CFGDIOC_GETCONFIG, (unsigned long) &config);
+ close(fd);
+ return ret;
+
+#elif CONFIG_MIKROE_STM32F4_CONFIGDATA_ROM
memcpy(configdata, touch_cal_data, datalen);
return OK;
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index f88f6a9be..474c696d2 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -5928,3 +5928,5 @@
for an MTD device that can be used to provide a simple, lightweight
interface to configation data storage that resides on some storage
media that is wrapped as an MTD device. From Ken Pettit (2013-11-1).
+ * configs/mikroe-stm32f4: Now uses /dev/config for configuration data
+ storage. From Ken Pettit (2013-11-1).
diff --git a/nuttx/configs/mikroe-stm32f4/Kconfig b/nuttx/configs/mikroe-stm32f4/Kconfig
index 0790f123a..1b936cc4f 100644
--- a/nuttx/configs/mikroe-stm32f4/Kconfig
+++ b/nuttx/configs/mikroe-stm32f4/Kconfig
@@ -8,55 +8,71 @@ if ARCH_BOARD_MIKROE_STM32F4
config MIKROE_FLASH
bool "MTD driver for onboard 1M FLASH"
default n
- select MTD
- select MTD_M25P
- select MTD_SMART
- select FS_SMARTFS
- select STM32_SPI3
- select MTD_BYTE_WRITE
+ select MTD
+ select MTD_M25P
+ select MTD_SMART
+ select FS_SMARTFS
+ select STM32_SPI3
+ select MTD_BYTE_WRITE
---help---
Configures an MTD device for use with the onboard flash
config MIKROE_FLASH_MINOR
int "Minor number for the FLASH /dev/smart entry"
default 0
- depends on MIKROE_FLASH
+ depends on MIKROE_FLASH
---help---
Sets the minor number for the FLASH MTD /dev entry
config MIKROE_FLASH_PART
bool "Enable partition support on FLASH"
default n
- depends on MIKROE_FLASH
+ depends on MIKROE_FLASH
---help---
Enables creation of partitions on the FLASH
+config MIKROE_FLASH_CONFIG_PART
+ bool "Create application config data partition on FLASH"
+ default y
+ depends on MIKROE_FLASH_PART
+ depends on PLATFORM_CONFIGDATA
+ ---help---
+ Enables creation of a /dev/config partition on the FLASH
+
+config MIKROE_FLASH_CONFIG_PART_NUMBER
+ int "Index number of config partition (in list below)"
+ default 0
+ depends on MIKROE_FLASH_CONFIG_PART
+ ---help---
+ Specifies the index number of the config data partition
+ from the partition list.
+
config MIKROE_FLASH_PART_LIST
string "Flash partition size list"
- default "256,768"
- depends on MIKROE_FLASH_PART
+ default "8,248,768"
+ depends on MIKROE_FLASH_PART
---help---
- Comma separated list of partition sizes in KB
+ Comma separated list of partition sizes in KB.
config MIKROE_RAMMTD
bool "MTD driver for SMARTFS RAM disk"
default n
- select MTD
- select RAMMTD
+ select MTD
+ select RAMMTD
---help---
Configures an MTD based RAM device for use with SMARTFS.
config MIKROE_RAMMTD_MINOR
int "Minor number for RAM /dev/smart entry"
default 1
- depends on MIKROE_RAMMTD
+ depends on MIKROE_RAMMTD
---help---
Sets the minor number for the RAM MTD /dev entry
config MIKROE_RAMMTD_SIZE
int "Size in KB of the RAM device to create"
default 32
- depends on MIKROE_RAMMTD
+ depends on MIKROE_RAMMTD
---help---
Sets the size of static RAM allocation for the SMART RAM device
diff --git a/nuttx/configs/mikroe-stm32f4/src/up_nsh.c b/nuttx/configs/mikroe-stm32f4/src/up_nsh.c
index 366e4e8f6..cfb41a283 100644
--- a/nuttx/configs/mikroe-stm32f4/src/up_nsh.c
+++ b/nuttx/configs/mikroe-stm32f4/src/up_nsh.c
@@ -59,6 +59,12 @@
# include <apps/usbmonitor.h>
#endif
+#ifdef CONFIG_MIKROE_FLASH_CONFIG_PART
+#ifdef CONFIG_PLATFORM_CONFIGDATA
+# include <nuttx/configdata.h>
+#endif
+#endif
+
#ifdef CONFIG_STM32_OTGFS
# include "stm32_usbhost.h"
#endif
@@ -227,6 +233,7 @@ int nsh_archinitialize(void)
partno = 0;
ptr = partstring;
partoffset = 0;
+
while (*ptr != '\0')
{
/* Get the partition size */
@@ -235,12 +242,27 @@ int nsh_archinitialize(void)
mtd_part = mtd_partition(mtd, partoffset, (partsize>>2)*16);
partoffset += (partsize >> 2) * 16;
- /* Now initialize a SMART Flash block device and bind it to the MTD device */
+#ifdef CONFIG_MIKROE_FLASH_CONFIG_PART
+ /* Test if this is the config partition */
+
+ if (CONFIG_MIKROE_FLASH_CONFIG_PART_NUMBER == partno)
+ {
+ /* Register the partition as the config device */
+
+ mtdconfig_register(mtd_part);
+ }
+ else
+#endif
+ {
+ /* Now initialize a SMART Flash block device and bind it
+ * to the MTD device.
+ */
#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
- sprintf(partname, "p%d", partno);
- smart_initialize(CONFIG_MIKROE_FLASH_MINOR, mtd_part, partname);
+ sprintf(partname, "p%d", partno);
+ smart_initialize(CONFIG_MIKROE_FLASH_MINOR, mtd_part, partname);
#endif
+ }
/* Update the pointer to point to the next size in the list */
@@ -258,7 +280,6 @@ int nsh_archinitialize(void)
partno++;
}
- }
#else /* CONFIG_MIKROE_FLASH_PART */
/* Configure the device with no partition support */
@@ -266,20 +287,21 @@ int nsh_archinitialize(void)
smart_initialize(CONFIG_MIKROE_FLASH_MINOR, mtd, NULL);
#endif /* CONFIG_MIKROE_FLASH_PART */
+ }
}
/* Create a RAM MTD device if configured */
#if defined(CONFIG_RAMMTD) && defined(CONFIG_MIKROE_RAMMTD)
{
- uint8_t *start = (uint8_t *) kmalloc(CONFIG_MIKROE_RAMMTD_SIZE * 1024);
- mtd = rammtd_initialize(start, CONFIG_MIKROE_RAMMTD_SIZE * 1024);
- mtd->ioctl(mtd, MTDIOC_BULKERASE, 0);
+ uint8_t *start = (uint8_t *) kmalloc(CONFIG_MIKROE_RAMMTD_SIZE * 1024);
+ mtd = rammtd_initialize(start, CONFIG_MIKROE_RAMMTD_SIZE * 1024);
+ mtd->ioctl(mtd, MTDIOC_BULKERASE, 0);
- /* Now initialize a SMART Flash block device and bind it to the MTD device */
+ /* Now initialize a SMART Flash block device and bind it to the MTD device */
#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
- smart_initialize(CONFIG_MIKROE_RAMMTD_MINOR, mtd, NULL);
+ smart_initialize(CONFIG_MIKROE_RAMMTD_MINOR, mtd, NULL);
#endif
}
@@ -308,7 +330,6 @@ int nsh_archinitialize(void)
else
{
message("nsh_archinitialize: Successfully bound SPI to the MMC/SD driver\n");
-
}
#endif