Skip to content

Commit 0b0520d

Browse files
jamike0xc0170
authored andcommitted
USBHOST : test mass storage
1 parent 56cdad3 commit 0b0520d

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
@@ -978,7 +978,8 @@
978978
"supported": CORTEX_ARM_SUPPORT,
979979
},
980980

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

10231030
# CMSIS DSP
10241031
{

0 commit comments

Comments
 (0)