test

Dependents:   Telemetria_RX_SD_GPS_copy Telemetria_RX_SD_GPS Telemetria_TX Telemetria_TX ... more

Revision:
84:3428e25c7157
Parent:
80:62f0b027efff
Child:
88:d120930aeb13
--- a/Arduino-mbed-APIs/arduino-mbed.cpp	Sun Aug 06 14:23:43 2017 +0200
+++ b/Arduino-mbed-APIs/arduino-mbed.cpp	Fri Aug 11 15:11:08 2017 +0200
@@ -12,8 +12,25 @@
 #include "arduino-util.h"
 
 Stream *ser;
-void InitSerial(Stream *serial) {
+bool SerialUSB_active = false;
+
+void InitSerial(Stream *serial, int timeout_ms) {
     ser = serial;
+    if (serial == (Stream *)&SerialUSB) {
+        uint32_t start = ms_getTicker();
+
+        SerialUSB_active = true;
+        while(!SerialUSB) {
+            if (ms_getTicker() > start + timeout_ms) {
+                SerialUSB_active = false;
+                break;
+            }
+        }
+        if (!SerialUSB_active) {
+            USB->DEVICE.CTRLA.bit.SWRST = 1; // disconnect the USB Port
+            while (USB->DEVICE.CTRLA.bit.SWRST == 1);
+        }
+    }
 }
 
 static void pinInt00(void);