So I just found myself in unchartered territory ...
I did make a mistake in my C, and could compile Simon's suggestion, but could not open a file, the pc console responds with
"No disk, or could not put SD card in to SPI idle state"
and gets stuck there, it does not return to the application. So back to the standard configuration, and with some trial and error I now have a working configuration, and indeed sd.disk_initialize() does the trick, but to my surprise I have to do it twice after inserting the SD card. This may have to do with the card type, or maybe a time-out in the library is a little bit too short. My results are really consistent, although I have only 2 cards to test, one is a 1 GByte SanDisk, the other one a 64 MByte Nokia branded card, and both behave identical.
My code now looks like:
switch (inbuf[2]) {
case f_sdcard : // create object for SD card
// sd = new SDFileSystem(p5, p6, p7, p8, "sd");
DBG_msg("do_fmount", "1st init");
sd.disk_initialize(); //initialize file system
DBG_msg("do_fmount", "2nd init");
sd.disk_initialize(); //initialize file system
break;
case f_local : // mount local flash, nothing really to do, it is always there
break;
case f_usb : msc.disk_initialize(); // enumerate USB device
break;
default : do_fdefault(); // command not recognized
break;
I am curious if others have found this behavior, and if maybe the time out in the laibrary should be made longer. In any case, when the card was already inserted during the reset, there are no problems, just changing a card causes this behavior.
I am working on a sort of command interpreter, and would like to dynamically mount and unmount filesystems, for example the LocalFileSystem, an SD Card or USB drive. Unmount is needed when taking out a drive and replacing it with something else.
The declaration and initialization of filesystems is always done outside main(), and not in a function. I have tested this inside a switch statement (see below), and it passes compilation, but I cannot open a file. When the declaration is done outside the scope of the function with the switch() statement, it works very well.
switch (inbuf[2]) {
case f_sdcard : { SDFileSystem sd(p5, p6, p7, p8, fs_sd); // mount SD card
break;
}
case f_flash : { LocalFileSystem flash("local"); // mount local flash
break;
}
}
My other question is if I need to unmount a filesystem prior to physical removal of an SD card or USB drive, and if so, how is this done. Then of ocurse when a new medium is inserted, it needs to be mounted again. How is that accomplished?
Thanks,