@@ -54,19 +54,23 @@ static void ifaceSetupHook(unsigned, void*);
5454 */
5555
5656#define USB_TIMEOUT 50
57-
57+ # if BOARD_HAVE_SERIALUSB
5858bool USBSerial::_hasBegun = false ;
59+ #endif
60+
5961USBSerial::USBSerial (void ) {
6062#if !BOARD_HAVE_SERIALUSB
6163 ASSERT (0 );
6264#endif
6365}
6466
6567void USBSerial::begin (void ) {
68+
69+ #if BOARD_HAVE_SERIALUSB
6670 if (_hasBegun)
6771 return ;
6872 _hasBegun = true ;
69- # if BOARD_HAVE_SERIALUSB
73+
7074 usb_cdcacm_enable (BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
7175 usb_cdcacm_set_hooks (USB_CDCACM_HOOK_RX, rxHook);
7276 usb_cdcacm_set_hooks (USB_CDCACM_HOOK_IFACE_SETUP, ifaceSetupHook);
@@ -79,6 +83,7 @@ void USBSerial::begin(unsigned long ignoreBaud)
7983volatile unsigned long removeCompilerWarningsIgnoreBaud=ignoreBaud;
8084
8185 ignoreBaud=removeCompilerWarningsIgnoreBaud;
86+ begin ();
8287}
8388void USBSerial::begin (unsigned long ignoreBaud, uint8_t ignore)
8489{
@@ -87,14 +92,16 @@ volatile uint8_t removeCompilerWarningsIgnore=ignore;
8792
8893 ignoreBaud=removeCompilerWarningsIgnoreBaud;
8994 ignore=removeCompilerWarningsIgnore;
95+ begin ();
9096}
9197
9298void USBSerial::end (void ) {
9399#if BOARD_HAVE_SERIALUSB
94100 usb_cdcacm_disable (BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
95101 usb_cdcacm_remove_hooks (USB_CDCACM_HOOK_RX | USB_CDCACM_HOOK_IFACE_SETUP);
102+ _hasBegun = false ;
96103#endif
97- _hasBegun = false ;
104+
98105}
99106
100107size_t USBSerial::write (uint8 ch) {
0 commit comments