spikeyang
spikeyang

Reputation: 690

Set accessory mode fail on Nexus 4

I am trying to learn about Android open accessory, because I am a newbie to ARM programming. So I want to put everything up from bottom, use free open source tools and code.

  1. Compiler: yagarto GNU ARM
  2. NXP LPC1768 demo board: from a company named "waveshare"
  3. USB driver example: NXP hostlite
  4. Android phone is NEXUS 4, Android 4.2.2 version

The reference example NXP hostlite is small and clear. But I can not set accessory correctly in my devised code.

Description:

  1. Inserting detection, and USB reset ---- OK
  2. Read device descriptor ---- OK
  3. Set address to 1, change maximum-pakcet-size to 64 ----- OK
  4. Read protocol, it returns 0x0002 . this means AOA v2 is supported. ----OK
  5. Write identifying string , 5 of them, ----- OK
  6. Set accessory mode. I can see there is a port disconnect and then a port connect interrupt nitification in my Log print-out, ---- so seems this command is also OK
  7. But when I try to read device descriptor now, it returns a Completion code of 5 to me when TD_SETUP is sent out. CC = = 5 means a stall or no response. So I can't judge if the VID, PID is OK or not. ---- Fail

According to AOA protocol, after setting accessory mode, the device would re-enumerate itself.

So my question is: What should I do for re-enumeration?

  1. Wait there until it finish itself; Do I need a delay?
  2. Or reset the device and then read device descriptor again?(I don't think so, because the returned VID/PID are not correct.)
  3. Or any suggestion you would like to share with me.

Upvotes: 0

Views: 758

Answers (1)

spikeyang
spikeyang

Reputation: 690

I found: during reenumeration, a port reset is absolutely needed. Otherwise, it won't work! There is no formal document to mention it. And a friend of mine who is familiar with USB told me a reset will bring the device to the same initial condition. But it's not in this application context. Now I can set to Android Accessory Mode successfully and connect with the NXP AOADemo apk.

Yeah! Next I will change the program on both device and host side. What I need is a little demo.


device descriptor before accessory mode:

00:12

01:01

02:00

03:02

04:00

05:00

06:00

07:40

08:D1

09:18

0A:E1

0B:4E

0C:28

0D:02

0E:01

0F:02

10:03

11:01

device descriptor after enter accessory mode:

00:12

01:01

02:00

03:02

04:00

05:00

06:00

07:40

08:D1

09:18

0A:00

0B:2D

0C:28

0D:02

0E:01

0F:02

10:03

11:01

VID 18D1, PID 2D00. I didn't turn on debug mode, so PID is 2D00, no problem. Not as what they said in another post.

======================================

Configuration descriptor:

-------Parse------------

09

02, configuration descriptor

20

00

01, 1 interface

01, 1 configuration

00

80

FA, Maximum current supply needed 500mA


09

04, interface descriptor

00

00

02, 2 endpoints

FF

FF

00

05


07

05, endpoint descriptor

81 in 1

02, bulk

40, maximum size 64 bytes

00

00


07

05, endpoint descriptor

02 out 2

02, bulk

40, maximum size 64 bytes

00

00

-------end of parse ------

Upvotes: 0

Related Questions