problem with lib_usb on XEF232-1024 Topic is solved

New to XMOS and XCore? Get started here.
plex
Member++
Posts: 22
Joined: Fri Aug 12, 2016 6:13 pm

problem with lib_usb on XEF232-1024

Post by plex »

Hi,
I was prototyping a project on the xCore-200 Explorer and successfully using the USB on tile1.

Now I am porting the project on the XEF232-1024 on my own board and I get a error when compiling which I cannot seem to resolve.
Analyzing XUD_DeviceAttach.xc
C:/Users/John/workspace/lib_usb/xudlib/XUD_DeviceAttach.xc:23:16: error: conflicting types for 'usb_tile'
extern tileref USB_TILE_REF;
^~~~~~~~~~~~
C:/Users/John/workspace/lib_usb/xudlib\XUD_USB_Defines.h:7:22: note: expanded from macro 'USB_TILE_REF'
#define USB_TILE_REF usb_tile


The only thing that I find relevant but do not know how to fix it is in the XN files where the xCore200Explorer has a declaration "tileref usb_tile" and the XEF232 has a declaration "tileref usb_tile[2]".
I am using tools 14.2.1 and the XEF232 xn file is from this version of tools.
lib_usb is version 3.1.2.
In the make file for both cases I have these flags:"-DXUD_SERIES_SUPPORT=XUD_X200_SERIES -DUSB_TILE=tile[1]"
Thank you in advance


View Solution
User avatar
aneves
Experienced Member
Posts: 93
Joined: Wed Sep 16, 2015 2:38 pm

Post by aneves »

I've never used the XEF232 but looks like it has 2 USB PHYs. The usb library is expecting only one USB PHY and explicitly defines it at XUD_USB_Defines.h on line 7:

Code: Select all

#define USB_TILE_REF usb_tile
Try changing that to this:

Code: Select all

#ifndef USB_TILE_REF
#define USB_TILE_REF usb_tile
#endif
and in your makefile change your flags from this

Code: Select all

-DXUD_SERIES_SUPPORT=XUD_X200_SERIES -DUSB_TILE=tile[1]
to this

Code: Select all

-DXUD_SERIES_SUPPORT=XUD_X200_SERIES -DUSB_TILE_REF=usb_tile[1]
assuming the 2nd USB tile (usb_tile[1]) is the usb PHY you are targeting.
henk
Respected Member
Posts: 347
Joined: Wed Jan 27, 2016 5:21 pm

Post by henk »

Yes - indeed, it has two USB interfaces.

If the suggestion above does not work, instead try to replace

Code: Select all

#define USB_TILE_REF usb_tile
with

Code: Select all

#define USB_TILE_REF usb_tile[0]
Or 1 - depending on which one you would like to use.
plex
Member++
Posts: 22
Joined: Fri Aug 12, 2016 6:13 pm

Post by plex »

Thank you both for the suggestions. Unfortunately they do not compile.
I tried a work around that allowed the project to compile but now I run into a new problem:
When the usb is connected to the PC the device is not recognized. The same project with the same pid,vid etc when compiled for the xCore-200 Explorer board connects to the pc fine.
So I am not sure if the solution I tried is correct. I had to modify the xn file to resolve the problem with the usb_tile declaration and I also had to add a link for xscope to work.
Here is the new xn file with the changes/additions posted bellow.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<Network xmlns="http://www.xmos.com"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.xmos.com http://www.xmos.com">
  <Type>Device</Type>
  <Name>XEF232-1024-FB374-C40 Device</Name>

  <Declarations>
    <Declaration>tileref tile[4]</Declaration>
    <Declaration>tileref usb_tile</Declaration>
    <Declaration>tileref usb2_tile</Declaration>
  </Declarations>

  <Packages>
    <Package id="0" Type="XS2-UEFnA-1024-FB374">
      <Nodes>
        <Node Id="0" InPackageId="0" Type="XS2-L16A-512" SystemFrequency="500MHz" Oscillator="24MHz" OscillatorSrc="1">
          <Boot>
            <Source Location="bootFlash0"/>
            <Bootee NodeId="2"/>
          </Boot>
          <Tile Number="0" Reference="tile[0]">
            <Port Location="XS1_PORT_1B" Name="PORT_SQI_CS_0"/>
            <Port Location="XS1_PORT_1C" Name="PORT_SQI_SCLK_0"/>
            <Port Location="XS1_PORT_4B" Name="PORT_SQI_SIO_0"/>
          </Tile>
          <Tile Number="1" Reference="tile[1]"/>
        </Node>
        <Node Id="2" InPackageId="2" Type="XS2-L16A-512" SystemFrequency="500MHz" Oscillator="24MHz" OscillatorSrc="3">
          <Boot>
            <Source Location="LINK" BootMode="4"/>
          </Boot>
          <Tile Number="0" Reference="tile[2]"/>
          <Tile Number="1" Reference="tile[3]"/>
        </Node>
        <Node Id="1" InPackageId="1" Type="periph:XS1-SU" Reference="usb_tile" Oscillator="24MHz">
        </Node>
        <Node Id="3" InPackageId="3" Type="periph:XS1-SU" Reference="usb2_tile" Oscillator="24MHz">
        </Node>        
        <Node Id="4" Type="device:" RoutingId="0x8000">
      <Service Id="0" Proto="xscope_host_data(chanend c);">
        <Chanend Identifier="c" end="3"/>
      </Service>
       </Node>          
      </Nodes>
      <Links>
        <Link Encoding="5wire" Delays="3clk">
          <LinkEndpoint NodeId="0" Link="7"/>
          <LinkEndpoint NodeId="2" Link="0"/>
        </Link>
        <Link Encoding="5wire" Delays="3clk">
          <LinkEndpoint NodeId="0" Link="4"/>
          <LinkEndpoint NodeId="2" Link="3"/>
        </Link>
        <Link Encoding="5wire" Delays="3clk">
          <LinkEndpoint NodeId="0" Link="6"/>
          <LinkEndpoint NodeId="2" Link="1"/>
        </Link>
        <Link Encoding="5wire" Delays="3clk">
          <LinkEndpoint NodeId="0" Link="5"/>
          <LinkEndpoint NodeId="2" Link="2"/>
        </Link>
        <Link Encoding="5wire">
          <LinkEndpoint NodeId="0" Link="8" Delays="52clk,52clk"/>
          <LinkEndpoint NodeId="1" Link="XL0" Delays="1clk,1clk"/>
        </Link>
        <Link Encoding="5wire">
          <LinkEndpoint NodeId="2" Link="8" Delays="52clk,52clk"/>
          <LinkEndpoint NodeId="3" Link="XL0" Delays="1clk,1clk"/>
        </Link>
         <Link Encoding="2wire" Delays="5clk" Flags="XSCOPE">
      	 <LinkEndpoint NodeId="0" Link="XL0"/>
         <LinkEndpoint NodeId="4" Chanend="1"/>
        </Link>  
      </Links>
    </Package>
  </Packages>
  <ExternalDevices>
    <Device NodeId="0" Tile="0" Class="SQIFlash" Name="bootFlash0">
      <Attribute Name="PORT_SQI_CS" Value="PORT_SQI_CS_0"/>
      <Attribute Name="PORT_SQI_SCLK" Value="PORT_SQI_SCLK_0"/>
      <Attribute Name="PORT_SQI_SIO" Value="PORT_SQI_SIO_0"/>
    </Device>
  </ExternalDevices>

  <JTAGChain>
    <JTAGDevice NodeId="0"/>
    <JTAGDevice NodeId="2"/>
  </JTAGChain>

</Network>
The changes are:
Changed tileref declaration usb_tile[2] to 2 separate ones, usb_tile and usb2_tile.
Changed the names on Node 1,3 to reflect the declaration change.
Added missing Oscillator frequency setting.
Added Node 4 for xscope (based on x200 Explored xn file)
Added 2 wire link for xscope(based on x200 Explorer xn file)

