Skip to content
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

Made USP-API included flexible #3679

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

NicoHood
Copy link
Contributor

Resolves https://github.com/arduino/Arduino/issues/3675

This also saves us tons of flash and ram for the Leonardo if the CDC Serial/HID is not used.
Example: 3724 flash, 135 ram (with Serial.begin(0)) vs 578 flash, 9 ram without

void setup() { Serial.begin(0); }
void loop() {}

The "downside" is that you need to reset the Leonardo if no USB-Core was compiled. But with the new Serial touch waiting this is not a problem. Maybe an additional note like "If your Leonardo board does not show up, reset it NOW." could easily solve this.

This PR would save us a lot of flash + ram AND USB caused problems (like unneded time consuming USB ISR Interrupts).

Edit: I updated the PR this way:

  • For the current bootloader everything is the same as before
  • For newer bootloaders (with the BOOTKEY fix) the USB-Core will only be included if its needed.
  • This way we can avoid any USB Clock workaround which would add more not wanted bytes.

The positive thing is that newer bootloaders are more save (Bootkey position, all registers cleared) and compile smaller (with this PR). And if the old bootloader is used nothing changes.

Only for newer bootloader

There is also a problem that if no USB-Core is used, the Led blink example wont work correctly with the current bootloader. This is caused by a bad coded bootloader which does not fully reset the MCU via watchdog and leaves the USB-Clock configured. You need a workaround to fix this (not included in this PR yet). HoodLoader2 already includes this (if you want to see it in action, v2.0.5 available for 32u4 as well!).

The Workaround is not so easy to add in this flexible setup. In my case I let the user choose with/without USB-Core. Thatswhy I only enabled it for fixed bootloaders to avoid flash consuming workarounds. So old bootloaders still work, but newer can use this feature.

Updating the bootloader can fix:

So a new bootloader would really solve some issues and makes sense to me. Especially clearing all registers via watchdog and using a proper BOOTKEY position can solve unexpected problems. (if you code a new bootloader make sure to use the lufa master, since it contains an important USB-HUB fix.)

You then could provide a simple bootloader burning sketch to flash the new bootloader with a 2nd arduino (to avoid confusing about ISP, capacitor etc).

Questions

  • This PR used the weak setupUSB() function. It was not used as far as I see. Is there any reason?
  • Do I need to declare a prototype of the setupUSB() in USBAPI.h again or does this cause more problems because of the weak definition in main.cpp?

cc @facchinm

@cmaglie cmaglie added Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) Component: USB Device Opposed to USB Host. Related to the USB subsystem (SerialUSB, HID, ...) USB: CDC serial Serial interface used by MCUs with native USB (e.g. Leonardo) to communicate with the computer feature request A request to make an enhancement (not a bug fix) labels Aug 17, 2015
@NicoHood
Copy link
Contributor Author

May anyone review this PR?
With arduino/arduino-builder#15 one could dynamically disable the USB-Core if needed. This keeps the USB-Core for beginners but can be still disabled also for leonardo boards. (The problem with the unfixed USB Clock bootloader is still there, but professional users should be aware of that)

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) Component: USB Device Opposed to USB Host. Related to the USB subsystem (SerialUSB, HID, ...) feature request A request to make an enhancement (not a bug fix) USB: CDC serial Serial interface used by MCUs with native USB (e.g. Leonardo) to communicate with the computer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants