1 week, 2 days ago.

Is it possible to read a small text file which is on the mass storage device shared with the PC?

I am a noobie to Mbed, but not embedded programming, so please excuse the question if it has an answer which is obvious to those in the know.

I would like to have a small text file on the USB mass storage device that is shared with the PC that carries a few configuration parameters (IP address, port number and maybe a few other options) which will be read once on program startup. These will then be used to configure the functionality of the program running on the Mbed. Ideally this file should be non-volatile and should persist on the Mbed, even when the PC has been unplugged and then be changeable from the PC once the Mbed is plugged back into it.

Is this possible and how would I go about it?

Many thanks.

Comment on this question

1 Answer

1 week, 1 day ago.

Hello Paul,

As far as I know the only USB mass storage device that can be shared with the PC is the LocalFileSystem. It's a file system that connects to the Mbed board's interface chip if the interface chip has built-in storage. The LocalFileSystem meets all your requirements but it is only available on the LPC1768 and LPC11U24 boards:

  • The text file located on the LocalFileSystem can be edited from the PC
  • Data from the text file can be read during Mbed's program startup
  • The file is non-volatile (persists on the Mbed even when the Mbed has been powered off).

A quick test:

  • Connect your LPC1768 over USB to the PC.
  • Create a new "config.txt" file on the MBED disk with your favourite text editor and save it.
  • The following Mbed program will print the content of the "config.txt" file to the serial monitor.

#include "mbed.h"

LocalFileSystem fs("local");

int main()
    printf("Opening file 'config.txt'... ");    
    FILE*   fp = fopen("/local/config.txt", "r");  
    printf("%s\n", (!fp ? "Fail :(" : "OK"));
    if (!fp)
        error("error: %s (%d)\n", strerror(errno), -errno);
    while (!feof(fp)) {
        int c = fgetc(fp);
        printf("%c", c);

Thanks so much for your answer. It explains a lot. I had come across the LocalFileSystem which seemed to be a possible solution, but, despite my prototyping code being syntactically the same as your example, it would fail to compile on the line where I instantiated it. However, I am using an Embedded Artists LPC4088 Mbed module so that is the reason!

I will get an LPC1768 module and repeat my tests. Thank you once again - with helpful responses like yours I can see that I am going to enjoy working with Mbed.

posted by Paul Maisey 10 Nov 2018

To post an answer, please log in.