Example to show how to use USB Host on the LPC4088 QSB.

Dependencies:   LPC4088-USBHost mbed

Committer:
embeddedartists
Date:
Fri Apr 24 06:13:20 2015 +0000
Revision:
0:5cd11f3b13a2
Example to show USB Host MassStorage

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:5cd11f3b13a2 1 // Simple USBHost MSD(USB Flash drive) for EA LPC4088 QSB test program
embeddedartists 0:5cd11f3b13a2 2 #include "USBHostMSD.h"
embeddedartists 0:5cd11f3b13a2 3
embeddedartists 0:5cd11f3b13a2 4 DigitalOut led1(LED1);
embeddedartists 0:5cd11f3b13a2 5 DigitalOut led2(LED2);
embeddedartists 0:5cd11f3b13a2 6 #define LED_OFF 0
embeddedartists 0:5cd11f3b13a2 7 #define LED_ON 1
embeddedartists 0:5cd11f3b13a2 8
embeddedartists 0:5cd11f3b13a2 9 int main() {
embeddedartists 0:5cd11f3b13a2 10 USBHostMSD msd("usb");
embeddedartists 0:5cd11f3b13a2 11 if (!msd.connect()) {
embeddedartists 0:5cd11f3b13a2 12 error("USB Flash drive not found.\n");
embeddedartists 0:5cd11f3b13a2 13 }
embeddedartists 0:5cd11f3b13a2 14 FILE* fp = fopen("/usb/test1.txt", "a");
embeddedartists 0:5cd11f3b13a2 15 if (fp) {
embeddedartists 0:5cd11f3b13a2 16 fprintf(fp, "Hello from EA LPC4088 QSB\n");
embeddedartists 0:5cd11f3b13a2 17 for(int i = 0; i < 21; i++) {
embeddedartists 0:5cd11f3b13a2 18 fprintf(fp, " %d", i);
embeddedartists 0:5cd11f3b13a2 19 led2 = !led2;
embeddedartists 0:5cd11f3b13a2 20 }
embeddedartists 0:5cd11f3b13a2 21 fprintf(fp, "\n");
embeddedartists 0:5cd11f3b13a2 22 fclose(fp);
embeddedartists 0:5cd11f3b13a2 23 }
embeddedartists 0:5cd11f3b13a2 24 fp = fopen("/usb/test1.txt", "r");
embeddedartists 0:5cd11f3b13a2 25 if (fp) {
embeddedartists 0:5cd11f3b13a2 26 int n = 0;
embeddedartists 0:5cd11f3b13a2 27 while(1) {
embeddedartists 0:5cd11f3b13a2 28 int c = fgetc(fp);
embeddedartists 0:5cd11f3b13a2 29 if (c == EOF) {
embeddedartists 0:5cd11f3b13a2 30 break;
embeddedartists 0:5cd11f3b13a2 31 }
embeddedartists 0:5cd11f3b13a2 32 printf("%c", c);
embeddedartists 0:5cd11f3b13a2 33 n++;
embeddedartists 0:5cd11f3b13a2 34 led1 = !led1;
embeddedartists 0:5cd11f3b13a2 35 }
embeddedartists 0:5cd11f3b13a2 36 fclose(fp);
embeddedartists 0:5cd11f3b13a2 37 printf("%d bytes\n", n);
embeddedartists 0:5cd11f3b13a2 38 }
embeddedartists 0:5cd11f3b13a2 39 led2 = LED_OFF;
embeddedartists 0:5cd11f3b13a2 40 while(1) {
embeddedartists 0:5cd11f3b13a2 41 led1 = !led1;
embeddedartists 0:5cd11f3b13a2 42 wait_ms(200);
embeddedartists 0:5cd11f3b13a2 43 }
embeddedartists 0:5cd11f3b13a2 44 }