Skip to content

Commit 8640830

Browse files
committed
support dropping Serial, add no_serial example
1 parent 1723633 commit 8640830

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

examples/CDC/no_serial/no_serial.ino

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*********************************************************************
2+
Adafruit invests time and resources providing this open source code,
3+
please support Adafruit and open-source hardware by purchasing
4+
products from Adafruit!
5+
6+
MIT license, check LICENSE for more information
7+
Copyright (c) 2019 Ha Thach for Adafruit Industries
8+
All text above, and the splash screen below must be included in
9+
any redistribution
10+
*********************************************************************/
11+
12+
#include "Adafruit_TinyUSB.h"
13+
14+
/* This sketch demonstrates USB CDC Serial can be dropped by simply
15+
* call Serial.end() within setup(). This must be called before any
16+
* other USB interfaces (MSC / HID) begin to have a clean configuration
17+
*
18+
* Note: this will cause device to loose the touch1200 and require
19+
* user manual interaction to put device into bootloader/DFU mode.
20+
*/
21+
22+
int led = LED_BUILTIN;
23+
24+
void setup()
25+
{
26+
Serial.end();
27+
pinMode(led, OUTPUT);
28+
}
29+
30+
void loop()
31+
{
32+
digitalWrite(led, HIGH);
33+
delay(1000);
34+
digitalWrite(led, LOW);
35+
delay(1000);
36+
}

src/arduino/Adafruit_USBD_CDC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void Adafruit_USBD_CDC::begin (uint32_t baud, uint8_t config)
7777

7878
void Adafruit_USBD_CDC::end(void)
7979
{
80-
// nothing to do
80+
USBDevice.clearConfiguration();
8181
}
8282

8383
uint32_t Adafruit_USBD_CDC::baud(void)

src/arduino/Adafruit_USBD_Device.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ void Adafruit_USBD_Device::clearConfiguration(void)
7070
.bDeviceSubClass = 0,
7171
.bDeviceProtocol = 0,
7272
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
73-
.idVendor = 0,
74-
.idProduct = 0,
73+
.idVendor = USB_VID,
74+
.idProduct = USB_PID,
7575
.bcdDevice = 0x0100,
7676
.iManufacturer = STRID_MANUFACTURER,
7777
.iProduct = STRID_PRODUCT,
@@ -225,7 +225,6 @@ uint8_t Adafruit_USBD_Device::getSerialDescriptor(uint16_t* serial_utf16)
225225
bool Adafruit_USBD_Device::begin(uint8_t rhport)
226226
{
227227
clearConfiguration();
228-
setID(USB_VID, USB_PID);
229228

230229
// Serial is always added by default
231230
// Use Interface Association Descriptor (IAD) for CDC

0 commit comments

Comments
 (0)