Make it possible to drop our power draw.

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?)
pull/18/head
Jesse Vincent 11 years ago
parent 2cd644cbb0
commit 9e42a149b9

@ -45,6 +45,7 @@ extern const u16 STRING_IPRODUCT[] PROGMEM;
extern const u16 STRING_IMANUFACTURER[] PROGMEM; extern const u16 STRING_IMANUFACTURER[] PROGMEM;
extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM; extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM;
extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM; extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM;
int usbMaxPower = 500;
const u16 STRING_LANGUAGE[2] = { const u16 STRING_LANGUAGE[2] = {
(3<<8) | (2+2), (3<<8) | (2+2),

@ -291,7 +291,7 @@ typedef struct
{ 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs } { 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
#define D_CONFIG(_totalLength,_interfaces) \ #define D_CONFIG(_totalLength,_interfaces) \
{ 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED | USB_CONFIG_REMOTE_WAKEUP, USB_CONFIG_POWER_MA(500) } { 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED | USB_CONFIG_REMOTE_WAKEUP, USB_CONFIG_POWER_MA(usbMaxPower) }
#define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \ #define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \
{ 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 } { 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 }

Loading…
Cancel
Save