Skip to content

Commit 4e64f3e

Browse files
authored
Merge pull request #3632 from hathach/msc_os
hcd/dwc2: fix txfifo full check
2 parents dcd2a4b + 3188ed4 commit 4e64f3e

16 files changed

Lines changed: 1739 additions & 71 deletions

File tree

.github/workflows/build.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,15 @@ jobs:
326326
github.repository_owner == 'hathach' &&
327327
!(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true)
328328
runs-on: [ self-hosted, Linux, X64, hifiphile ]
329+
timeout-minutes: 30
329330
env:
330331
IAR_LMS_BEARER_TOKEN: ${{ secrets.IAR_LMS_BEARER_TOKEN }}
332+
PYTHONUNBUFFERED: '1'
331333
steps:
332334
- name: Clean workspace
333335
run: |
334336
echo "Cleaning up previous run"
335-
rm -rf "${{ github.workspace }}"3
337+
rm -rf "${{ github.workspace }}"
336338
mkdir -p "${{ github.workspace }}"
337339
338340
- name: Toolchain version
@@ -356,4 +358,5 @@ jobs:
356358
run: python3 tools/build.py --toolchain iar $BUILD_ARGS
357359

358360
- name: Test on actual hardware (hardware in the loop)
359-
run: python3 test/hil/hil_test.py hfp.json
361+
run: |
362+
python3 test/hil/hil_test.py hfp.json

examples/host/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set(EXAMPLE_LIST
1414
hid_controller
1515
midi_rx
1616
msc_file_explorer
17+
msc_file_explorer_freertos
1718
)
1819

1920
foreach (example ${EXAMPLE_LIST})
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
4+
5+
project(msc_file_explorer_freertos C CXX ASM)
6+
7+
# Checks this example is valid for the family and initializes the project
8+
family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR})
9+
10+
# Espressif has its own cmake build system
11+
if(FAMILY STREQUAL "espressif")
12+
return()
13+
endif()
14+
15+
add_executable(${PROJECT_NAME})
16+
17+
# Example source
18+
target_sources(${PROJECT_NAME} PUBLIC
19+
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
20+
${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c
21+
${TOP}/lib/fatfs/source/ff.c
22+
${TOP}/lib/fatfs/source/ffsystem.c
23+
${TOP}/lib/fatfs/source/ffunicode.c
24+
)
25+
26+
# Example include
27+
target_include_directories(${PROJECT_NAME} PUBLIC
28+
${CMAKE_CURRENT_SOURCE_DIR}/src
29+
${TOP}/lib/fatfs/source
30+
${TOP}/lib/embedded-cli
31+
)
32+
33+
# Configure compilation flags and libraries for the example with FreeRTOS.
34+
# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
35+
family_configure_host_example(${PROJECT_NAME} freertos)
36+
37+
# Suppress warnings on fatfs
38+
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
39+
set_source_files_properties(${TOP}/lib/fatfs/source/ff.c PROPERTIES
40+
COMPILE_OPTIONS "-Wno-conversion;-Wno-cast-qual"
41+
)
42+
endif ()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"version": 6,
3+
"include": [
4+
"../../../hw/bsp/BoardPresets.json"
5+
]
6+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
RTOS = freertos
2+
include ../../../hw/bsp/family_support.mk
3+
4+
FATFS_PATH = lib/fatfs/source
5+
6+
INC += \
7+
src \
8+
$(TOP)/$(FATFS_PATH) \
9+
$(TOP)/lib/embedded-cli \
10+
11+
# Example source
12+
EXAMPLE_SOURCE = \
13+
src/main.c \
14+
src/msc_app.c \
15+
16+
SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
17+
18+
# FatFS source
19+
SRC_C += \
20+
$(FATFS_PATH)/ff.c \
21+
$(FATFS_PATH)/ffsystem.c \
22+
$(FATFS_PATH)/ffunicode.c \
23+
24+
# suppress warning caused by fatfs
25+
CFLAGS += -Wno-error=cast-qual
26+
27+
include ../../../hw/bsp/family_rules.mk
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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`.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
family:espressif
2+
family:samd21
3+
family:samd5x_e5x
4+
mcu:LPC175X_6X
5+
mcu:LPC177X_8X
6+
mcu:LPC18XX
7+
mcu:LPC40XX
8+
mcu:LPC43XX
9+
mcu:LPC54
10+
mcu:LPC55
11+
mcu:MAX3421
12+
mcu:MIMXRT10XX
13+
mcu:MIMXRT11XX
14+
mcu:MIMXRT1XXX
15+
mcu:MSP432E4
16+
mcu:RP2040
17+
mcu:RW61X
18+
mcu:RX65X
19+
mcu:STM32C0
20+
mcu:STM32F4
21+
mcu:STM32F7
22+
mcu:STM32G0
23+
mcu:STM32H5
24+
mcu:STM32H7
25+
mcu:STM32H7RS
26+
mcu:STM32N6
27+
mcu:STM32U3
28+
mcu:STM32U5
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mcu:CH32F20X
2+
board:lpcxpresso54114
3+
mcu:FT90X
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file is for ESP-IDF only
2+
set(FATFS_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../lib/fatfs/source)
3+
set(EMBEDDED_CLI_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../lib/embedded-cli)
4+
5+
idf_component_register(
6+
SRCS "main.c" "msc_app.c"
7+
${FATFS_DIR}/ff.c
8+
${FATFS_DIR}/ffsystem.c
9+
${FATFS_DIR}/ffunicode.c
10+
INCLUDE_DIRS "." ${FATFS_DIR} ${EMBEDDED_CLI_DIR}
11+
REQUIRES boards tinyusb_src)
12+
13+
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error=format)

0 commit comments

Comments
 (0)