The purpose of this application is to allow easy manipulation of the QSPI file system from a PC (**NOTE**: Application doesn't work with update to mbed OS 5 since USB Device support is currently not available for LPC4088)

Dependencies:   DMBasicGUI DMSupport

Note

This application doesn't work with the latest updates to mbed OS 5 since USB Device support is currently not available for LPC4088

The purpose of this application is to allow easy manipulation of the QSPI file system from a PC.

The application makes the LPC4088 Display Module appear as a USB Memory Stick when connected to a PC. The PC will see the current content of the QSPI file system plus an image file of the file system that can be downloaded and (at a later time) be used to restore the file system to it's current state.

To use this application:

  1. Download the lpc4088_displaymodule_fs_aid application using drag-n-drop and then reset the board
  2. Optionally start a terminal program to read the status messages from the application
  3. Connect a USB cable to the mini USB slot on the back of the LPC4088 Display Module, and then to the PC
  4. The PC will install drivers if needed and then the USB Memory Stick will be available as a new drive
  5. Modify the file system to suit your needs
  6. With the USB cable still connected, press the USER/ISP/SW1 button on the LPC4088 Display Module
  7. The application will now:
    1. disconnect the USB Memory Stick
    2. write all changes to the QSPI flash memory
    3. create a new image file of the updated QSPI file system and store it in the .current/ folder
    4. connect the USB Memory Stick again
  8. Continue from step 5. until satisfied

Note 1: If the QSPI doesn't have a file system on it or to replace the current one with a new, possibly of a different size, file system just add a file with the name format_qspi_X_mb (where X should be replace with the wanted file system size in Mb). For a 10 Mb file system the file name should be format_qspi_10_mb.

Note 2: The file system that is exposed is a copy (in SDRAM) of the QSPI file system. The reason for this is that the USBMSD class requires a FAT file system.

Note 3: The image files created in step 7.3 above will be a *.fsX file (where the 'X' is the size of the file system in MB so *.fs1 for a 1MByte file system). The *.fsX file extensions are recognized by the HDK and can be used to drag-n-drop to the MBED drive in the same way as the *.bin files are. A *.fsX file will not overwrite the program stored in internal flash.

Files at this revision

API Documentation at this revision

Comitter:
alindvall
Date:
Mon May 16 08:13:27 2016 +0000
Parent:
0:06e35dd73c95
Commit message:
Added support for formatting of QSPI file system via special files.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 06e35dd73c95 -r b04139d88c59 main.cpp
--- a/main.cpp	Mon May 16 07:05:18 2016 +0000
+++ b/main.cpp	Mon May 16 08:13:27 2016 +0000
@@ -1,7 +1,7 @@
 /******************************************************************************
  * Includes
  *****************************************************************************/
- 
+
 #include "mbed.h"
 #include "mbed_interface.h"
 #include "rtos.h"
@@ -48,16 +48,16 @@
 {
   static int state = 0;
   state = (state + 1) % 2;
-    
-    DMBoard* board = &DMBoard::instance();
-    board->setLED(DMBoard::Led1, state==0);
-    board->setLED(DMBoard::Led2, state!=0);
+
+  DMBoard* board = &DMBoard::instance();
+  board->setLED(DMBoard::Led1, state==0);
+  board->setLED(DMBoard::Led2, state!=0);
 }
 
 static void handleError(const char* msg)
 {
-    DMBoard* board = &DMBoard::instance();
-    board->logger()->printf(msg);
+  DMBoard* board = &DMBoard::instance();
+  board->logger()->printf(msg);
   while(true) {
     board->setLED(DMBoard::Led1, false);
     board->setLED(DMBoard::Led2, false);
@@ -70,7 +70,7 @@
 
 static void waitForButtonPress()
 {
-    DMBoard* board = &DMBoard::instance();
+  DMBoard* board = &DMBoard::instance();
   printf("Press button to sync file systems\n");
 
   board->setLED(DMBoard::Led1, false);
@@ -89,8 +89,12 @@
 {
     FILE *fp = fopen("/ram/qspi_not_formatted.txt", "w");
     if (fp != NULL) {
-        fprintf(fp, "The QSPI file system has not be formatted and this program can't do it.\n");
-        fprintf(fp, "Format the QSPI file system and then run this program again!\n");
+        fprintf(fp, "The QSPI file system has not be formatted. To format create a\n");
+        fprintf(fp, "file with the name \"format_qspi_X_mb\" on the drive and then\n");
+        fprintf(fp, "press the USER/ISP/SW1 button to format\n");
+        fprintf(fp, "The X in the file name should be replaced with the desired\n");
+        fprintf(fp, "file system size in Mb (1 to 16). For a 10 Mb file sytem the file\n");
+        fprintf(fp, "name would be format_qspi_10_mb.\n");
         fclose(fp);
     }
 }
@@ -384,7 +388,7 @@
     handleError(lsbuff);
   }
   sprintf(image_file_name, "/ram/.current/fs_image.fs%d", (size >> 20));
-  
+
   // NOTE: The line below is very very !!!! important. For some weird reason the
   //       RAM file system must have at least one folder on it before USB is connected.
   //       If the RAM file system doesn't have any folders on it the result is that
@@ -439,28 +443,58 @@
   }
 }
 
+static bool formatIfRequested()
+{
+  DMBoard* board = &DMBoard::instance();
+  RtosLog* logger = board->logger();
+  char marker[50];
+  int size;
+  uint32_t maxSize = SPIFI::instance().memorySize()>>20;
+
+  for (size = 1; size <= maxSize; size++) {
+    sprintf(marker, "/ram/format_qspi_%d_mb", size);
+    FILE *fp = fopen(marker, "r");
+    if (fp != NULL) {
+      logger->printf("Found a marker file requesting to place a %d Mb file system on QSPI\n", size);
+      logger->printf("This operation may take up to a couple of minutes!\n");
+      QSPIFileSystem* qspi = board->getQspiFS();
+
+      int err = qspi->format(size);
+      if (err == 0) {
+        logger->printf("Successfully added a %d Mb file system to QSPI!\n", size);
+      } else {
+        logger->printf("Failed to format QSPI!\n");
+      }
+      // formatting was requested
+      return true;
+    }
+  }
+  // no formatting requested
+  return false;
+}
+
 static void showInfoScreen()
 {
-    static SWIM_WINDOW_T* win = NULL;
-    static void* fb = NULL;
-    
+  static SWIM_WINDOW_T* win = NULL;
+  static void* fb = NULL;
+
   Display* disp = DMBoard::instance().display();
   win = (SWIM_WINDOW_T*)malloc(sizeof(SWIM_WINDOW_T));
   fb = disp->allocateFramebuffer();
-    
-  swim_window_open(win, 
+
+  swim_window_open(win,
                    disp->width(), disp->height(),         // full size
                    (COLOR_T*)fb,
                    0,0,disp->width()-1, disp->height()-1, // window position and size
                    0,                                     // border
                    BLUE, WHITE, BLACK);                   // colors: pen, backgr, forgr
-  
-    swim_set_font(win, (FONT_T*)&font_winfreesys14x16);
+
+  swim_set_font(win, (FONT_T*)&font_winfreesys14x16);
 
   // Show a message
-    swim_put_text_centered_win(win, "In this version all instructions are printed on the console!", disp->height()/2 - 20);
-    swim_put_text_centered_win(win, "Connect a terminal application using 115200, 8N1.", disp->height()/2 + 20);
-    
+  swim_put_text_centered_win(win, "In this version all instructions are printed on the console!", disp->height()/2 - 20);
+  swim_put_text_centered_win(win, "Connect a terminal application using 115200, 8N1.", disp->height()/2 + 20);
+
   // Start display in default mode (16-bit)
   Display::DisplayError disperr = disp->powerUp(fb);
   if (disperr != Display::DisplayError_Ok) {
@@ -484,41 +518,41 @@
     wait_ms(2000); // allow RtosLog to flush messages
     mbed_die();
   }
-  
+
   log->printf("\n\n---\nQSPI file syncer app\nBuilt: " __DATE__ " at " __TIME__ "\n\n");
 
-    showInfoScreen();
-    
+  showInfoScreen();
+
   // allocate a chunk of memory in the external SDRAM to use as a RAM file system
   void* fsmem = malloc(RAM_FS_SIZE);
   if (fsmem == NULL) {
     log->printf("Failed to allocate memory for RAM file system\n");
     mbed_die();
   }
- 
+
   // create a file system based on the allocated memory
   RAMFileSystem ramfs((uint32_t)fsmem, RAM_FS_SIZE, "ram");
-    USBMSD_RAMFS usbmsd(&ramfs);  
- 
-    while(true)
-    {
+  USBMSD_RAMFS usbmsd(&ramfs);
+
+  while(true)
+  {
     // add an empty file system on it
     ramfs.format();
-      
-      QSPIFileSystem* qspi = board->getQspiFS();
+
+    QSPIFileSystem* qspi = board->getQspiFS();
     bool qspiFormatted = qspi->isformatted();
     if (!qspiFormatted)
     {
       addNotFormattedFile();
     }
-      else
-      {
+    else
+    {
       createImageFile(qspi);
-    
+
       // Copy QSPI FS to RAM FS
       syncDir("/ram/", "/qspi/");
-      }
-    
+    }
+
     printf("Insert the USB cable!\n");
     printf("Starting USB...\n");
     for (int i = 0; i < 10; i++)
@@ -533,24 +567,19 @@
       wait(1);
     }
 
-    // 6b)
-    if (qspiFormatted) 
-    {
-      waitForButtonPress();
-    }
-    else
-    {
-      // 6a) no point in waiting for buttons if no file system
-      while (1) {};
-    }
+    waitForButtonPress();
 
-    // 7)
     usbmsd.disconnect();
     printf("Disconnected!\n");
 
-    // 8) Copy RAM FS to QSPI FS
+    // Look for (re)format instruction file
+    if (formatIfRequested()) {
+      continue;
+    }
+
+    // Copy RAM FS to QSPI FS
     recursiveList("/ram/");
     syncDir("/qspi/", "/ram/");
-    }   
+  }
 }