6 years ago.

USBHost on application board mbed-os

Hi. I am trying to write a CSV file to a USB flash stick. I'm using the application board:

https://os.mbed.com/cookbook/mbed-application-board

With mbed-os I cannot find any examples to work on. Anyone who have experienced the same difficulties ?

Any help is much appreciated.

Regards Mustafa Kazaale

1 Answer

6 years ago.

Hi there,

The following code utilizes the LocalFileSystem library (make sure to import the "mbed-os" library into your project with the following URL: https://github.com/armmbed/mbed-os):

#include "mbed.h"

LocalFileSystem local("local");
DigitalOut led(LED1);
AnalogIn pot1(p19);

int main()
{
    FILE *fp = fopen("/local/test.csv","w");
    printf("Create file handle for test.csv\r\n");

    printf("Writing to file\r\n");
    for (int i = 0; i < 100; i++) {
        float val = pot1.read();
        fprintf(fp,"%.2f\n", val);
    }
    
    fclose(fp);
    printf("Close the handle\r\n");
    led=1;
}

For USBHost I would take a look at this program: https://os.mbed.com/users/vinit/code/SD-to-Flash-Data-Transfer/file/5838d8c4432a/main.cpp/

Please let me know if you have any questions!

- Jenny, team Mbed

If this solved your question, please make sure to click the "Thanks" link below!

Thank you so much. I'll try it out ;)

posted by Mustafa Kazaale 13 Apr 2018