{"id":1465,"date":"2017-12-16T23:15:10","date_gmt":"2017-12-16T22:15:10","guid":{"rendered":"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1465"},"modified":"2018-01-05T23:27:39","modified_gmt":"2018-01-05T22:27:39","slug":"09-f746-demo_hid_msc-stm32f746","status":"publish","type":"page","link":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1465","title":{"rendered":"09-F746-Demo_HID_MSC (STM32F746)"},"content":{"rendered":"<p><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-previous\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1463\" title=\"08-F746-Demo_UsbMscHost (STM32F746)\"><span class=\"meta-nav\">\u2190<\/span> 08-F746-Demo_UsbMscHost (STM32F746)<\/a><\/div><\/div><!-- #nav-below --><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-next\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1467\" title=\"10-F746-Demo_UDP_Server (STM32F746)\">10-F746-Demo_UDP_Server (STM32F746) <span class=\"meta-nav\">&rarr;<\/span><\/a><\/div><\/div><!-- #nav-below --><\/p>\n<p>Mit diesem Demo-Projekt wird der USB-DualMode (MSC+HID) des STM32F746-Discovery-Board getestet.<\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ File     : main.c\r\n\/\/ Datum    : 12.07.2015\r\n\/\/ Version  : 1.0\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_hid_host.h\"\r\n#include \"stm32_ub_usb_msc_host.h\"\r\n#include \"stm32_ub_fatfs.h\"\r\n\r\n\/\/--------------------------------------------------------------\r\nUSB_MSC_HOST_STATUS_t msc_status;\r\nUSB_HID_HOST_STATUS_t hid_status;\r\n\r\n\r\nvoid clearDisplay(void);\r\nvoid usbDemo(void);\r\nvoid mouseDemo(void);\r\nvoid keyboardDemo(void);\r\n\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\r\n  \/\/ init USB-HID (USB-FS)\r\n  UB_USB_HID_HOST_Init();\r\n\r\n  \/\/ init USB-MSC (USB-HS)\r\n  UB_USB_MSC_HOST_Init();\r\n  UB_Fatfs_Init();\r\n\r\n  while(1) {\r\n\thid_status=UB_USB_HID_HOST_Do();\r\n    UB_USB_MSC_HOST_Do();\r\n    if(UB_Fatfs_CheckMedia(USB_0)==FATFS_OK) usbDemo();\r\n    if(hid_status==USB_HID_MOUSE_CONNECTED) mouseDemo();\r\n    if(hid_status==USB_HID_KEYBOARD_CONNECTED) keyboardDemo();\r\n\r\n\r\n  }\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\/HID-Demo (09.08.2015 \/ UB)\",&amp;Arial_10x15,RGB_COL_RED,RGB_COL_BLACK);\r\n#ifdef USE_USB_FS\r\n  #ifdef USE_USB_HS\r\n\tUB_Font_DrawString(10,60,\"HID at CN13 and MSC at CN12\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\tUB_Font_DrawString(10,120,\"please insert USB-Drive or USB-Keyboard\/Mouse\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n  #else\r\n\tUB_Font_DrawString(10,60,\"please define USE_USB_FS and USE_USB_HS\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\twhile(1);\r\n  #endif\r\n#else\r\n\tUB_Font_DrawString(10,60,\"please define USE_USB_FS and 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\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\tUB_USB_HID_HOST_Do();\r\n\t\tmsc_status=UB_USB_MSC_HOST_Do();\r\n\t}while(msc_status==USB_MSC_DEV_CONNECTED);\r\n\r\n\tclearDisplay();\r\n}\r\n\r\nvoid mouseDemo(void)\r\n{\r\n\tchar buf[50];\r\n\tuint8_t check;\r\n\r\n\tUB_LCD_FillLayer(RGB_COL_GREEN);\r\n\tUB_Font_DrawString(10,20,\"Mouse-Demo\",&amp;Arial_10x15,RGB_COL_RED,RGB_COL_BLACK);\r\n\tdo {\r\n\t\thid_status=UB_USB_HID_HOST_Do();\r\n\t\tUB_USB_MSC_HOST_Do();\r\n\t\tcheck=UB_USB_HID_HOST_GetMouse();\r\n\t\tif(check&gt;0) {\r\n\t\t  UB_Font_DrawString(10,60,\"Position :\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\t\t  sprintf(buf,\"X= %d , Y= %d    \",USB_MOUSE_DATA.xpos, USB_MOUSE_DATA.ypos);\r\n\t\t  UB_Font_DrawString(10,80,buf,&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\r\n\t\t  UB_Font_DrawString(10,120,\"Buttons :\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\t\t  sprintf(buf,\"1= %d , 2= %d , 3=%d   \",USB_MOUSE_DATA.btn_left, USB_MOUSE_DATA.btn_right , USB_MOUSE_DATA.btn_center);\r\n\t\t  UB_Font_DrawString(10,140,buf,&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\t\t}\r\n\r\n\t}while(hid_status==USB_HID_MOUSE_CONNECTED);\r\n\r\n\tclearDisplay();\r\n}\r\n\r\nvoid keyboardDemo(void)\r\n{\r\n\tuint8_t key;\r\n\tuint16_t xp=0,yp=80;\r\n\r\n\tUB_LCD_FillLayer(RGB_COL_GREEN);\r\n\tUB_Font_DrawString(10,20,\"Keyboard-Demo\",&amp;Arial_10x15,RGB_COL_RED,RGB_COL_BLACK);\r\n\tUB_Font_DrawString(10,60,\"Text :\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\tdo {\r\n\t\thid_status=UB_USB_HID_HOST_Do();\r\n\t\tUB_USB_MSC_HOST_Do();\r\n\t\tkey=UB_USB_HID_HOST_GetKey();\r\n\t\tif((key&gt;=32) &amp;&amp; (key&lt;=128)) { UB_Font_DrawChar(xp,yp,key,&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); xp+=Arial_10x15.width; if(xp&gt;460) {\r\n\t\t\t  xp=0;\r\n\t\t\t  yp+=Arial_10x15.height;\r\n\t\t  }\r\n\t\t}\r\n\r\n\t}while(hid_status==USB_HID_KEYBOARD_CONNECTED);\r\n\r\n\tclearDisplay();\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\/08\/F746_Demo_HID_MSC.zip\">F746_Demo_HID_MSC<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Mit diesem Demo-Projekt wird der USB-DualMode (MSC+HID) des STM32F746-Discovery-Board getestet. \/\/&#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 : 12.07.2015 \/\/ Version : 1.0 \/\/ Autor : UB \/\/ EMail : mc-4u(@)t-online.de \/\/ Web : www.mikrocontroller-4u.de \/\/ CPU : STM32F746 \/\/ &hellip; <a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1465\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1444,"menu_order":9,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[289,130],"tags":[157,158,167,105,95],"class_list":["post-1465","page","type-page","status-publish","hentry","category-demo-projekte","category-stm32f746","tag-hid","tag-msc","tag-projekt","tag-stm32f746","tag-usb"],"_links":{"self":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1465"}],"version-history":[{"count":3,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1465\/revisions"}],"predecessor-version":[{"id":1887,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1465\/revisions\/1887"}],"up":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1444"}],"wp:attachment":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}