Based on http://forum.freetronics.com/viewtopic.php?f=27&t=679
Adjusting USB bMaxPower value w/ Arduino 1.0.1
Postby adr1an » Wed May 30, 2012 1:42 pm
Ok, I've not needed this personally, But fractal pointed out in another thread that when plugging the new 1.0.1 sketches into a device that only allows LowPower devices to be attached, an annoying error message is generated in MaxOSX.
By default the sketches are set to negotiate to 500ma for the USB bMaxPower value - this value is part of the USB Standard and sets the maximum amount of current the device should draw. It is part of the spec, but isn't actually reflective of what current the device will draw (an important distinction I guess).
In order to write sketches that work without errors on the Host using the LeoStick w/ Arduino 1.0.1, then you can do the following to enable you to adjust the MaxPower values. Its ugly, and I have no idea what I'm doing, but it works, and compiles without error.
So this works, but no idea if its the best way..
Edit USBCore.cpp . Around line 47 or so, you'll see
CODE: SELECT ALL
extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM;
Add the line
CODE: SELECT ALL
int usbMaxPower = 500;
Edit USBCore.h. Edit the D_CONFIG define around line 284 to be:
CODE: SELECT ALL
{ 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 ALL
extern int usbMaxPower
Then you can do in setup(), before calling any USB descriptors (i.e, one of the first things)
CODE: SELECT ALL
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.
Incidentally - theres a bunch more VID/PID locations I should update I've found, as well as that ugly "Unknown IO" - so will post a fix to that in next day or so.
In the meantime - let me know if the above works - curious how transportable the hack is (it seems to have had almost negligible impact on sketch size too! about 6 bytes?)