Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 5 months ago.
LocalFileSystem on NucleoSTM32F411RE
I want a local file system (like the one on LPC 1768) where I can write and read few key values onto the flash memory from my application using a config file on the nucleo STM32F401 or F411 boards.
Has anybody already have the LocalFileSystem supported on the nucleo F401/411 boards ? I already tried the example given here https://developer.mbed.org/handbook/LocalFileSystem#implementation-details
but it gives me compilation error for nucleo F411 platform.
If there is no support then what should be a possible approach on nucleo platforms where I can store and read values like we do using an EEPROM.
note: I cannot use any kind of external device like a pendrive or any external memory due to security.
Can LocalFileSystem be ported to Nucleo F411 platforms ? If yes what should be my approach to get it working on nucleo F401/F411 boards .
- yk
3 Answers
9 years, 5 months ago.
The localfile system is only available on the original mbed platforms (lpc11U24 and lpc1768). It is implemented as external EEPROM device connected to the socalled interface chip. That is the chip that also provides the drag-drop programming. There are some examples of code that uses an SD card as external filesystem. The alternative might be to use the internal flash of the processor (IAP) to store some values. Be aware that you dont write so often that this memory wears out and becomes unreliable.
9 years, 5 months ago.
LocalFileSystem then wouldn't have been suitable anyway since it uses an external storage chip.
You say you only need to read/write a few key values. What I once did for something like that was start with RAMDISK code: https://developer.mbed.org/users/samux/code/RAM_DISK/file/3d0c421fe52b/USBMSD_Ram.cpp (or here a similar one part of another lib: https://developer.mbed.org/users/Sissors/code/USBFileSystem_RAMDISK_HelloWorld/file/9261d5bd633b/RAM_DISK/USBMSD_Ram.cpp). Needs some minor modifications for latest USBDevice lib, but shouldn't be too bad.
Then what I did myself was keep the entire filesystem in flash (so simply not copy it to RAM, and only define it as constant). I only used a single file in a single sector (was just few key values), and for example the read code is:
int ConfigDisk::disk_read(uint8_t * data, uint64_t block, uint8_t count) { if (block < 4) memcpy(data, &disk[block*512], 512); else if (block == 4) createFile(data); else memset(data, 0, 512); return 0; }
The first 4 blocks were filesystem blocks which were defines in the flash. So if they were read, it would just copy from flash to the data block. The next block is the actual file, and all others just return zero. For writing only writing to block 4 (so 5th block) is accepted, all others are simply ignored.
Then createFile works like:
void ConfigDisk::createFile(uint8_t *data) { time_t seconds = clk.time(NULL); struct tm *curtime = localtime(&seconds); memset(data, 0, 512); data += sprintf((char*)data, "Tijd: %02d:%02d\r\n", curtime->tm_hour, curtime->tm_min); data += sprintf((char*)data, "Ochtend tijd: %02d:%02d\r\n", state.morningHours, state.morningMinutes); data += sprintf((char*)data, "Avond tijd: %02d:%02d\r\n", state.eveningHours, state.eveningMinutes); data += sprintf((char*)data, "Min temp: %2.1fC\r\n", state.minTemperature); data += sprintf((char*)data, "Max temp: %2.1fC\r\n", state.maxTemperature); }
Yeah it is dutch :P. What this does is it created a text file with the few key values, in human readable format.
Those key values you could for example store in your own flash using IAP. I had an RTC with battery backed-up RAM memory where I stored it.
Edit: This is assuming you also want it accessible via USB like LocalFileSystem. If not, well then there are alot easier options :P.
Hi Erik, thanks , but when you say" LocalFileSystem then wouldn't have been suitable anyway since it uses an external storage chip" , does it mean that LocalFileSystem uses some external flash chip and not the internal flash ROM of the controller. I believe the LocalFileSystem implemented for LPC1768 does not have any external storage chip , but has only 512KB internal Flash ROM, so it must be for internal Flash ROM.
-yk
posted by 15 Jul 2015