![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Working version on STM32F411. Test for CLI
Dependencies: FATFileSystem mbed-rtos mbed
Fork of USBHost by
main.cpp@41:4b9ff677f582, 2017-09-29 (annotated)
- Committer:
- stema
- Date:
- Fri Sep 29 12:47:27 2017 +0000
- Revision:
- 41:4b9ff677f582
Working version. Test for CLI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stema | 41:4b9ff677f582 | 1 | #include "mbed.h" |
stema | 41:4b9ff677f582 | 2 | #include "USBHostMSD.h" |
stema | 41:4b9ff677f582 | 3 | |
stema | 41:4b9ff677f582 | 4 | DigitalOut led(LED1); |
stema | 41:4b9ff677f582 | 5 | DigitalOut debug_pin(A5); |
stema | 41:4b9ff677f582 | 6 | |
stema | 41:4b9ff677f582 | 7 | void msd_task(void const*) |
stema | 41:4b9ff677f582 | 8 | { |
stema | 41:4b9ff677f582 | 9 | USBHostMSD msd("usb"); |
stema | 41:4b9ff677f582 | 10 | int i = 0; |
stema | 41:4b9ff677f582 | 11 | |
stema | 41:4b9ff677f582 | 12 | debug_pin = 0; |
stema | 41:4b9ff677f582 | 13 | |
stema | 41:4b9ff677f582 | 14 | while(1) |
stema | 41:4b9ff677f582 | 15 | { |
stema | 41:4b9ff677f582 | 16 | // try to connect a MSD device |
stema | 41:4b9ff677f582 | 17 | while(!msd.connect()) |
stema | 41:4b9ff677f582 | 18 | { |
stema | 41:4b9ff677f582 | 19 | Thread::wait(500); |
stema | 41:4b9ff677f582 | 20 | printf("Waiting for USB stick..\n"); |
stema | 41:4b9ff677f582 | 21 | } |
stema | 41:4b9ff677f582 | 22 | |
stema | 41:4b9ff677f582 | 23 | FILE* fp = fopen("/usb/my_test.txt", "w"); |
stema | 41:4b9ff677f582 | 24 | |
stema | 41:4b9ff677f582 | 25 | while(1) |
stema | 41:4b9ff677f582 | 26 | { |
stema | 41:4b9ff677f582 | 27 | if(fp != NULL) |
stema | 41:4b9ff677f582 | 28 | { |
stema | 41:4b9ff677f582 | 29 | debug_pin = 1; |
stema | 41:4b9ff677f582 | 30 | |
stema | 41:4b9ff677f582 | 31 | fprintf(fp, "Hello, SD Card World: that's the string number %d!\r\n", i++); |
stema | 41:4b9ff677f582 | 32 | //printf("Goodbye World!\r\n"); |
stema | 41:4b9ff677f582 | 33 | //fclose(fp); |
stema | 41:4b9ff677f582 | 34 | |
stema | 41:4b9ff677f582 | 35 | debug_pin = 0; |
stema | 41:4b9ff677f582 | 36 | } |
stema | 41:4b9ff677f582 | 37 | else |
stema | 41:4b9ff677f582 | 38 | { |
stema | 41:4b9ff677f582 | 39 | printf("FILE == NULL\r\n"); |
stema | 41:4b9ff677f582 | 40 | } |
stema | 41:4b9ff677f582 | 41 | |
stema | 41:4b9ff677f582 | 42 | Thread::wait(10); |
stema | 41:4b9ff677f582 | 43 | |
stema | 41:4b9ff677f582 | 44 | // if device disconnected, try to connect again |
stema | 41:4b9ff677f582 | 45 | //if(!msd.connected()) |
stema | 41:4b9ff677f582 | 46 | // break; |
stema | 41:4b9ff677f582 | 47 | } |
stema | 41:4b9ff677f582 | 48 | } |
stema | 41:4b9ff677f582 | 49 | } |
stema | 41:4b9ff677f582 | 50 | |
stema | 41:4b9ff677f582 | 51 | |
stema | 41:4b9ff677f582 | 52 | int main() |
stema | 41:4b9ff677f582 | 53 | { |
stema | 41:4b9ff677f582 | 54 | Thread msdTask(msd_task, NULL, osPriorityNormal, 1024*8); |
stema | 41:4b9ff677f582 | 55 | |
stema | 41:4b9ff677f582 | 56 | while(1) |
stema | 41:4b9ff677f582 | 57 | { |
stema | 41:4b9ff677f582 | 58 | led=!led; |
stema | 41:4b9ff677f582 | 59 | Thread::wait(500); |
stema | 41:4b9ff677f582 | 60 | } |
stema | 41:4b9ff677f582 | 61 | } |