I just realized that when the IDE is compiling a sketch for the ProMicro, all the USB libraries are included even if you don’t use them. Eg. the USB Serial stuff, and the keyboard and mouse HID stuff, is all compiled and included into the sketch regardless of whether there’s a single Serial or Keyboard or Mouse statement in there.
Is there a way to selectively omit the whole USB library? It looks like this might save as much as 3kB of space, which is massive considering the bootloader is already taking 4kB. (In an earlier thread I asked about bypassing the bootloader, but I haven’t had to do that yet - stripping down and optimizing my code and other libraries has kept me under the maximum so far).
Digging into the ProMicro hardware folder, I found that in (sketch folder)/hardware/proMicro/cores/arduino/main.cpp there is an #if that attaches the USB stuff:
#if defined(USBCON)
USB.attach();
#endif
If I comment out those three lines then Verify the sketch, it comes in around 3kB smaller than it does otherwise. For example, the standard “Blink” example, with the USB libraries inluded, reports Binary sketch size: 4360 bytes (of a 28672 byte maximum). When I comment out those lines in main.cpp and reload the sketch, the Blink example drops down to Binary sketch size: 1316 bytes (of a 28672 byte maximum).
The only downside I have found in (limited) testing is that when the USB libraries are omitted, the board does not auto-reset when you try to load a new sketch - you need to manually reset it and time that with hitting the ‘upload’ button in the IDE. This shouldn’t be an issue though as the 1.0.1 version of the IDE & official Leonardo documentation already includes a fairly graceful way to handle the manual-reset if the auto-reset doesn’t work.
I’ve searched all the files in the ProMicro section but I can’t find where USBCON is defined. I found it’s tested in a handful of places, but it doesn’t seem to be defined anywhere. I also searched the Arduino IDE and it doesn’t appear to be defined there either.
So what I am wondering is if there is some way (preferences? board.txt file?) to tell the IDE that the USB libraries are not necessary and should not be included? I can go with manually editing the main.cpp but it seems like there ought to be a friendlier way to specify that the USB libraries are not needed.
Thanks!