{"id":1463,"date":"2017-12-16T23:13:59","date_gmt":"2017-12-16T22:13:59","guid":{"rendered":"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1463"},"modified":"2018-01-05T23:23:35","modified_gmt":"2018-01-05T22:23:35","slug":"08-f746-demo_usbmschost-stm32f746","status":"publish","type":"page","link":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/stm32f746\/komplette-projekt-liste-stm32f746\/08-f746-demo_usbmschost-stm32f746\/","title":{"rendered":"08-F746-Demo_UsbMscHost (STM32F746)"},"content":{"rendered":"<p><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-previous\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/stm32f746\/komplette-projekt-liste-stm32f746\/07-f746-demo_pacman-stm32f746\/\" title=\"07-F746-Demo_PacMan (STM32F746)\"><span class=\"meta-nav\">\u2190<\/span> 07-F746-Demo_PacMan (STM32F746)<\/a><\/div><\/div><!-- #nav-below --><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-next\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/stm32f746\/komplette-projekt-liste-stm32f746\/09-f746-demo_hid_msc-stm32f746\/\" title=\"09-F746-Demo_HID_MSC (STM32F746)\">09-F746-Demo_HID_MSC (STM32F746) <span class=\"meta-nav\">&rarr;<\/span><\/a><\/div><\/div><!-- #nav-below --><\/p>\n<p>Mit diesem Demo-Projekt wird FATFS auf USB und MMC des STM32F746-Discovery-Board getestet.\u00a0Mehr Infos zu FATFS findet Ihr hier: <a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1414\">14-FATFS-Library (STM32F746)<\/a>.<\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ File     : main.c\r\n\/\/ Datum    : 05.09.2015\r\n\/\/ Version  : 1.1\r\n\/\/ Autor    : UB\r\n\/\/ EMail    : mc-4u(@)t-online.de\r\n\/\/ Web      : www.mikrocontroller-4u.de\r\n\/\/ CPU      : STM32F746\r\n\/\/ Board    : STM32F746-Discovery-Board\r\n\/\/ IDE      : OpenSTM32\r\n\/\/ GCC      : 4.9 2015q2\r\n\/\/ Module   : CubeHAL\r\n\/\/ Funktion : Hauptprogramm\r\n\/\/--------------------------------------------------------------\r\n\r\n\r\n#include \"stm32_ub_system.h\"\r\n#include \"stm32_ub_lcd_480x272.h\"\r\n#include \"stm32_ub_font.h\"\r\n#include \"stm32_ub_usb_msc_host.h\"\r\n#include \"stm32_ub_fatfs.h\"\r\n\r\n\r\n\/\/ Info : to use directory commands in fatfs like \"f_chdir\"\r\n\/\/ you must set the define \"_FS_RPATH\" in \"ffconf.h\" to '1'\r\n\r\n\/\/--------------------------------------------------------------\r\nUSB_MSC_HOST_STATUS_t status;\r\nvoid clearDisplay(void);\r\nvoid usbDemo(void);\r\nvoid mmcDemo(void);\r\nFRESULT makeDirInUSBRoot(void);\r\nFRESULT deleteDirInUSBRoot(void);\r\n\r\nint main(void)\r\n{\r\n  \/\/ init vom System\r\n  UB_System_Init();\r\n\r\n  \/\/ init vom LCD\r\n  UB_LCD_Init();\r\n  UB_LCD_LayerInit_Fullscreen();\r\n  UB_LCD_SetLayer_2();\r\n\r\n  clearDisplay();\r\n\r\n  \/\/ init vom USB als MSC-Host\r\n  UB_USB_MSC_HOST_Init();\r\n\r\n  \/\/ init vom FATFS-System\r\n  UB_Fatfs_Init();\r\n\r\n  while(1) {\r\n    UB_USB_MSC_HOST_Do();\r\n    if(UB_Fatfs_CheckMedia(USB_0)==FATFS_OK) usbDemo();\r\n    if(UB_Fatfs_CheckMedia(MMC_1)==FATFS_OK) mmcDemo();\r\n  }\r\n}\r\n\r\nvoid clearDisplay(void)\r\n{\r\n\tUB_LCD_FillLayer(RGB_COL_GREEN);\r\n\tUB_Font_DrawString(10,20,\"F746 USB-MSC\/SD-MMC-Demo (05.09.2015 \/ UB)\",&amp;Arial_10x15,RGB_COL_RED,RGB_COL_BLACK);\r\n#ifdef USE_USB_FS\r\n\tUB_Font_DrawString(10,60,\"USB-FS at CN13\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\tUB_Font_DrawString(10,120,\"please insert USB-Drive or MMC-Drive...\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n#elif USE_USB_HS\r\n\tUB_Font_DrawString(10,60,\"USB-HS at CN12\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\tUB_Font_DrawString(10,120,\"please insert USB-Drive  or MMC-Drive...\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n#else\r\n\tUB_Font_DrawString(10,60,\"please define USE_USB_FS or USE_USB_HS\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\twhile(1);\r\n#endif\r\n\r\n}\r\n\r\n\r\nvoid usbDemo(void)\r\n{\r\n\tFIL myFile;\r\n\tFATFS_t check;\r\n\r\n\tUB_LCD_FillLayer(RGB_COL_GREEN);\r\n\tUB_Font_DrawString(10,20,\"USB-Demo\",&amp;Arial_10x15,RGB_COL_RED,RGB_COL_BLACK);\r\n\r\n   \t\/\/ Media mounten\r\n   \tif(UB_Fatfs_Mount(USB_0)==FATFS_OK) {\r\n      UB_Font_DrawString(10,60,\"mount ok\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n      \/\/ File zum schreiben im root neu anlegen\r\n      if(UB_Fatfs_OpenFile(&amp;myFile, \"0:\/USB_File.txt\", F_WR_CLEAR)==FATFS_OK) {\r\n        UB_Font_DrawString(10,80,\"file open : USB_File.txt\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n    \t\/\/ ein paar Textzeilen in das File schreiben\r\n        UB_Fatfs_WriteString(&amp;myFile,\"Test der WriteString-Funktion\");\r\n        UB_Fatfs_WriteString(&amp;myFile,\"hier Zeile zwei\");\r\n        check=UB_Fatfs_WriteString(&amp;myFile,\"ENDE\");\r\n        if(check==FATFS_OK) {\r\n        \tUB_Font_DrawString(10,100,\"write in file : ok\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n        }\r\n        else {\r\n        \tUB_Font_DrawString(10,100,\"write in file : error\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n        }\r\n        \/\/ File schliessen\r\n        UB_Fatfs_CloseFile(&amp;myFile);\r\n        UB_Font_DrawString(10,120,\"file closed\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n      }\r\n      \/\/ Media unmounten\r\n      UB_Fatfs_UnMount(USB_0);\r\n      UB_Font_DrawString(10,140,\"device unmounted\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n    }\r\n   \telse UB_Font_DrawString(10,60,\"mount error\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\r\n   \tUB_Font_DrawString(10,200,\"please unplug USB-Device...\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\r\n\tdo {\r\n\t\tstatus=UB_USB_MSC_HOST_Do();\r\n\t}while(status==USB_MSC_DEV_CONNECTED);\r\n\r\n\tclearDisplay();\r\n}\r\n\r\nvoid mmcDemo(void)\r\n{\r\n\tFIL myFile;\r\n\tFATFS_t check;\r\n\r\n\tUB_LCD_FillLayer(RGB_COL_GREEN);\r\n\tUB_Font_DrawString(10,20,\"MMC-Demo\",&amp;Arial_10x15,RGB_COL_RED,RGB_COL_BLACK);\r\n\r\n   \t\/\/ Media mounten\r\n   \tif(UB_Fatfs_Mount(MMC_1)==FATFS_OK) {\r\n      UB_Font_DrawString(10,60,\"mount ok\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n      \/\/ File zum schreiben im root neu anlegen\r\n      if(UB_Fatfs_OpenFile(&amp;myFile, \"1:\/MMC_File.txt\", F_WR_CLEAR)==FATFS_OK) {\r\n        UB_Font_DrawString(10,80,\"file open : MMC_File.txt\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n    \t\/\/ ein paar Textzeilen in das File schreiben\r\n        UB_Fatfs_WriteString(&amp;myFile,\"Test der WriteString-Funktion\");\r\n        UB_Fatfs_WriteString(&amp;myFile,\"hier Zeile zwei\");\r\n        check=UB_Fatfs_WriteString(&amp;myFile,\"ENDE\");\r\n        if(check==FATFS_OK) {\r\n        \tUB_Font_DrawString(10,100,\"write in file : ok\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n        }\r\n        else {\r\n        \tUB_Font_DrawString(10,100,\"write in file : error\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n        }\r\n        \/\/ File schliessen\r\n        UB_Fatfs_CloseFile(&amp;myFile);\r\n        UB_Font_DrawString(10,120,\"file closed\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n      }\r\n      \/\/ Media unmounten\r\n      UB_Fatfs_UnMount(MMC_1);\r\n      UB_Font_DrawString(10,140,\"device unmounted\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n    }\r\n   \telse UB_Font_DrawString(10,60,\"mount error\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\r\n   \tUB_Font_DrawString(10,200,\"please unplug MMC-Device...\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\r\n\tdo {\r\n\t\tUB_USB_MSC_HOST_Do();\r\n\t}while(UB_Fatfs_CheckMedia(MMC_1)==FATFS_OK);\r\n\r\n\tclearDisplay();\r\n}\r\n\r\nFRESULT makeDirInUSBRoot(void)\r\n{\r\n\tFRESULT res=FR_DISK_ERR;\r\n\r\n\tif(UB_Fatfs_CheckMedia(USB_0)==FATFS_OK) {\r\n\t\tif(UB_Fatfs_Mount(USB_0)==FATFS_OK) {\r\n\t\t\t\/\/ make directory in root\r\n\t\t\tres=f_mkdir(\"dir1\");\r\n\r\n\t\t\tUB_Fatfs_UnMount(USB_0);\r\n\t\t}\r\n\t}\r\n\r\n\treturn res;\r\n}\r\n\r\nFRESULT deleteDirInUSBRoot(void)\r\n{\r\n\tFRESULT res=FR_DISK_ERR;\r\n\r\n\tif(UB_Fatfs_CheckMedia(USB_0)==FATFS_OK) {\r\n\t\tif(UB_Fatfs_Mount(USB_0)==FATFS_OK) {\r\n\t\t\t\/\/ delete directory in root\r\n\t\t\tres=f_unlink(\"dir1\");\r\n\r\n\t\t\tUB_Fatfs_UnMount(USB_0);\r\n\t\t}\r\n\t}\r\n\r\n\treturn res;\r\n}\r\n<\/pre>\n<p>Hier der komplette OpenSTM32-Projektordner zum\u00a0Download :<\/p>\n<ul>\n<li><a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2015\/09\/F746_Demo_UsbMscHost.zip\">F746_Demo_UsbMscHost<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Mit diesem Demo-Projekt wird FATFS auf USB und MMC des STM32F746-Discovery-Board getestet.\u00a0Mehr Infos zu FATFS findet Ihr hier: 14-FATFS-Library (STM32F746). \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; \/\/ File : main.c \/\/ Datum : 05.09.2015 \/\/ Version : 1.1 \/\/ Autor : UB \/\/ EMail : &hellip; <a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/stm32f746\/komplette-projekt-liste-stm32f746\/08-f746-demo_usbmschost-stm32f746\/\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1444,"menu_order":8,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[289,130],"tags":[152,174,167,105,95],"class_list":["post-1463","page","type-page","status-publish","hentry","category-demo-projekte","category-stm32f746","tag-fatfs","tag-mmc","tag-projekt","tag-stm32f746","tag-usb"],"_links":{"self":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/pages\/1463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/comments?post=1463"}],"version-history":[{"count":4,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/pages\/1463\/revisions"}],"predecessor-version":[{"id":1884,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/pages\/1463\/revisions\/1884"}],"up":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/pages\/1444"}],"wp:attachment":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/media?parent=1463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/categories?post=1463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/tags?post=1463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}