Go Down

Topic: Best way to adjust the USB ConfigDescriptor bMaxPower in 1.0.1 on a Leonardo? (Read 1 time) previous topic - next topic


Hi all,
I've been playing with what is ostensibly a Leonardo clone - the Freetronics LeoStick. I've compiled the new Arduino 1.0.1 Caterina bootloader and using the new 1.0.1 USBCore.cpp/.h files etc.

The current USB_CONFIG_POWER_MA Macro used as part of the D_CONFIG macro called out of USBCore.cpp is hardcoded at 500ma.
This can cause errors to appear when plugging the device into many Keyboard based USB Ports or Hubs. I'm lead to believe particularly on MacOSX ?

So I've tried to hack in, unfortunately (I hate modifying core code :( ) the ability to alter this in a sketch, so you can set it in the setup() function. Is this the best way to do this?
This works, and allows you to set any arbitrary integer value to be used for the negotiation of the sketch comport.

Edit USBCore.cpp . Around line 47 or so, you'll see
Code: [Select]
extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM;

Add the line
Code: [Select]
int usbMaxPower = 500;

Edit USBCore.h. Edit the D_CONFIG define around line 284 to be:
Code: [Select]

#define D_CONFIG(_totalLength,_interfaces) \
  { 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED, USB_CONFIG_POWER_MA(usbMaxPower) }

By default, it will now negotiate 500ma. However in your sketch, at the top, define
Code: [Select]
extern int usbMaxPower

Then you can do in setup(), before calling any USB descriptors (i.e, one of the first things)
Code: [Select]
usbMaxPower = 100;

Voila! Script defineable usbMaxPower values... albeit very klunky and involving hacks to the USBCore.cpp/USBCore.h - which I was trying to avoid.

Is this the best way to accomplish this for now with 1.0.1 ?

Checkout my projects development blog @ SLiDA


Checkout my projects development blog @ SLiDA


No comments ?

How many people do you suppose have Leonardos already?
The art of getting good answers lies in asking good questions.


How many people do you suppose have Leonardos already?

I was asking broadly - Theres still a general programming question though ? Anyway.. no worries..
Checkout my projects development blog @ SLiDA

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131