Skip to content

changing CFG_TUD_CDC from 1 -> 0 compile issues #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JeffCalwood opened this issue Feb 24, 2025 · 1 comment
Open

changing CFG_TUD_CDC from 1 -> 0 compile issues #497

JeffCalwood opened this issue Feb 24, 2025 · 1 comment
Labels
Bug Something isn't working

Comments

@JeffCalwood
Copy link

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

@JeffCalwood JeffCalwood added the Bug Something isn't working label Feb 24, 2025
@lukescott
Copy link

lukescott commented May 5, 2025

I have been down the rabbit hole on this one. This has been fixed since 3.1.2, but the Adafruit framework includes 3.1.0 and hasn't been updated since 2024. You can try to include Adafruit's TinyUSB as a library, but you'll get duplicate symbols. If you try to #define CFG_TUD_CDC, 3.1.0 will trample your definition and include it anyway.

Your options are basically this:

  1. Call Serial.end() in your setup function. This is by far the easiest. TinyUSB 3.1.0 set it up, you tear it down.
  2. Use master branch of the core framework, something along the lines of this (untested; somewhat from ChatGPT). Last release was 1.17.6 which has 3.1.0.
platform_packages =
  framework-arduino-samd-adafruit @ https://github.com/adafruit/ArduinoCore-samd.git
build_flags =
  -DUSE_TINYUSB

I have tried using TUSB_CONFIG_FILE. Arduino's fork doesn't respect it. I have tried shadowing tusb_config_samd.h providing the exact path, framework include always comes first. I have tried installing TinyUSB as a lib, but can't get past the duplicate symbols.

Only thing that works well enough for my use-case is Serial.end(). And that's because my KVM happens to support full-speed. Apparently a lot of KVM's only support low speed, and apparently that's nearly impossible to change even with the non-forked version because there isn't enough interest.

And ChatGPT's most advance models couldn't even find the Serial.end() solution, I happened upon it on a random form post. Perhaps now it will with this post, after all it did find this issue when I asked if anyone was having a similar problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants