Building a USB serial device with STM32F103C8T6 board

Dependencies:   mbed mbed-STM32F103C8T6 USBDevice_STM32F103

Building a USB serial device with STM32F103C8T6 board

A USB device stack has been developed by mbed in order to provide all the great capabilities of USB. The USBdevice class has been extended by Norimasa Okamoto to support also the NUCLEO-F103RB boards (and others). For more information concerning the stack architecture, visit the USBDevice stack architecture.
The USBSerial class uses the USB interface to emulate a serial port. The STM32F103C8T6 board is recognized by the computer as a serial port. This is a great solution to communicate easily between the microcontroller and a computer. The mbed serial port works by default on Mac, Linux and Windows 10, but earlier version of Windows needs a driver. These instructions explain how to setup the mbed Microcontroller to use the USB serial port on Windows 7 and earlier.

Zoom in /media/uploads/hudakz/stm32f103c8t6_usb_serial.jpg

NOTE:

In this application, power the STM32F103C8T6 board over a USB cable connected to the Micro-B USB connector (see in picture above) which you are going to use also for the USB serial communication with the connected PC. Once the binary has been downloaded to the board, disconnect and then reconnect the USB cable to the STM32F103C8T6 board to start running the program and to get the USB serial connection work.

Files at this revision

API Documentation at this revision

Comitter:
hudakz
Date:
Mon May 13 08:42:21 2019 +0000
Parent:
7:bd396db062ea
Commit message:
Updated.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld 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
diff -r bd396db062ea -r 114dbc93d9f7 main.cpp
--- a/main.cpp	Wed Feb 20 12:42:52 2019 +0000
+++ b/main.cpp	Mon May 13 08:42:21 2019 +0000
@@ -1,14 +1,14 @@
-//#include "stm32f103c8t6.h"
+#include "stm32f103c8t6.h"
 #include "mbed.h"
 #include "USBSerial.h"
 
 DigitalOut  myled(LED1);
 
 int main() {
-    //confSysClock();     //Configure system clock (72MHz HSE clock, 48MHz USB clock)
+    confSysClock();     //Configure system clock (72MHz HSE clock, 48MHz USB clock)
     
     Serial    pc(PA_2, PA_3);
-    //USBSerial usbSerial;  // connection is blocked when USB is not plugged in
+//    USBSerial usbSerial;  // connection is blocked when USB is not plugged in
     USBSerial usbSerial(0x1f00, 0x2012, 0x0001,  false);    // connection is not blocked when USB is not plugged in
     
     while(1) {
diff -r bd396db062ea -r 114dbc93d9f7 mbed.bld
--- a/mbed.bld	Wed Feb 20 12:42:52 2019 +0000
+++ b/mbed.bld	Mon May 13 08:42:21 2019 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
diff -r bd396db062ea -r 114dbc93d9f7 mbed_app.json
--- a/mbed_app.json	Wed Feb 20 12:42:52 2019 +0000
+++ b/mbed_app.json	Mon May 13 08:42:21 2019 +0000
@@ -2,7 +2,8 @@
     "target_overrides": {
         "NUCLEO_F103RB": {
             "target.clock_source": "USE_PLL_HSE_XTAL",
-            "target.clock_source_usb": "1"
+            "target.clock_source_usb": "1",
+            "target.default_lib": "small"
         }
     }
 }