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

Dependencies:   EALib USBDevice mbed

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

The application makes the LPC4088 QuickStart Board 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. Make sure that the QSPI file system has been formatted (using either the app_qspi_format application or one of the erase.* images).
  2. Download the app_qspifs_memstick application using drag-n-drop and then reset the board
  3. Optionally start a terminal program to read the status messages from the application
  4. Connect a USB cable to the micro USB slot on the back of the LPC4088 QuickStart Board, underneath the ethernet connector, and then to the PC
  5. The PC will install drivers if needed and then the USB Memory Stick will be available as a new drive
  6. Modify the file system to suit your needs
  7. With the USB cable still connected, press the button on the LPC4088 QuickStart Board
  8. 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
  9. Continue from step 6. until satisfied

Note 1: 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 2: The image files created in step 8.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.

Committer:
embeddedartists
Date:
Tue Aug 26 06:44:43 2014 +0000
Revision:
2:5a954ee65b33
Parent:
0:bd0d999bb6fb
Aligned with the updates in FATFileSystem (i.e. one more parameter in disk_read/disk_write).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:bd0d999bb6fb 1 #include "RAMFileSystem.h"
embeddedartists 0:bd0d999bb6fb 2 #include "mbed_debug.h"
embeddedartists 0:bd0d999bb6fb 3
embeddedartists 0:bd0d999bb6fb 4 #define RAMFS_DBG 0
embeddedartists 0:bd0d999bb6fb 5
embeddedartists 0:bd0d999bb6fb 6 #define SECTOR_SIZE 512
embeddedartists 0:bd0d999bb6fb 7
embeddedartists 0:bd0d999bb6fb 8 RAMFileSystem::RAMFileSystem(uint32_t addr, uint32_t size, const char* name) :
embeddedartists 0:bd0d999bb6fb 9 FATFileSystem(name) {
embeddedartists 0:bd0d999bb6fb 10 memStart = addr;
embeddedartists 0:bd0d999bb6fb 11 memSize = size - (size % SECTOR_SIZE);
embeddedartists 0:bd0d999bb6fb 12 status = 1; //1: disk not initialized
embeddedartists 0:bd0d999bb6fb 13 }
embeddedartists 0:bd0d999bb6fb 14
embeddedartists 0:bd0d999bb6fb 15 int RAMFileSystem::disk_initialize() {
embeddedartists 0:bd0d999bb6fb 16 debug_if(RAMFS_DBG, "init RAM fs\n");
embeddedartists 0:bd0d999bb6fb 17 status = 0; //OK
embeddedartists 0:bd0d999bb6fb 18 return status;
embeddedartists 0:bd0d999bb6fb 19 }
embeddedartists 0:bd0d999bb6fb 20
embeddedartists 0:bd0d999bb6fb 21 int RAMFileSystem::disk_write(const uint8_t *buffer, uint64_t sector) {
embeddedartists 0:bd0d999bb6fb 22 debug_if(RAMFS_DBG, "write to sector %llu\n", sector);
embeddedartists 0:bd0d999bb6fb 23 if (sector >= disk_sectors()) {
embeddedartists 0:bd0d999bb6fb 24 return 1;
embeddedartists 0:bd0d999bb6fb 25 }
embeddedartists 0:bd0d999bb6fb 26
embeddedartists 0:bd0d999bb6fb 27 memcpy((uint8_t*)(memStart + SECTOR_SIZE*((uint32_t)sector)), buffer, SECTOR_SIZE);
embeddedartists 0:bd0d999bb6fb 28 return 0;
embeddedartists 0:bd0d999bb6fb 29 }
embeddedartists 0:bd0d999bb6fb 30
embeddedartists 0:bd0d999bb6fb 31 int RAMFileSystem::disk_read(uint8_t *buffer, uint64_t sector) {
embeddedartists 0:bd0d999bb6fb 32 debug_if(RAMFS_DBG, "read from sector %llu\n", sector);
embeddedartists 0:bd0d999bb6fb 33 if (sector >= disk_sectors()) {
embeddedartists 0:bd0d999bb6fb 34 return 1;
embeddedartists 0:bd0d999bb6fb 35 }
embeddedartists 0:bd0d999bb6fb 36
embeddedartists 0:bd0d999bb6fb 37 memcpy(buffer, (uint8_t*)(memStart + SECTOR_SIZE*((uint32_t)sector)), SECTOR_SIZE);
embeddedartists 0:bd0d999bb6fb 38 return 0;
embeddedartists 0:bd0d999bb6fb 39 }
embeddedartists 0:bd0d999bb6fb 40
embeddedartists 2:5a954ee65b33 41 int RAMFileSystem::disk_nwrite(const uint8_t *buffer, uint64_t sector, uint8_t count) {
embeddedartists 2:5a954ee65b33 42 debug_if(RAMFS_DBG, "write to sector(s) %llu..%llu\n", sector, sector+count);
embeddedartists 2:5a954ee65b33 43 if ((sector+count-1) >= disk_sectors()) {
embeddedartists 2:5a954ee65b33 44 return 1;
embeddedartists 2:5a954ee65b33 45 }
embeddedartists 2:5a954ee65b33 46
embeddedartists 2:5a954ee65b33 47 memcpy((uint8_t*)(memStart + SECTOR_SIZE*((uint32_t)sector)), buffer, SECTOR_SIZE*count);
embeddedartists 2:5a954ee65b33 48 return 0;
embeddedartists 2:5a954ee65b33 49 }
embeddedartists 2:5a954ee65b33 50
embeddedartists 2:5a954ee65b33 51 int RAMFileSystem::disk_nread(uint8_t *buffer, uint64_t sector, uint8_t count) {
embeddedartists 2:5a954ee65b33 52 debug_if(RAMFS_DBG, "read from sector(s) %llu..%llu\n", sector, sector+count);
embeddedartists 2:5a954ee65b33 53 if ((sector+count-1) >= disk_sectors()) {
embeddedartists 2:5a954ee65b33 54 return 1;
embeddedartists 2:5a954ee65b33 55 }
embeddedartists 2:5a954ee65b33 56
embeddedartists 2:5a954ee65b33 57 memcpy(buffer, (uint8_t*)(memStart + SECTOR_SIZE*((uint32_t)sector)), SECTOR_SIZE*count);
embeddedartists 2:5a954ee65b33 58 return 0;
embeddedartists 2:5a954ee65b33 59 }
embeddedartists 2:5a954ee65b33 60
embeddedartists 0:bd0d999bb6fb 61 int RAMFileSystem::disk_status() {
embeddedartists 0:bd0d999bb6fb 62 debug_if(RAMFS_DBG, "disk status %d\n", status);
embeddedartists 0:bd0d999bb6fb 63 return status;
embeddedartists 0:bd0d999bb6fb 64 }
embeddedartists 0:bd0d999bb6fb 65 int RAMFileSystem::disk_sync() {
embeddedartists 0:bd0d999bb6fb 66 return 0;
embeddedartists 0:bd0d999bb6fb 67 }
embeddedartists 0:bd0d999bb6fb 68 uint64_t RAMFileSystem::disk_sectors() {
embeddedartists 0:bd0d999bb6fb 69 debug_if(RAMFS_DBG, "returning fs has %u sectors\n", memSize/SECTOR_SIZE);
embeddedartists 0:bd0d999bb6fb 70 return memSize/SECTOR_SIZE;
embeddedartists 0:bd0d999bb6fb 71 }
embeddedartists 0:bd0d999bb6fb 72
embeddedartists 0:bd0d999bb6fb 73 uint64_t RAMFileSystem::disk_size() {
embeddedartists 0:bd0d999bb6fb 74 return memSize;
embeddedartists 0:bd0d999bb6fb 75 }
embeddedartists 0:bd0d999bb6fb 76