Several examples run on only mbed-os5.13.0 (not 5.14.0)
Dependencies: BD_SD_DISCO_F769NI BSP_DISCO_F769NI LCD_DISCO_F769NI TS_DISCO_F769NI USBHost_F769NI
z_example/7_USBMemory_copy0.cpp
- Committer:
- kenjiArai
- Date:
- 2019-08-07
- Revision:
- 3:35ac9ee7d2d6
File content as of revision 3:35ac9ee7d2d6:
// Original // https://os.mbed.com/users/jeonbc/code/stm32-disco-example/ // // Modified by K.Arai // July 25th, 2019 // #include "select_program.h" //#define EXAMPLE_7_USB_MSD //#ifdef EXAMPLE_7_USB_MSD #if 0 #include <stdlib.h> #include "mbed.h" #include "LCD_DISCO_F769NI.h" #include "USBHostMSD.h" #include "FATFileSystem.h" LCD_DISCO_F769NI lcd; DigitalOut led_green(LED1); DigitalOut led_orange(LED2); DigitalOut led_red(LED3); DigitalOut led_blue(LED4); Serial pc(SERIAL_TX, SERIAL_RX, 115200); USBHostMSD msd; FATFileSystem fs("usb"); void msd_task(void const *) { int i = 0; int err; printf("wait for usb memory stick insertion\r\n"); while(1) { //pc.printf("line:%d\r\n", __LINE__); wait_ms(500); // try to connect a MSD device while(!msd.connect()) { pc.printf("line:%d\r\n", __LINE__); wait_ms(500); } if (fs.mount(&msd) != 0) { pc.printf("line:%d\r\n", __LINE__); continue; } else { pc.printf("file system mounted\n"); } pc.printf("line:%d\r\n", __LINE__); if (!msd.connect()) { pc.printf("line:%d\r\n", __LINE__); continue; } // in a loop, append a file // if the device is disconnected, we try to connect it again // append a file File file; err = file.open(&fs, "test1.txt", O_WRONLY | O_CREAT |O_APPEND); pc.printf("line:%d\r\n", __LINE__); if (err == 0) { char tmp[100]; sprintf(tmp,"Hello fun USB stick World: %d!\r\n", i++); file.write(tmp,strlen(tmp)); sprintf(tmp,"Goodbye World!\r\n"); file.write(tmp,strlen(tmp)); file.close(); } else { pc.printf("FILE == NULL\r\n"); } ThisThread::sleep_for(500); pc.printf("again\n"); // if device disconnected, try to connect again while (msd.connected()) { wait_ms(500); } while (fs.unmount() < 0) { wait_ms(500); pc.printf("unmount\n"); } } } int main() { pc.baud(115200); pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", __FILE__, __DATE__, __TIME__); lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"MBED EXAMPLE", CENTER_MODE); ThisThread::sleep_for(500); Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 6); pc.printf("line:%d\r\n", __LINE__); lcd.Clear(LCD_COLOR_BLUE); lcd.SetBackColor(LCD_COLOR_BLUE); lcd.SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetFont(&Font24); lcd.DisplayStringAt(0, LINE(7), (uint8_t *)"HAVE FUN !!!", CENTER_MODE); while(true) { // WARNING: LEDs are OFF led_green = 1; led_orange = 1; led_red = 1; led_blue = 1; ThisThread::sleep_for(200); // WARNING: LEDs are ON led_green = 0; led_orange = 0; led_red = 0; led_blue = 0; ThisThread::sleep_for(1000); } } #endif