SD library mkdir(); produces weird effect on DUE and Bitlash 2.0

Hi everybody, I am trying to implement the native SDCard library to Bitlash 2.0.
When I boot the Due with the Sketch loaded, it recognizes the SDCard, I can use my custom comand DIR (based on a demo sketch of the SD Library) and it works like a charm.
When it boots, I run DIR, and it shows me all the folder tree without problems. I can run DIR repeatidly and even navigate inside folders running DIR as well. The thing is that when I run the MKDIR command, it does work too, it creates the folders and I create all I want, but then the DIR command will only show me all the folders/files made after the first call to MKDIR. The only solution is rebooting the arduino, and running DIR will show all the files and folders, included those made by MKDIR prior to reboot.

The command snippets are the following:
(currentDirectory is a charArray with stores the current level. It works fine and I already checked it doesn’t get corrupted by anything else. Before and after DIR and MKDIR, the currentDirectory is the same)

DIR command:

numvar dir(void){
  vgaPrintLN("--Directory Print--");
File directory =;
  printDirectory(directory, 0);
return 0;

void printDirectory(File dir, int numTabs) {
   while(true) {
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
     for (uint8_t i=0; i<numTabs; i++) {
     if (entry.isDirectory()) {
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       vgaPrintLN(entry.size(), DEC);

MKDIR command:

numvar mk(void){

char final[250];
sprintf(final,"%s%s",currentDirectory,(char*) getarg(1));
  vgaPrintLN("@directorio creado");
}  else{
vgaPrint("@error creando directorio");

is there a way to hard-reset the SD library?

Try adding a rewindDirectory() here:

void printDirectory(File dir, int numTabs) {
  dir.rewindDirectory();  // <-------------Add Here
   while(true) {

The open function does not position all directory files to the beginning. For example SD has an internal copy of root and just returns a copy in open so it is positioned just after the last mkdir.

is there a way to hard-reset the SD library?

SD.h is a wrapper for a very old version of SdFat and there are a number of bugs in the wrapper and that version of SdFat. One of these bugs prevents a “hard-reset”.

Newer versions of SdFat allow begin() to be called to reset everything.

You can fix the “native SD library” by editing SD.cpp at about line 337 and adding a line in begin().

boolean SDClass::begin(uint8_t csPin) {

    Performs the initialisation required by the sdfatlib library.

    Return true if initialization succeeds, false otherwise.

  root.close();  // <------------------------Add this line.
  return card.init(SPI_HALF_SPEED, csPin) &&
         volume.init(card) &&

This solved the issue! Thanks for the help. I will implement the hard reset option too just in case :grin: