Skip to content

Commit d872cb1

Browse files
committed
avoid multiple USB serial begin (taken from F1)
1 parent f1e2cba commit d872cb1

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

STM32F4/cores/maple/usb_serial.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,25 @@
3636
#ifdef SERIAL_USB
3737

3838
#define USB_TIMEOUT 50
39+
bool USBSerial::_hasBegun = false;
3940

4041
USBSerial::USBSerial(void) {
4142
}
4243

4344
void USBSerial::begin(void) {
45+
if (_hasBegun)
46+
return;
47+
_hasBegun = true;
4448
setupUSB();
4549
}
4650

4751
void USBSerial::begin(int) {
48-
setupUSB();
52+
this->begin();
4953
}
5054

5155
void USBSerial::end(void) {
5256
disableUSB();
57+
_hasBegun = false;
5358
}
5459

5560
size_t USBSerial::write(uint8 ch) {

STM32F4/cores/maple/usb_serial.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class USBSerial : public Stream {
6565

6666
void enableBlockingTx(void);
6767
void disableBlockingTx(void);
68+
69+
protected:
70+
static bool _hasBegun;
6871
};
6972

7073
extern USBSerial SerialUSB;

0 commit comments

Comments
 (0)