Arduino Forum

Products => Arduino Zero => Topic started by: luiscoll on Apr 23, 2019, 12:44 am

Title: Reported USB max power.
Post by: luiscoll on Apr 23, 2019, 12:44 am
I'm doing an application with a MKRZERO that communicates with a phone via USB, also is powered from the phone. The consuption is not more than 25 mA.
In Android have not problems, the CDC serial port works ok, and the arduino is powered from the phone without problems.
When connected to an iPhone, the phone says "this device needs too much power, diconecting".
Connecting to a PC the command usb-devices says the device reports Max Power = 500 mA.

Code: [Select]

T:  Bus=05 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#= 20 Spd=12  MxCh= 0
D:  Ver= 2.00 Cls=ef(misc ) Sub=02 Prot=01 MxPS=64 #Cfgs=  1
P:  Vendor=2341 ProdID=804f Rev=01.00
S:  Manufacturer=Arduino LLC
S:  Product=Arduino MKRZero
S:  SerialNumber=FDAF4D37514D50364E4A2020FF01221E
C:  #Ifs= 2 Cfg#= 1 Atr=a0 MxPwr=500mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=02 Prot=00 Driver=cdc_acm
I:  If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_acm

This is a USB reported data, not the real used power.
I use a customized bootloader, and in bootloader mode reports 98 mA. because the file sam_ba_usb.c has been modified to report a lower value.
Modifying the file platform.txt to add
Code: [Select]
-DUSB_POWER={build.usb_power} to build.usb_flags and boards.txt to ad
Code: [Select] does not solve the problem, the compile sketch still reports 500 mA.
Is there any way to change this?
Title: Re: Reported USB max power.
Post by: gbafamily on Apr 23, 2019, 08:24 pm
USBCore.h might be the place to look.

Code: [Select]
// bMaxPower in Configuration Descriptor
#define USB_CONFIG_POWER_MA(mA)                ((mA)/2)
 #define USB_CONFIG_POWER                      (500)

Title: Re: Reported USB max power.
Post by: luiscoll on Apr 24, 2019, 10:45 am
Perfect, thats the correct place.
I've changed

Code: [Select]
#define USB_CONFIG_POWER                      (500)


Code: [Select]
#define USB_CONFIG_POWER                      (25)

And now it reports 25 mA. as needed power.
Thanks a lot.  :)