Create text file in on-board memory
Tagged: filesystem, mDot
- This topic has 10 replies, 3 voices, and was last updated 6 years, 8 months ago by Denwis La.
-
AuthorPosts
-
February 7, 2018 at 1:19 pm #22536Denwis LaParticipant
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
February 7, 2018 at 1:36 pm #22541Ryan KlaassenBlockedOne 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);February 7, 2018 at 1:45 pm #22542Jason ReissKeymasterHere is another example.
February 7, 2018 at 2:56 pm #22543Denwis LaParticipantThank 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.
February 7, 2018 at 3:03 pm #22544Jason ReissKeymasterDid 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?
February 7, 2018 at 3:34 pm #22545Denwis LaParticipantI 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.February 7, 2018 at 3:38 pm #22546Jason ReissKeymasterWhen you upload either binary?
February 7, 2018 at 3:45 pm #22547Denwis LaParticipantYes. Both binaries produce this message for me.
February 22, 2018 at 1:15 pm #22669Denwis LaParticipantUpdate: 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
February 26, 2018 at 9:24 am #22685Jason ReissKeymasterThe 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-bootloaderAvailable 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!
March 25, 2018 at 11:46 am #22929Denwis LaParticipantI’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;
-
AuthorPosts
- You must be logged in to reply to this topic.