adafruit / adafruit/Adafruit_TinyUSB_Arduino
changing CFG_TUD_CDC from 1 -> 0 compile issues
- Dominant language
- C
- Stars
- 654
- Forks
- 183
- PR merge metrics
- No merged PRs in 30d
Description
### Operating System
Windows 10
### Arduino IDE version
2.3.4
### Board
Feather M0 adalogger (SAMD21)
### ArduinoCore version
1.8.5
### TinyUSB Library version
3.4.1
### Sketch as ATTACHED TXT
-
### Compiled Log as ATTACHED TXT
several compile issue. Really sorry I didn't keep them, but easy to reproduce and probably a little expected. More constructive info below.
### What happened ?
-
### How to reproduce ?
To the motivation: between CFG_TUD_CDC==0 and the CFG_TUD_HID==1 (I changed them at the same time. shouldn't have ...) I save 7kB to flash so I felt it was worth reporting.
Sorry, my TinyUSB library code is a little butchered by now, so I can't make a pretty pull request. But here are the fixes (all via #if/#endif).
Adafruit_tinyUSB.h, line 40: (this fixes a C linkage error)
```
#if CFG_TUD_CDC
#include "arduino/Adafruit_USBD_CDC.h"
#else
#include "Adafruit_TinyUSB_API.h" // usually, Adafruit_USBD_CDC.h would include this. but without CFG_TUD_CDC ...
#endif
```
Adafruit_USBD_Device.cpp, line 273. must prevent access to SerialTinyUSB
```
#if CFG_TUD_CDC
SerialTinyUSB.begin(115200);
#endif
```
Adafruit_TinyUSB_API.cpp, line 53. Keep body of FlushCDC empty
```
#if CFG_TUD_CDC
uint8_t const cdc_instance = Adafruit_USBD_CDC::getInstanceCount();
for (uint8_t instance = 0; instance < cdc_instance; instance++) {
tud_cdc_n_write_flush(instance);
}
#endif
```
Just my suggestions. Hope this helps.
### Debug Log
_No response_
### Screenshots
_No response_
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the compile failures on the Feather M0 with CFG_TUD_CDC set to 0, then inspect the conditional paths in Adafruit_tinyUSB.h around line 40, Adafruit_USBD_Device.cpp around line 273, and Adafruit_TinyUSB_API.cpp around line 53. Confirm the suggested guards resolve compilation without CDC while preserving the existing CDC-enabled build.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- build-system, embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100