My makefile flags for debug are -O3 -g -Wall -report -fxscope -DXUD_SERIES_SUPPORT=XUD_X200_SERIES -DUSB_TILE=tile[1]

It compiles and runs, I can also debug with xscope all 4 tiles.
But the USB device is not recognised by Windows.

I am really new to xmos so any input is welcomed. I hope that the problem is on my side and not in the tools - XEF232-1024 combo so that it can be resolved easier.
Thanks again!
henk
Respected Member
Posts: 347
Joined: Wed Jan 27, 2016 5:21 pm

Post by henk »

The changes look sensible - can you confirm that you use the left-hand USB interface on the package; not the right hand one?

Is anything visible on the USB bus, or on the windows side? I mean, does it see a USB device, and not recognise the particular device, or is there no USB traffic at all?

On a MacOSX I would run USB prober to check for an unrecognised device - there will be something similar on Windows.
plex
Member++
Posts: 22
Joined: Fri Aug 12, 2016 6:13 pm

Post by plex »

Yes the USB is the on the left side pins AA6,AA7 for the data lines.
I can see some traffic with the oscilloscope, possibly a reset request from the host. My next move was to try a USB analyser application on the PC. I will post any from this and other tests.
User avatar
aneves
Experienced Member
Posts: 93
Joined: Wed Sep 16, 2015 2:38 pm

Post by aneves »

If you are set up to debug with xscope, I'd say that would be a great place to start. Redirect IO so that you can use printf functions over xscope. Here's how:

https://www.xmos.com/published/how-redi ... ons-xscope

Now use the printf statements to print the return values for your endpoint0 handling to see where things are going wrong and to print the contents of the setup packets (if you are getting any).
plex
Member++
Posts: 22
Joined: Fri Aug 12, 2016 6:13 pm

Post by plex »

The USB connectivity issue is fixed now. It was a mistake on my side having the dataP and dataN reversed. I have a usb cable soldered to the board and the image search on google i did for "usb wire colors" produced a few images at the top where green was labeled as negative. I later found out that the opposite is true.
Still there is some problem with the USB and probably xscope link connections as the feedback seems slower and the USB does not always work as expected.
With the same code that I am using on the x200 explorer(where it runs perfectly) on the XEF232-1024 I get for example the following behaviour:
I check the cdc.bytes_available, read the returned number of bytes and when I check again for bytes available there is one more, I read it and it is the start of the previous packet an then one more and it is the second character from the previous packet and then the buffer is empty. The same happens in full speed and high speed modes.
I believe that my xn file is still not correct. Here is the current one:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<Network xmlns="http://www.xmos.com"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.xmos.com http://www.xmos.com">
  <Type>Device</Type>
  <Name>XEF232-1024-FB374-C40 Device</Name>

  <Declarations>
    <Declaration>tileref tile[4]</Declaration>
    <Declaration>tileref usb_tile</Declaration>
    <Declaration>tileref usb2_tile</Declaration>
  </Declarations>

  <Packages>
    <Package id="0" Type="XS2-UEFnA-1024-FB374">
      <Nodes>
        <Node Id="0" InPackageId="0" Type="XS2-L16A-512" SystemFrequency="500MHz" Oscillator="24MHz" OscillatorSrc="1">
          <Boot>
            <Source Location="bootFlash0"/>
            <Bootee NodeId="2"/>
          </Boot>
          <Tile Number="0" Reference="tile[0]">
            <Port Location="XS1_PORT_1B" Name="PORT_SQI_CS_0"/>
            <Port Location="XS1_PORT_1C" Name="PORT_SQI_SCLK_0"/>
            <Port Location="XS1_PORT_4B" Name="PORT_SQI_SIO_0"/>
          </Tile>
          <Tile Number="1" Reference="tile[1]"/>
        </Node>
        <Node Id="2" InPackageId="2" Type="XS2-L16A-512" SystemFrequency="500MHz" Oscillator="24MHz" OscillatorSrc="3">
          <Boot>
            <Source Location="LINK" BootMode="4"/>
          </Boot>
          <Tile Number="0" Reference="tile[2]"/>
          <Tile Number="1" Reference="tile[3]"/>
        </Node>
        <Node Id="1" InPackageId="1" Type="periph:XS1-SU" Reference="usb_tile" Oscillator="24MHz">
        </Node>
        <Node Id="3" InPackageId="3" Type="periph:XS1-SU" Reference="usb2_tile" Oscillator="24MHz">
        </Node>   
      </Nodes>
      <Links>
        <Link Encoding="5wire" Delays="3clk">
          <LinkEndpoint NodeId="0" Link="7"/>
          <LinkEndpoint NodeId="2" Link="0"/>
        </Link>
        <Link Encoding="5wire" Delays="3clk">
          <LinkEndpoint NodeId="0" Link="4"/>
          <LinkEndpoint NodeId="2" Link="3"/>
        </Link>
        <Link Encoding="5wire" Delays="3clk">
          <LinkEndpoint NodeId="0" Link="6"/>
          <LinkEndpoint NodeId="2" Link="1"/>
        </Link>
        <Link Encoding="5wire" Delays="3clk">
          <LinkEndpoint NodeId="0" Link="5"/>
          <LinkEndpoint NodeId="2" Link="2"/>
        </Link>
        <Link Encoding="5wire">
          <LinkEndpoint NodeId="0" Link="8" Delays="52clk,52clk"/>
          <LinkEndpoint NodeId="1" Link="XL0" Delays="1clk,1clk"/>  
          </Link>  
         <Link Encoding="5wire">
          <LinkEndpoint NodeId="2" Link="8" Delays="52clk,52clk"/>
          <LinkEndpoint NodeId="3" Link="XL0" Delays="1clk,1clk"/>
        </Link>    
      </Links>
    </Package>
  </Packages>
 <Nodes>
    <Node Id="4" Type="device:" RoutingId="0x8000">
      <Service Id="0" Proto="xscope_host_data(chanend c);">
        <Chanend Identifier="c" end="3"/>
      </Service>
    </Node>
  </Nodes>
 <Links>
    <Link Encoding="2wire" Delays="5clk" Flags="XSCOPE">
      <LinkEndpoint NodeId="0" Link="XL0"/>
      <LinkEndpoint NodeId="4" Chanend="1"/>
    </Link>
  </Links>
  <ExternalDevices>
    <Device NodeId="0" Tile="0" Class="SQIFlash" Name="bootFlash0">
      <Attribute Name="PORT_SQI_CS" Value="PORT_SQI_CS_0"/>
      <Attribute Name="PORT_SQI_SCLK" Value="PORT_SQI_SCLK_0"/>
      <Attribute Name="PORT_SQI_SIO" Value="PORT_SQI_SIO_0"/>
    </Device>
  </ExternalDevices>
  <JTAGChain>
    <JTAGDevice NodeId="0"/>
    <JTAGDevice NodeId="2"/>
  </JTAGChain>
</Network>
The XN Specification documents is not extensive enough for me to be confident that the settings are correct. IT would be great if somebody from xmos can verify or correct the XN file.
I will continue troubleshooting and report.
User avatar
aneves
Experienced Member
Posts: 93
Joined: Wed Sep 16, 2015 2:38 pm

Post by aneves »

Got any code you can post with some kind of debug output?
henk
Respected Member
Posts: 347
Joined: Wed Jan 27, 2016 5:21 pm

Post by henk »

Hi plex,

It is difficult to debug an XN file without the board - as it is a description of the board hardware. So assuming you have a boot flash in the right place, set the boot mode of node 1 correctly, have the link to xSCOPE in the advertised place, and use a 24 MHz oscillator it looks ok.

What makes you think it is not right?

If USB doesn't always work as expected I would start to investigate whether you have any signal integrity issues.

What sort of device class are you implementing?

Cheers,
Henk
Post Reply