Emulation of LocalFileSystem with virtual COM.

Dependencies:   USBDevice

Dependents:   KL46Z-lpc81isp lpcterm2

#include "USBLocalFileSystem.h"

int main() {
    USBLocalFileSystem* usb_local = new USBLocalFileSystem(); // RamDisk(64KB)

    while(1) {
        usb_local->lock(true);
        usb_local->remount();
        char filename[32];
        if (usb_local->find(filename, sizeof(filename), "*.TXT")) {
            FILE* fp = fopen(filename, "r");
            if (fp) {
                int c;
                while((c = fgetc(fp)) != EOF) {
                    usb_local->putc(c);
                }
                fclose(fp);
            }
        }    
        usb_local->lock(false);

        wait_ms(1000*5);
    }
}



Sample application:

Import programKL46Z-lpc81isp

ISP example program.

Import programlpcterm2

semihost server example program

Committer:
va009039
Date:
Sat Jun 21 22:39:59 2014 +0000
Revision:
6:528036abfb02
Parent:
0:39eb4d5b97df
add LPC11U68

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:39eb4d5b97df 1 /*---------------------------------------------------------------------------/
va009039 0:39eb4d5b97df 2 / FatFs - FAT file system module configuration file R0.09a (C)ChaN, 2012
va009039 0:39eb4d5b97df 3 /----------------------------------------------------------------------------/
va009039 0:39eb4d5b97df 4 /
va009039 0:39eb4d5b97df 5 / CAUTION! Do not forget to make clean the project after any changes to
va009039 0:39eb4d5b97df 6 / the configuration options.
va009039 0:39eb4d5b97df 7 /
va009039 0:39eb4d5b97df 8 /----------------------------------------------------------------------------*/
va009039 0:39eb4d5b97df 9 #ifndef _FFCONF
va009039 0:39eb4d5b97df 10 #define _FFCONF 4004 /* Revision ID */
va009039 0:39eb4d5b97df 11
va009039 0:39eb4d5b97df 12 #define FFS_DBG 0
va009039 0:39eb4d5b97df 13
va009039 0:39eb4d5b97df 14 /*---------------------------------------------------------------------------/
va009039 0:39eb4d5b97df 15 / Functions and Buffer Configurations
va009039 0:39eb4d5b97df 16 /----------------------------------------------------------------------------*/
va009039 0:39eb4d5b97df 17
va009039 0:39eb4d5b97df 18 #define _FS_TINY 0 /* 0:Normal or 1:Tiny */
va009039 0:39eb4d5b97df 19 /* When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system
va009039 0:39eb4d5b97df 20 / object instead of the sector buffer in the individual file object for file
va009039 0:39eb4d5b97df 21 / data transfer. This reduces memory consumption 512 bytes each file object. */
va009039 0:39eb4d5b97df 22
va009039 0:39eb4d5b97df 23
va009039 0:39eb4d5b97df 24 #define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */
va009039 0:39eb4d5b97df 25 /* Setting _FS_READONLY to 1 defines read only configuration. This removes
va009039 0:39eb4d5b97df 26 / writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename,
va009039 0:39eb4d5b97df 27 / f_truncate and useless f_getfree. */
va009039 0:39eb4d5b97df 28
va009039 0:39eb4d5b97df 29
va009039 0:39eb4d5b97df 30 #define _FS_MINIMIZE 0 /* 0 to 3 */
va009039 0:39eb4d5b97df 31 /* The _FS_MINIMIZE option defines minimization level to remove some functions.
va009039 0:39eb4d5b97df 32 /
va009039 0:39eb4d5b97df 33 / 0: Full function.
va009039 0:39eb4d5b97df 34 / 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename
va009039 0:39eb4d5b97df 35 / are removed.
va009039 0:39eb4d5b97df 36 / 2: f_opendir and f_readdir are removed in addition to 1.
va009039 0:39eb4d5b97df 37 / 3: f_lseek is removed in addition to 2. */
va009039 0:39eb4d5b97df 38
va009039 0:39eb4d5b97df 39
va009039 0:39eb4d5b97df 40 #define _USE_STRFUNC 0 /* 0:Disable or 1-2:Enable */
va009039 0:39eb4d5b97df 41 /* To enable string functions, set _USE_STRFUNC to 1 or 2. */
va009039 0:39eb4d5b97df 42
va009039 0:39eb4d5b97df 43
va009039 0:39eb4d5b97df 44 #define _USE_MKFS 1 /* 0:Disable or 1:Enable */
va009039 0:39eb4d5b97df 45 /* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
va009039 0:39eb4d5b97df 46
va009039 0:39eb4d5b97df 47
va009039 0:39eb4d5b97df 48 #define _USE_FORWARD 0 /* 0:Disable or 1:Enable */
va009039 0:39eb4d5b97df 49 /* To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */
va009039 0:39eb4d5b97df 50
va009039 0:39eb4d5b97df 51
va009039 0:39eb4d5b97df 52 #define _USE_FASTSEEK 0 /* 0:Disable or 1:Enable */
va009039 0:39eb4d5b97df 53 /* To enable fast seek feature, set _USE_FASTSEEK to 1. */
va009039 0:39eb4d5b97df 54
va009039 0:39eb4d5b97df 55
va009039 0:39eb4d5b97df 56
va009039 0:39eb4d5b97df 57 /*---------------------------------------------------------------------------/
va009039 0:39eb4d5b97df 58 / Locale and Namespace Configurations
va009039 0:39eb4d5b97df 59 /----------------------------------------------------------------------------*/
va009039 0:39eb4d5b97df 60
va009039 0:39eb4d5b97df 61 #define _CODE_PAGE 858
va009039 0:39eb4d5b97df 62 /* The _CODE_PAGE specifies the OEM code page to be used on the target system.
va009039 0:39eb4d5b97df 63 / Incorrect setting of the code page can cause a file open failure.
va009039 0:39eb4d5b97df 64 /
va009039 0:39eb4d5b97df 65 / 932 - Japanese Shift-JIS (DBCS, OEM, Windows)
va009039 0:39eb4d5b97df 66 / 936 - Simplified Chinese GBK (DBCS, OEM, Windows)
va009039 0:39eb4d5b97df 67 / 949 - Korean (DBCS, OEM, Windows)
va009039 0:39eb4d5b97df 68 / 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)
va009039 0:39eb4d5b97df 69 / 1250 - Central Europe (Windows)
va009039 0:39eb4d5b97df 70 / 1251 - Cyrillic (Windows)
va009039 0:39eb4d5b97df 71 / 1252 - Latin 1 (Windows)
va009039 0:39eb4d5b97df 72 / 1253 - Greek (Windows)
va009039 0:39eb4d5b97df 73 / 1254 - Turkish (Windows)
va009039 0:39eb4d5b97df 74 / 1255 - Hebrew (Windows)
va009039 0:39eb4d5b97df 75 / 1256 - Arabic (Windows)
va009039 0:39eb4d5b97df 76 / 1257 - Baltic (Windows)
va009039 0:39eb4d5b97df 77 / 1258 - Vietnam (OEM, Windows)
va009039 0:39eb4d5b97df 78 / 437 - U.S. (OEM)
va009039 0:39eb4d5b97df 79 / 720 - Arabic (OEM)
va009039 0:39eb4d5b97df 80 / 737 - Greek (OEM)
va009039 0:39eb4d5b97df 81 / 775 - Baltic (OEM)
va009039 0:39eb4d5b97df 82 / 850 - Multilingual Latin 1 (OEM)
va009039 0:39eb4d5b97df 83 / 858 - Multilingual Latin 1 + Euro (OEM)
va009039 0:39eb4d5b97df 84 / 852 - Latin 2 (OEM)
va009039 0:39eb4d5b97df 85 / 855 - Cyrillic (OEM)
va009039 0:39eb4d5b97df 86 / 866 - Russian (OEM)
va009039 0:39eb4d5b97df 87 / 857 - Turkish (OEM)
va009039 0:39eb4d5b97df 88 / 862 - Hebrew (OEM)
va009039 0:39eb4d5b97df 89 / 874 - Thai (OEM, Windows)
va009039 0:39eb4d5b97df 90 / 1 - ASCII only (Valid for non LFN cfg.)
va009039 0:39eb4d5b97df 91 */
va009039 0:39eb4d5b97df 92
va009039 0:39eb4d5b97df 93
va009039 0:39eb4d5b97df 94 #define _USE_LFN 0 /* 0 to 3 */
va009039 0:39eb4d5b97df 95 #define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
va009039 0:39eb4d5b97df 96 /* The _USE_LFN option switches the LFN support.
va009039 0:39eb4d5b97df 97 /
va009039 0:39eb4d5b97df 98 / 0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect.
va009039 0:39eb4d5b97df 99 / 1: Enable LFN with static working buffer on the BSS. Always NOT reentrant.
va009039 0:39eb4d5b97df 100 / 2: Enable LFN with dynamic working buffer on the STACK.
va009039 0:39eb4d5b97df 101 / 3: Enable LFN with dynamic working buffer on the HEAP.
va009039 0:39eb4d5b97df 102 /
va009039 0:39eb4d5b97df 103 / The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. To enable LFN,
va009039 0:39eb4d5b97df 104 / Unicode handling functions ff_convert() and ff_wtoupper() must be added
va009039 0:39eb4d5b97df 105 / to the project. When enable to use heap, memory control functions
va009039 0:39eb4d5b97df 106 / ff_memalloc() and ff_memfree() must be added to the project. */
va009039 0:39eb4d5b97df 107
va009039 0:39eb4d5b97df 108
va009039 0:39eb4d5b97df 109 #define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
va009039 0:39eb4d5b97df 110 /* To switch the character code set on FatFs API to Unicode,
va009039 0:39eb4d5b97df 111 / enable LFN feature and set _LFN_UNICODE to 1. */
va009039 0:39eb4d5b97df 112
va009039 0:39eb4d5b97df 113
va009039 0:39eb4d5b97df 114 #define _FS_RPATH 0 /* 0 to 2 */
va009039 0:39eb4d5b97df 115 /* The _FS_RPATH option configures relative path feature.
va009039 0:39eb4d5b97df 116 /
va009039 0:39eb4d5b97df 117 / 0: Disable relative path feature and remove related functions.
va009039 0:39eb4d5b97df 118 / 1: Enable relative path. f_chdrive() and f_chdir() are available.
va009039 0:39eb4d5b97df 119 / 2: f_getcwd() is available in addition to 1.
va009039 0:39eb4d5b97df 120 /
va009039 0:39eb4d5b97df 121 / Note that output of the f_readdir fnction is affected by this option. */
va009039 0:39eb4d5b97df 122
va009039 0:39eb4d5b97df 123
va009039 0:39eb4d5b97df 124
va009039 0:39eb4d5b97df 125 /*---------------------------------------------------------------------------/
va009039 0:39eb4d5b97df 126 / Physical Drive Configurations
va009039 0:39eb4d5b97df 127 /----------------------------------------------------------------------------*/
va009039 0:39eb4d5b97df 128
va009039 0:39eb4d5b97df 129 #define _VOLUMES 1
va009039 0:39eb4d5b97df 130 /* Number of volumes (logical drives) to be used. */
va009039 0:39eb4d5b97df 131
va009039 0:39eb4d5b97df 132
va009039 0:39eb4d5b97df 133 #define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */
va009039 0:39eb4d5b97df 134 /* Maximum sector size to be handled.
va009039 0:39eb4d5b97df 135 / Always set 512 for memory card and hard disk but a larger value may be
va009039 0:39eb4d5b97df 136 / required for on-board flash memory, floppy disk and optical disk.
va009039 0:39eb4d5b97df 137 / When _MAX_SS is larger than 512, it configures FatFs to variable sector size
va009039 0:39eb4d5b97df 138 / and GET_SECTOR_SIZE command must be implememted to the disk_ioctl function. */
va009039 0:39eb4d5b97df 139
va009039 0:39eb4d5b97df 140
va009039 0:39eb4d5b97df 141 #define _MULTI_PARTITION 0 /* 0:Single partition, 1/2:Enable multiple partition */
va009039 0:39eb4d5b97df 142 /* When set to 0, each volume is bound to the same physical drive number and
va009039 0:39eb4d5b97df 143 / it can mount only first primaly partition. When it is set to 1, each volume
va009039 0:39eb4d5b97df 144 / is tied to the partitions listed in VolToPart[]. */
va009039 0:39eb4d5b97df 145
va009039 0:39eb4d5b97df 146
va009039 0:39eb4d5b97df 147 #define _USE_ERASE 0 /* 0:Disable or 1:Enable */
va009039 0:39eb4d5b97df 148 /* To enable sector erase feature, set _USE_ERASE to 1. CTRL_ERASE_SECTOR command
va009039 0:39eb4d5b97df 149 / should be added to the disk_ioctl functio. */
va009039 0:39eb4d5b97df 150
va009039 0:39eb4d5b97df 151
va009039 0:39eb4d5b97df 152
va009039 0:39eb4d5b97df 153 /*---------------------------------------------------------------------------/
va009039 0:39eb4d5b97df 154 / System Configurations
va009039 0:39eb4d5b97df 155 /----------------------------------------------------------------------------*/
va009039 0:39eb4d5b97df 156
va009039 0:39eb4d5b97df 157 #define _WORD_ACCESS 0 /* 0 or 1 */
va009039 0:39eb4d5b97df 158 /* Set 0 first and it is always compatible with all platforms. The _WORD_ACCESS
va009039 0:39eb4d5b97df 159 / option defines which access method is used to the word data on the FAT volume.
va009039 0:39eb4d5b97df 160 /
va009039 0:39eb4d5b97df 161 / 0: Byte-by-byte access.
va009039 0:39eb4d5b97df 162 / 1: Word access. Do not choose this unless following condition is met.
va009039 0:39eb4d5b97df 163 /
va009039 0:39eb4d5b97df 164 / When the byte order on the memory is big-endian or address miss-aligned word
va009039 0:39eb4d5b97df 165 / access results incorrect behavior, the _WORD_ACCESS must be set to 0.
va009039 0:39eb4d5b97df 166 / If it is not the case, the value can also be set to 1 to improve the
va009039 0:39eb4d5b97df 167 / performance and code size.
va009039 0:39eb4d5b97df 168 */
va009039 0:39eb4d5b97df 169
va009039 0:39eb4d5b97df 170
va009039 0:39eb4d5b97df 171 /* A header file that defines sync object types on the O/S, such as
va009039 0:39eb4d5b97df 172 / windows.h, ucos_ii.h and semphr.h, must be included prior to ff.h. */
va009039 0:39eb4d5b97df 173
va009039 0:39eb4d5b97df 174 #define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */
va009039 0:39eb4d5b97df 175 #define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */
va009039 0:39eb4d5b97df 176 #define _SYNC_t HANDLE /* O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc.. */
va009039 0:39eb4d5b97df 177
va009039 0:39eb4d5b97df 178 /* The _FS_REENTRANT option switches the reentrancy (thread safe) of the FatFs module.
va009039 0:39eb4d5b97df 179 /
va009039 0:39eb4d5b97df 180 / 0: Disable reentrancy. _SYNC_t and _FS_TIMEOUT have no effect.
va009039 0:39eb4d5b97df 181 / 1: Enable reentrancy. Also user provided synchronization handlers,
va009039 0:39eb4d5b97df 182 / ff_req_grant, ff_rel_grant, ff_del_syncobj and ff_cre_syncobj
va009039 0:39eb4d5b97df 183 / function must be added to the project. */
va009039 0:39eb4d5b97df 184
va009039 0:39eb4d5b97df 185
va009039 0:39eb4d5b97df 186 #define _FS_LOCK 0 /* 0:Disable or >=1:Enable */
va009039 0:39eb4d5b97df 187 /* To enable file lock control feature, set _FS_LOCK to 1 or greater.
va009039 0:39eb4d5b97df 188 The value defines how many files can be opened simultaneously. */
va009039 0:39eb4d5b97df 189
va009039 0:39eb4d5b97df 190
va009039 0:39eb4d5b97df 191 #endif /* _FFCONFIG */