summaryrefslogtreecommitdiff
path: root/examples/host/msc_file_explorer/README.md
blob: b80ca8f6cc2d7cf0a614d4fd767659a1e6423ae3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# MSC File Explorer

This host example implements an interactive command-line file browser for USB Mass Storage devices.
When a USB flash drive is connected, the device is automatically mounted using FatFS and a shell-like
CLI is presented over the board's serial console.

## Features

- Automatic mount/unmount of USB storage devices
- FAT12/16/32 filesystem support via FatFS
- Interactive CLI with command history
- Read speed benchmarking with `dd`
- Support for up to 4 simultaneous USB storage devices (via hub)

## Supported Commands

| Command | Usage              | Description                                          |
|---------|--------------------|------------------------------------------------------|
| help    | `help`             | Print list of available commands                     |
| cat     | `cat <file>`       | Print file contents to the console                   |
| cd      | `cd <dir>`         | Change current working directory                     |
| cp      | `cp <src> <dest>`  | Copy a file                                          |
| dd      | `dd [count]`       | Read sectors and report speed (default 1024 sectors) |
| ls      | `ls [dir]`         | List directory contents                              |
| pwd     | `pwd`              | Print current working directory                      |
| mkdir   | `mkdir <dir>`      | Create a directory                                   |
| mv      | `mv <src> <dest>`  | Rename/move a file or directory                      |
| rm      | `rm <file>`        | Remove a file                                        |

## Configuration

Notable `tusb_config.h` settings:

```c
#define CFG_TUH_ENABLED       1
#define CFG_TUH_HUB           1
#define CFG_TUH_MSC           1
#define CFG_TUH_DEVICE_MAX    (3*CFG_TUH_HUB + 1)
#define CFG_TUH_MSC_MAXLUN    4
```

## Build

CMake:

```bash
mkdir build && cd build
cmake -DBOARD=raspberry_pi_pico ..
cmake --build .
```

Make:

```bash
make BOARD=raspberry_pi_pico all
```

## FreeRTOS variant

A FreeRTOS build is in `examples/host/msc_file_explorer_freertos` — identical MSC FatFS file-explorer CLI, running the host stack and CLI as FreeRTOS tasks.

## Usage

1. Flash the firmware to your board.
2. Open a serial terminal (e.g. `minicom`, `screen`, `PuTTY`) at 115200 baud.
3. Plug a USB flash drive into the board's USB host port.
4. The device is auto-mounted and the prompt appears:

```
TinyUSB MSC File Explorer Example

Device connected
  Vendor  : Kingston
  Product : DataTraveler 2.0
  Rev     : 1.0
  Capacity: 1.9 GB

0:/> _
```

### Browsing Files

```
0:/> ls
----a    1234  readme.txt
d----       0  photos
d----       0  docs

0:/> cd photos
0:/photos> ls
----a  520432  vacation.jpg
----a  312088  family.png

0:/> cat readme.txt
Hello from USB drive!
```

### Copying and Moving Files

```
0:/> cp readme.txt backup.txt
0:/> mv backup.txt docs/backup.txt
```

### Measuring Read Speed

```
0:/> dd
Reading 1024 sectors...
  Data speed: 823 KB/s
```

### Multiple Devices

When using a USB hub, multiple drives are mounted as `0:`, `1:`, etc. Use the drive prefix to
navigate between them:

```
0:/> cd 1:
1:/> ls
```

## Testing

This example is part of the TinyUSB HIL (Hardware-in-the-Loop) test suite. The HIL test
automatically flashes, runs the example, and verifies MSC enumeration and file operations
against a known USB drive.