|
| 1 | +# MSC File Explorer (FreeRTOS) |
| 2 | + |
| 3 | +This host example implements an interactive command-line file browser for USB Mass Storage devices. |
| 4 | +When a USB flash drive is connected, the device is automatically mounted using FatFS and a shell-like |
| 5 | +CLI is presented over the board's serial console. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- Automatic mount/unmount of USB storage devices |
| 10 | +- FAT12/16/32 filesystem support via FatFS |
| 11 | +- Interactive CLI with command history |
| 12 | +- Read speed benchmarking with `dd` |
| 13 | +- Support for up to 4 simultaneous USB storage devices (via hub) |
| 14 | + |
| 15 | +## Supported Commands |
| 16 | + |
| 17 | +| Command | Usage | Description | |
| 18 | +|---------|--------------------|------------------------------------------------------| |
| 19 | +| help | `help` | Print list of available commands | |
| 20 | +| cat | `cat <file>` | Print file contents to the console | |
| 21 | +| cd | `cd <dir>` | Change current working directory | |
| 22 | +| cp | `cp <src> <dest>` | Copy a file | |
| 23 | +| dd | `dd [count]` | Read sectors and report speed (default 1024 sectors) | |
| 24 | +| ls | `ls [dir]` | List directory contents | |
| 25 | +| pwd | `pwd` | Print current working directory | |
| 26 | +| mkdir | `mkdir <dir>` | Create a directory | |
| 27 | +| mv | `mv <src> <dest>` | Rename/move a file or directory | |
| 28 | +| rm | `rm <file>` | Remove a file | |
| 29 | + |
| 30 | +## Build |
| 31 | + |
| 32 | +Build for a specific board using CMake (see [Getting Started](https://docs.tinyusb.org/en/latest/getting_started.html)): |
| 33 | + |
| 34 | +```bash |
| 35 | +# Example: build for STM32F407 Discovery board |
| 36 | +cmake -B build -DBOARD=stm32f407disco -GNinja examples/host/msc_file_explorer_freertos |
| 37 | +cmake --build build |
| 38 | +``` |
| 39 | + |
| 40 | +## Usage |
| 41 | + |
| 42 | +1. Flash the firmware to your board. |
| 43 | +2. Open a serial terminal (e.g. `minicom`, `screen`, `PuTTY`) at 115200 baud. |
| 44 | +3. Plug a USB flash drive into the board's USB host port. |
| 45 | +4. The device is auto-mounted and the prompt appears: |
| 46 | + |
| 47 | +``` |
| 48 | +TinyUSB MSC File Explorer Example |
| 49 | +
|
| 50 | +Device connected |
| 51 | + Vendor : Kingston |
| 52 | + Product : DataTraveler 2.0 |
| 53 | + Rev : 1.0 |
| 54 | + Capacity: 1.9 GB |
| 55 | +
|
| 56 | +0:/> _ |
| 57 | +``` |
| 58 | + |
| 59 | +### Browsing Files |
| 60 | + |
| 61 | +``` |
| 62 | +0:/> ls |
| 63 | +----a 1234 readme.txt |
| 64 | +d---- 0 photos |
| 65 | +d---- 0 docs |
| 66 | +
|
| 67 | +0:/> cd photos |
| 68 | +0:/photos> ls |
| 69 | +----a 520432 vacation.jpg |
| 70 | +----a 312088 family.png |
| 71 | +
|
| 72 | +0:/> cat readme.txt |
| 73 | +Hello from USB drive! |
| 74 | +``` |
| 75 | + |
| 76 | +### Copying and Moving Files |
| 77 | + |
| 78 | +``` |
| 79 | +0:/> cp readme.txt backup.txt |
| 80 | +0:/> mv backup.txt docs/backup.txt |
| 81 | +``` |
| 82 | + |
| 83 | +### Measuring Read Speed |
| 84 | + |
| 85 | +``` |
| 86 | +0:/> dd |
| 87 | +Reading 1024 sectors... |
| 88 | + Data speed: 823 KB/s |
| 89 | +``` |
| 90 | + |
| 91 | +### Multiple Devices |
| 92 | + |
| 93 | +When using a USB hub, multiple drives are mounted as `0:`, `1:`, etc. Use the drive prefix to |
| 94 | +navigate between them: |
| 95 | + |
| 96 | +``` |
| 97 | +0:/> cd 1: |
| 98 | +1:/> ls |
| 99 | +``` |
| 100 | + |
| 101 | +## Testing |
| 102 | + |
| 103 | +Build-time validation follows the standard TinyUSB host example flow. Runtime behavior should be |
| 104 | +verified on hardware by attaching an MSC device and exercising CLI commands such as `ls`, `pwd`, |
| 105 | +and `dd`. |
0 commit comments