final
Dependencies: mbed FATFileSystem
Fork of KL46Z-USBHostMSD_HelloWorld by
main.cpp@1:88de0ef4739f, 2014-01-23 (annotated)
- Committer:
- va009039
- Date:
- Thu Jan 23 10:21:32 2014 +0000
- Revision:
- 1:88de0ef4739f
- Parent:
- 0:7012d3c02e58
- Child:
- 2:982b2bbbeda4
update KL46Z-USBHost library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 1:88de0ef4739f | 1 | // Simple USBHost MSD(USB Flash drive) for FRDM-KL46Z test program |
va009039 | 0:7012d3c02e58 | 2 | #include "USBHostMSD.h" |
va009039 | 0:7012d3c02e58 | 3 | |
va009039 | 1:88de0ef4739f | 4 | DigitalOut led1(LED_GREEN); |
va009039 | 1:88de0ef4739f | 5 | DigitalOut led2(LED_RED); |
va009039 | 0:7012d3c02e58 | 6 | #define LED_OFF 1 |
va009039 | 0:7012d3c02e58 | 7 | #define LED_ON 0 |
va009039 | 0:7012d3c02e58 | 8 | |
va009039 | 0:7012d3c02e58 | 9 | int main() { |
va009039 | 0:7012d3c02e58 | 10 | USBHostMSD msd("usb"); |
va009039 | 0:7012d3c02e58 | 11 | |
va009039 | 0:7012d3c02e58 | 12 | FILE* fp = fopen("/usb/test1.txt", "a"); |
va009039 | 0:7012d3c02e58 | 13 | if (fp) { |
va009039 | 0:7012d3c02e58 | 14 | fprintf(fp, "Hello from FRDM-KL46Z\n"); |
va009039 | 1:88de0ef4739f | 15 | for(int i = 0; i < 21; i++) { |
va009039 | 1:88de0ef4739f | 16 | fprintf(fp, " %d", i); |
va009039 | 1:88de0ef4739f | 17 | led2 = !led2; |
va009039 | 1:88de0ef4739f | 18 | } |
va009039 | 1:88de0ef4739f | 19 | fprintf(fp, "\n"); |
va009039 | 0:7012d3c02e58 | 20 | fclose(fp); |
va009039 | 0:7012d3c02e58 | 21 | } |
va009039 | 0:7012d3c02e58 | 22 | fp = fopen("/usb/test1.txt", "r"); |
va009039 | 0:7012d3c02e58 | 23 | if (fp) { |
va009039 | 1:88de0ef4739f | 24 | int n = 0; |
va009039 | 0:7012d3c02e58 | 25 | while(1) { |
va009039 | 0:7012d3c02e58 | 26 | int c = fgetc(fp); |
va009039 | 0:7012d3c02e58 | 27 | if (c == EOF) { |
va009039 | 0:7012d3c02e58 | 28 | break; |
va009039 | 0:7012d3c02e58 | 29 | } |
va009039 | 0:7012d3c02e58 | 30 | printf("%c", c); |
va009039 | 1:88de0ef4739f | 31 | n++; |
va009039 | 1:88de0ef4739f | 32 | led1 = !led1; |
va009039 | 0:7012d3c02e58 | 33 | } |
va009039 | 0:7012d3c02e58 | 34 | fclose(fp); |
va009039 | 1:88de0ef4739f | 35 | printf("%d bytes\n", n); |
va009039 | 0:7012d3c02e58 | 36 | } |
va009039 | 0:7012d3c02e58 | 37 | led2 = LED_OFF; |
va009039 | 0:7012d3c02e58 | 38 | while(1) { |
va009039 | 0:7012d3c02e58 | 39 | led1 = !led1; |
va009039 | 0:7012d3c02e58 | 40 | wait_ms(200); |
va009039 | 0:7012d3c02e58 | 41 | } |
va009039 | 0:7012d3c02e58 | 42 | } |