From 3a8c1cdccda70755ab52839adb5f869eae8564ba Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 1 Nov 2013 07:50:35 -0600 Subject: [PATCH] The Mikroe STM32 F4 board now uses /dev/config for configuration data storage. From Ken Pettit --- ChangeLog.txt | 3 +- platform/mikroe-stm32f4/Kconfig | 10 +--- platform/mikroe-stm32f4/mikroe_configdata.c | 66 +++++++++++++++++++-- 3 files changed, 63 insertions(+), 16 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 949ae7414..4c831693a 100644 --- a/ChangeLog.txt +++ b/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/platform/mikroe-stm32f4/Kconfig b/platform/mikroe-stm32f4/Kconfig index 55a1475bd..a26765ccf 100644 --- a/platform/mikroe-stm32f4/Kconfig +++ b/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/platform/mikroe-stm32f4/mikroe_configdata.c b/platform/mikroe-stm32f4/mikroe_configdata.c index 5147a95c9..957bc0985 100644 --- a/platform/mikroe-stm32f4/mikroe_configdata.c +++ b/platform/mikroe-stm32f4/mikroe_configdata.c @@ -46,6 +46,8 @@ #include #include +#include +#include #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;