Skip to content

Commit 72dae26

Browse files
committed
USBHOST : test mass storage
1 parent 14153dc commit 72dae26

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "mbed.h"
2+
#include "USBHostMSD.h"
3+
DigitalOut led(LED1);
4+
void msd_task(void const *) {
5+
printf("init msd\n");
6+
USBHostMSD msd("usb");
7+
int i = 0;
8+
printf("wait for usb memory stick insertion\n");
9+
while(1) {
10+
11+
// try to connect a MSD device
12+
while(!msd.connect()) {
13+
Thread::wait(500);
14+
}
15+
16+
// in a loop, append a file
17+
// if the device is disconnected, we try to connect it again
18+
19+
// append a file
20+
FILE * fp = fopen("/usb/test1.txt", "a");
21+
22+
if (fp != NULL) {
23+
fprintf(fp, "Hello fun SD Card World: %d!\r\n", i++);
24+
printf("Goodbye World!\r\n");
25+
fclose(fp);
26+
} else {
27+
printf("FILE == NULL\r\n");
28+
}
29+
Thread::wait(500);
30+
printf("again\n");
31+
// if device disconnected, try to connect again
32+
while (msd.connected()) {
33+
Thread::wait(500);
34+
}
35+
}
36+
}
37+
38+
int main() {
39+
Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4);
40+
while(1) {
41+
led=!led;
42+
Thread::wait(500);
43+
}
44+
}

tools/tests.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,8 @@
977977
"supported": CORTEX_ARM_SUPPORT,
978978
},
979979

980-
# USB Tests
980+
# USB Tests
981+
# USB device test list
981982
{
982983
"id": "USB_1", "description": "Mouse",
983984
"source_dir": join(TEST_DIR, "usb", "device", "basic"),
@@ -1018,6 +1019,12 @@
10181019
"source_dir": join(TEST_DIR, "usb", "device", "audio_cb"),
10191020
"dependencies": [MBED_LIBRARIES, USB_LIBRARIES],
10201021
},
1022+
# USB host test list
1023+
{
1024+
"id": "USB_10", "description": "MSD",
1025+
"source_dir": join(TEST_DIR, "usb", "host", "mass_storage"),
1026+
"dependencies": [MBED_LIBRARIES, USB_HOST_LIBRARIES, FAT_FS, RTOS],
1027+
},
10211028

10221029
# CMSIS DSP
10231030
{

0 commit comments

Comments
 (0)