Create text file in on-board memory

Home Forums mDot/xDot Create text file in on-board memory

Tagged: ,

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #22536
    Denwis La
    Participant

    Hello,

    Would there happen to be an example available for how to create files in the mDot? When I try to use saveUserFile(“Test”, data, 128) I get the error that saveUserFile is undefined when I build it.

    I am thinking that I am not passing the right parameters when I call the function. “Test” for const char* parameter, data as an int array of 10 elements for void* parameter, and 128 for uint32_t parameter, which is for size of file in bytes. Am I correct?

    I have mdot.h included in the header from libmDot-dev-mbed5 version 3.02-39 and mbed 5.5.7.

    Thank you

    #22541
    Ryan Klaassen
    Blocked

    One example is:

    char data[] = “hello”;

    dot->saveUserFile(“test1”, (void*)data, 5);

    Another way of doing it would be
    char data[] = “hello”;
    mDot::mdot_file file = dot->openUserFile(“test1”,(mDot::FM_RDWR|mDot::FM_CREAT));
    dot->writeUserFile(file, (void*)data, 5);
    dot->closeUserFile(file);

    #22542
    Jason Reiss
    Keymaster
    #22543
    Denwis La
    Participant

    Thank you for the examples.

    Realized that the reason that I was getting those identifier errors was due to me not including the dot-> part.

    When I implement these examples I get none of the printf statements in my terminal and instead get a continuous FaulHard that goes on nonstop.

    I’ve tried just a dot->saveUserFile call with a print statement right before it and I still get this FaulHard without my print statement showing.

    #22544
    Jason Reiss
    Keymaster

    Did you compile the example project as is or try to integrate with your own project?

    Can you get the example project to work without modifications?

    #22545
    Denwis La
    Participant

    I compiled it as is and in my own project.
    They compile successfully. When I upload the binary and reset is when I get the faulhard message.

    #22546
    Jason Reiss
    Keymaster

    When you upload either binary?

    #22547
    Denwis La
    Participant

    Yes. Both binaries produce this message for me.

    #22669
    Denwis La
    Participant

    Update: Creating the files is working now. I tried implementing the functions in another program and it worked. I’m unsure as to why, when I imported the example and upload its bin file, it gives that error.

    Another question, is it possible to see the created file in the same location as the DETAILS.TXT file on the mDot at default? I would like to be able to open the file from computer rather than from code.

    Thank you

    #22685
    Jason Reiss
    Keymaster

    The DETAILS.TXT file is in the flash of the programming module on the developer board. The mDot software does not have access to it.

    The boot loader can be used to send a file from the flash to a PC over serial. The file name will have ‘u_’ prepended to the name you have assigned through code.

    The bootloader is accessed through the debug port.
    https://os.mbed.com/teams/MultiTech/wiki/updating-firmware-using-MTS-bootloader

    Available commands:
    help: display this message
    boot: start user application
    upgrade : upgrade to new firmware transferred over serial
    transfer : transfer new firmware over serial, but don’t flash it
    recv simple : read file into the filesystem over serial
    recv ymodem [filename]: read file into the filesystem over serial
    send
    : send file from the filesystem over serial
    flash: flash new firmware that has already been transferred
    reset: perform a soft reset of the system
    delete
    : delete the specififed file from the filesystem
    erase: erase entire 2MB external flash – BE SURE YOU WANT TO DO THIS!

    #22929
    Denwis La
    Participant

    I’ve opted to try to use an SD card for my application. With mbed’s sd-driver library, I’m experiencing troubles performing sd initialization with its init() function and mount() from their FATfilesystem. I was advised on the mbed forums that maybe it is due to a spi frequency problem. What happens is that it takes forever, and mostly never, finishes the init() or mount() function.

    The SDblock device instance is at default 100kHz. I’m trying to find what the mDot’s minimum SPI ferquency is so that I can adjust it in its definition, however I am having trouble finding it, unless it is 96MHz(?). And so I don’t know what or where to look on how to resolve my problem.

    
    SDBlockDevice sd(D11, D12, D13, D10); // mosi, miso, sclk, cs
    
    FATFileSystem fs("sd"); 
    
    if(sd.init() == 0)
        {
            pc.printf("Init success \n\r");
        }
        else pc.printf("Init failed \n\r");
        int err = fs.mount(&sd);
        pc.printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));
        if (err)
            return err;
        pc.printf("Error for mounting was %d\n\r", err);
        // Open the file.
        pc.printf("Opening file '/sd/mytest/sdtest.txt'... ");
     
        fp = fopen("/sd/mytest/sdtest.txt", "w+");
        pc.printf("%s\r\n", (!fp ? "Failed :(\r\n" : "OK\r\n"));
     
        if (!fp)
        {
            // Check whether directory '/sd/mytest' exists.
            pc.printf("\r\nChecking directory '/sd/mytest'...\r\n");
            struct stat info;
            err = mystat("/sd/mytest", &info);
            if (err)
            {
                pc.printf("Directory '/sd/mytest' does not exist.\r\n");
                pc.printf("Trying to create it...");
                err = mkdir("/sd/mytest", 0777);
                pc.printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));
                if (err)
                  return err;
            }
                    
            // Create a new 'sdtest.txt' file.
            pc.printf("File not found, creating a new one...\r\n");
            fp = fopen("/sd/mytest/sdtest.txt", "w+");
            pc.printf("%s\r\n", (!fp ? "Failed :(" : "OK"));
            if (!fp)
            {
                error("error: %s (%d)\r\n", strerror(errno), -errno);
                return errno;
            }
        }
        
        for (int i = 0; i < 10; i++)
        {
            pc.printf("Writing numbers (%d/%d)... ", i, 10);
            err = fprintf(fp, "    %d\r\n", i);
            if (err < 0)
            {
                pc.printf("Fail :(\r\n");
                error("error: %s (%d)\r\n", strerror(errno), -errno);
            }
            else
                pc.printf("OK\r\n");
        }
     
        pc.printf("Writing numbers (%d/%d)... OK\r\n\r\n", 10, 10);
        
        err = fclose(fp);
        pc.printf("Closing file '/sd/mytest/sdtest.txt'... ");
        pc.printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));
        if (err)
          return err;
     
        return 0;
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.