1st working sample

Files at this revision

API Documentation at this revision

Comitter:
kenjiArai
Date:
Mon Jan 06 10:56:13 2020 +0000
Commit message:
1st working example

Changed in this revision

0_USB_Serial/main.cpp Show annotated file Show diff for this revision Revisions of this file
1_USB_Storage_RW_microSD/main.cpp Show annotated file Show diff for this revision Revisions of this file
2_USB_Mouse/main.cpp Show annotated file Show diff for this revision Revisions of this file
3_USB_Keyboard/main.cpp Show annotated file Show diff for this revision Revisions of this file
check_revision.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
select_example.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c6dea1f647f6 0_USB_Serial/main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/0_USB_Serial/main.cpp	Mon Jan 06 10:56:13 2020 +0000
@@ -0,0 +1,19 @@
+
+//#define EXAMPLE_0_SERIAL
+#ifdef EXAMPLE_0_SERIAL
+
+#include "mbed.h"
+#include "USBSerial.h"
+
+Serial pc(USBTX, USBRX, 115200);
+USBSerial usb_serial;
+
+int main(void){
+    uint32_t num = 0;
+    while(true) {
+        usb_serial.printf("I am a USB virtual serial port: %d\r\n", num++);
+        pc.printf("I am a ST-Link virtual serial port: %d\r\n", num + 10000);
+    }
+}
+
+#endif  // EXAMPLE_0_SERIAL
diff -r 000000000000 -r c6dea1f647f6 1_USB_Storage_RW_microSD/main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/1_USB_Storage_RW_microSD/main.cpp	Mon Jan 06 10:56:13 2020 +0000
@@ -0,0 +1,45 @@
+/*
+ * Mbed Application program
+ *  SD Card & USB on Mbed-os5
+ *
+ * Copyright (c) 2019,'20 Kenji Arai / JH1PJL
+ *  http://www.page.sannet.ne.jp/kenjia/index.html
+ *  https://os.mbed.com/users/kenjiArai/
+ *      Created:    December  31st, 2019
+ *      Revised:    January    6th, 2020
+ */
+
+//#define EXAMPLE_1_MSD
+#ifdef EXAMPLE_1_MSD
+
+//  Include --------------------------------------------------------------------
+#include "mbed.h"
+#include "USBMSD.h"
+#include "SDBlockDevice.h"
+#include "FATFileSystem.h"
+
+//  Definition -----------------------------------------------------------------
+
+//  Constructor ----------------------------------------------------------------
+Serial pc(USBTX, USBRX, 115200);
+SDBlockDevice   sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, 12000000);
+USBMSD usb(&sd);
+
+//  RAM ------------------------------------------------------------------------
+
+//  ROM / Constant data --------------------------------------------------------
+
+//  Function prototypes --------------------------------------------------------
+
+//------------------------------------------------------------------------------
+//  Control Program
+//------------------------------------------------------------------------------
+int main() {
+    pc.printf("Wait for a while and check ");
+    pc.printf("if it is recognized as a drive on your PC.\r\n");
+    while(true) {
+        usb.process();
+    }
+}
+
+#endif  // EXAMPLE_1_MSD
\ No newline at end of file
diff -r 000000000000 -r c6dea1f647f6 2_USB_Mouse/main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/2_USB_Mouse/main.cpp	Mon Jan 06 10:56:13 2020 +0000
@@ -0,0 +1,27 @@
+//#define EXAMPLE_2_MOUSE
+#ifdef EXAMPLE_2_MOUSE
+
+#include "mbed.h"
+#include "USBMouse.h"
+
+USBMouse mouse;
+
+int main() {
+    int16_t x = 0;
+    int16_t y = 0;
+    int32_t radius = 10;
+    int32_t angle = 0;
+
+    while (true) {
+        //will cause mouse to move in a circle
+        x = cos((double)angle*3.14/180.0)*radius;
+        y = sin((double)angle*3.14/180.0)*radius;
+
+        //will move mouse x, y away from its previous position on the screen
+        mouse.move(x, y);
+        angle += 3;
+        ThisThread::sleep_for(1);
+    }
+}
+
+#endif  // EXAMPLE_2_MOUSE
diff -r 000000000000 -r c6dea1f647f6 3_USB_Keyboard/main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3_USB_Keyboard/main.cpp	Mon Jan 06 10:56:13 2020 +0000
@@ -0,0 +1,17 @@
+//#define EXAMPLE_3_KEYBOARD
+#ifdef EXAMPLE_3_KEYBOARD
+
+#include "mbed.h"
+#include "USBKeyboard.h"
+
+USBKeyboard key;
+
+int main(void)
+{
+  while (true) {
+      key.printf("Mbed USBDevice -- Keyboard on mbed-os5.15.0\r\n");
+      ThisThread::sleep_for(1000);
+  }
+}
+
+#endif  // EXAMPLE_3_KEYBOARD
diff -r 000000000000 -r c6dea1f647f6 check_revision.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/check_revision.cpp	Mon Jan 06 10:56:13 2020 +0000
@@ -0,0 +1,21 @@
+/*
+ * Check Mbed revision
+ *
+ * Copyright (c) 2019 Kenji Arai / JH1PJL
+ *  http://www.page.sannet.ne.jp/kenjia/index.html
+ *  https://os.mbed.com/users/kenjiArai/
+ *      Created:    July      17th, 2019
+ *      Revised:    December  24th, 2019
+ */
+
+#include "mbed.h"
+
+//    RUN ONLY ON mbed-os5.15.0
+//      https://github.com/ARMmbed/mbed-os/releases/tag/mbed-os-5.15.0
+#if (MBED_MAJOR_VERSION == 5) &&\
+    (MBED_MINOR_VERSION == 15) &&\
+    (MBED_PATCH_VERSION == 0)
+#else
+    //#warning "Please use Mbed-os5.15.0"
+    #error "Please use Mbed-os5.15.0"
+#endif
\ No newline at end of file
diff -r 000000000000 -r c6dea1f647f6 mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Mon Jan 06 10:56:13 2020 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#64853b354fa188bfe8dbd51e78771213c7ed37f7
diff -r 000000000000 -r c6dea1f647f6 mbed_app.json
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Mon Jan 06 10:56:13 2020 +0000
@@ -0,0 +1,14 @@
+{
+    "config": {
+        "usb_speed": {
+            "help": "USE_USB_OTG_FS or USE_USB_OTG_HS or USE_USB_HS_IN_FS",
+            "value": "USE_USB_OTG_FS"
+        }
+    },
+    "target_overrides": {
+        "*": {
+            "target.components_add": ["SD"],
+            "target.device_has_add": ["USBDEVICE"]
+        }
+    }
+}
diff -r 000000000000 -r c6dea1f647f6 select_example.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/select_example.cpp	Mon Jan 06 10:56:13 2020 +0000
@@ -0,0 +1,52 @@
+/*
+ * STM32F4xx USB Device example programs
+ *
+ * Copyright (c) 2020 Kenji Arai / JH1PJL
+ *  http://www.page.sannet.ne.jp/kenjia/index.html
+ *  https://os.mbed.com/users/kenjiArai/
+ *      Created:    January    4th, 2020
+ *      Revised:    January    6th, 2020
+ */
+
+
+/*
+    You can select several examples as followings.
+    0.  0_USB_Serial
+        Send & Receive data strings via USB port to Host PC
+    1.  1_USB_Storage_RW_microSD
+        Access microSD drive via USB port from Host PC
+    2.  2_USB_Mouse
+        Mouse control for Host PC
+    3.  3_USB_Keyboard
+        Keyboard control for Host PC
+ */
+#define EXAMPLE_NUMBER      2   // select 0 or 3
+
+//----------------- You don't need any modification ----------------------------
+#if EXAMPLE_NUMBER == 0
+    #define EXAMPLE_0_SERIAL
+    #ifdef EXAMPLE_0_SERIAL
+        #include "0_USB_Serial/main.cpp"
+        #warning "Select 0_USB_Serial"
+    #endif
+#elif EXAMPLE_NUMBER == 1
+    #define EXAMPLE_1_MSD
+    #ifdef EXAMPLE_1_MSD
+        #include "1_USB_Storage_RW_microSD/main.cpp"
+        #warning "Select 1_USB_Storage_RW_microSD"
+    #endif
+#elif EXAMPLE_NUMBER == 2
+    #define EXAMPLE_2_MOUSE
+    #ifdef EXAMPLE_2_MOUSE
+        #include "2_USB_Mouse/main.cpp"
+        #warning "Select 2_USB_Mouse"
+    #endif
+#elif EXAMPLE_NUMBER == 3
+    #define EXAMPLE_3_KEYBOARD
+    #ifdef EXAMPLE_3_KEYBOARD
+        #include "3_USB_Keyboard/main.cpp"
+        #warning "Select 3_USB_Keyboard"
+    #endif
+#else
+    #error " Please set 0 to 3 number for EXAMPLE_NUMBER!!"
+#endif