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
Diff: z_example/7_USBMemory.cpp
- Revision:
- 4:0f4affc00183
- Parent:
- 3:35ac9ee7d2d6
--- a/z_example/7_USBMemory.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -// 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 - -#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; - -void msd_task(void const *) -{ - FATFileSystem fsu("usb"); - FILE *fp; - bool usb_memory_run = false; - uint32_t n = 0; - - wait(1.0f); - pc.printf("line:%d\r\n", __LINE__); - while(!msd.connect()) { - pc.printf("line:%d\r\n", __LINE__); - wait_ms(20); - } - pc.printf("line:%d\r\n", __LINE__); - wait(1.0f); - if (msd.connected() == true) { - pc.printf("line:%d\r\n", __LINE__); - wait(1.0f); - if (fsu.mount(&msd) == 0) { - wait(1.0f); - usb_memory_run = true; - pc.printf("line:%d\r\n", __LINE__); - fp = fopen("test1.txt", "a"); - if (fp != 0) { - pc.printf("USBdisk:open test1.txt\r\n"); - usb_memory_run = true; - } else { - pc.printf("Cannot use USB memory\r\n"); - usb_memory_run = false; - } - fclose(fp); - } else { - pc.printf("line:%d\r\n", __LINE__); - } - } else { - pc.printf("Cannot use USB Memory\r\n"); - usb_memory_run = false; - } - while (true) { - pc.printf("line:%d\r\n", __LINE__); - while(msd.connected() == false) { - while(!msd.connect()) { - pc.printf("line:%d\r\n", __LINE__); - wait_ms(20); - } - pc.printf("line:%d\r\n", __LINE__); - } - if (msd.connected() == true) { - pc.printf("line:%d\r\n", __LINE__); - usb_memory_run = true; - if (fsu.mount(&msd) == 0) { - pc.printf("line:%d\r\n", __LINE__); - } else { - pc.printf("line:%d\r\n", __LINE__); - } - } else { - pc.printf("Cannot use USB Memory\r\n"); - usb_memory_run = false; - } - fp = fopen("test1.txt", "a"); - pc.printf("line:%d\r\n", __LINE__); - if(fp == NULL) { - pc.printf("Cannot use USB Memory\r\n"); - pc.printf("FILE == NULL\r\n"); - usb_memory_run = false; - } else { - usb_memory_run = true; - char tmp[100]; - sprintf(tmp,"Hello fun USB stick World: %d!\r\n", n++); - fprintf(fp, tmp); - fclose(fp); - } - ThisThread::sleep_for(2000); - pc.printf("again\r\n"); - } -} - -int main() -{ - 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