Trying to turn on an LED

New to XMOS and XCore? Get started here.
Post Reply
User avatar
MAC
Member
Posts: 8
Joined: Wed Nov 19, 2014 4:12 am

Trying to turn on an LED

Post by MAC »

Hi all

I'm basically trying to do one of the LED examples with no success. Code compiles and there is JTAG activity, but no lit LED. Heres the code

Code: Select all

#include <xs1.h>
#include <platform.h>
#include <timer.h>

port p = XS1_PORT_8B;

int main(void){
    while(1){
        p <: 1;
    }
    return 0;

}
My board is the Multichannel Audio Board, XR-USB-AUDIO-2.0-MC. Maybe i've got a development environment problem.

Can someone help?
Thanks


User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Hi Mac. On your board the LEDs are mapped to the X1D14..X1D21. The X1 notes the port pins are on Tile[1]. You will need to inform your code to make use of Tile[1] so that you access the correct 8 bit port. From the hardware manual for your board, suspecting you are accessing the ULPI interface which is on Tile[0]. That is my logical stab at the issue.

Also, consider to apply:

out port p = XS1_PORT_8B;

Sorry but unable to find the specific keywords you will need to use to inform the compiler that you wish to use the Tile[1] port pins but it is also late in the evening...

There are some articles on the XMOS website noting the parallel construct (ie. par keyword) as follows:

on tile[1].core[0] : task2();

so perhaps you need to create another task with your desired port pin access. Hoping there is an easier method that someone else can identify.

see here:

Use of specific tile / cores
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

Hi Mac try this:

Code: Select all

// On tile denotes which tile the GPIO port is attached to
on tile[0] : out port p = XS1_PORT_8B;

int main(void) {

	par {
		// Run our code on the Same tile as the port we are using
		on tile[0] : {
			while(1) { // not sure which port bits led attached to so use all
				p <: 0xFF; // all 8 bits on
				delay_milliseconds(500);
				p <: 0; // all 8 bits off
				delay_milliseconds(500);
			}
		}
	}


	return 0;
}
Warning I haven't checked to see if it's the right port in the schematic, or run this.

PS : if you don't be specific about tiles it will default to using tile[0] which makes sense if you think about it.

regards
Al
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Thanks Al for your details. Silly enough, forgot the includes in my project so received assorted errors in attempting the similar idea so did not post :)

MAC, in theory, the following should work for your specific board with LEDs on Tile[1]:

#include <xs1.h>
#include <platform.h>
#include <timer.h>


// On tile denotes which tile the GPIO port is attached to
on tile[1] : out port p = XS1_PORT_8B;

int main(void) {

par {
// Run our code on the Same tile as the port we are using
on tile[1] : {
while(1) { // not sure which port bits led attached to so use all
p <: 0xFF; // all 8 bits on
delay_milliseconds(500);
p <: 0; // all 8 bits off
delay_milliseconds(500);
}
}
}


return 0;
}
User avatar
MAC
Member
Posts: 8
Joined: Wed Nov 19, 2014 4:12 am

Post by MAC »

Thanks Al and Mon

I tried Al's code and got two errors:
../src/LED_Test1.xc:12: error: `tile' undeclared here (not in a function)
../src/LED_Test1.xc:12: error: 'on' expression not of type tileref

I did a google search for the second error and an XMOS document outlining the .xn file came up http://www.xmos.com/download/public/XN- ... cation.pdf. Looking at that file it referenced the Declaration of a tileref object.

So I looked for a tileref declaration in my .xn file, but didn't find one. However I did find these lines:

Code: Select all

<Core Number="0" Reference="stdcore[1]">
        <Port Location="XS1_PORT_8B" Name="PORT_LEDS"/>
As a guess I changed the code to this:

Code: Select all

#include <xs1.h>
#include <platform.h>
#include <timer.h>

on stdcore[1] : out port p = XS1_PORT_8B;

int main(void){
    par{
    on stdcore[1]:{
        while(1){
            p <: 1;
            delay_milliseconds(200);
            p <: 0;
            delay_milliseconds(200);
        }
    }
    }
    return 0;

}
And it compiled with no errors!

I haven't had a chance to run it on my board yet, I'll have to check Monday. I'll let you know.

If this does fix the issue, I guess this is specific to the given code for the MULTICHANNEL AUDIO REF design. When you make the .xn file is it standard practice to just use the "tile[x]" name? The person who wrote my .xn file didn't follow that standard if it is indeed a standard...
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

Hi Mac

stdcore[x] was the old way of doing it (depreciated I think) with the newer tools and chips use tile[x], maybe you are using an older version of the tools? I just noticed my code example used tile[0], try changing it to tile[1] also for your app when you do use a newer version.

regards
Al
User avatar
MAC
Member
Posts: 8
Joined: Wed Nov 19, 2014 4:12 am

Post by MAC »

Ok i tried my code above and it worked fine.

I then went back and Al's code with tile[0] replaced with tile[1], here's the code

Code: Select all

#include <xs1.h>
#include <platform.h>
#include <timer.h>

on tile[1] : out port p = XS1_PORT_8B;

int main(void){
    par{
    on tile[1]:{
        while(1){
            p <: 1;
            delay_milliseconds(200);
            p <: 0;
            delay_milliseconds(200);
        }
    }
    }
    return 0;

}
I get these errors:
Compiling LED_Test1.xc
../src/LED_Test1.xc:12: error: `tile' undeclared here (not in a function)
../src/LED_Test1.xc:12: error: 'on' expression not of type tileref

The source file XR-USB-AUDIO-2.0.xn has these lines that I think are as Al described, "the old way..."

Code: Select all

      <Core Number="0" Reference="stdcore[1]">
        <Port Location="XS1_PORT_8B" Name="PORT_LEDS"/>
      </Core>
That line "stdcore[1]" troubles me in the .xn file. Tried replacing the references to stdcore[x].
Heres the code, sorry long

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>USB Audio 2.0 Multichannel Board</Name>
  <BoardId>0006021X</BoardId>
  <Declarations>
    <Declaration>tileref tile[2]</Declaration>
  </Declarations>

  <Nodes>
      <Node Id="0" Type="XS1-L1A" oscillator="13Mhz" systemfrequency="500Mhz" referencefrequency="100MHz">
      <Tile Number="0" Reference="tile[0]">
        <Port Location="XS1_PORT_1A" Name="PORT_SPI_MISO"/>
        <Port Location="XS1_PORT_1B" Name="PORT_SPI_SS"/>
        <Port Location="XS1_PORT_1C" Name="PORT_SPI_CLK"/> 
        <Port Location="XS1_PORT_1D" Name="PORT_SPI_MOSI"/>

        <Port Name="UIFM_INT_CLK_PORT" Location="XS1_PORT_1I"/>
        <Port Name="UIFM_USB_CLK_PORT" Location="XS1_PORT_1H"/>
        <Port Name="UIFM_REG_WRITE_PORT" Location="XS1_PORT_8C"/>     
        <Port Name="UIFM_REG_READ_PORT"  Location="XS1_PORT_8D"/> 
        <Port Name="UIFM_FLAG_0_PORT"    Location="XS1_PORT_1N"/>       
        <Port Name="UIFM_FLAG_1_PORT"    Location="XS1_PORT_1O"/>
        <Port Name="UIFM_FLAG_2_PORT"    Location="XS1_PORT_1P"/>
        <Port Name="UIFM_TX_DATA_PORT"   Location="XS1_PORT_8A"/>
        <Port Name="UIFM_RX_DATA_PORT"   Location="XS1_PORT_8B"/>
        <Port Name="UIFM_STP_SUS_PORT"   Location="XS1_PORT_1E"/>
        <Port Name="UIFM_LS_PORT"        Location="XS1_PORT_4D"/>
      </Tile>
      <Boot>
        <Source Location="SPI:bootFlash"/>
        <Bootee NodeId="1"/>
      </Boot>
    </Node>
    <Node Id="1" Type="XS1-L1A" oscillator="13Mhz" systemfrequency="500MHz" referencefrequency="100MHz">
      <Boot>
        <Source Location="XMOSLINK"/>
      </Boot>
      <Tile Number="0" Reference="tile[1]">
        <Port Location="XS1_PORT_8B" Name="PORT_LEDS"/>
      </Tile>
    </Node>
  </Nodes>

  <Links>
    <Link Encoding="5wire" Delays="0,1">
      <LinkEndpoint NodeId="0" Link="4"/>
      <LinkEndpoint NodeId="1" Link="7"/>
    </Link>
    <Link Encoding="5wire" Delays="0,1">
      <LinkEndpoint NodeId="0" Link="5"/>
      <LinkEndpoint NodeId="1" Link="6"/>
    </Link>
    <Link Encoding="5wire" Delays="0,1">
      <LinkEndpoint NodeId="0" Link="6"/>
      <LinkEndpoint NodeId="1" Link="5"/>
    </Link>
    <Link Encoding="5wire" Delays="0,1">
      <LinkEndpoint NodeId="0" Link="7"/>
      <LinkEndpoint NodeId="1" Link="4"/>
    </Link>
  </Links>

  <Packages>
    <Package ID="0" Type="XS1-L2A-QF124">
      <Component NodeId="0" InPackage="0"/>
      <Component NodeId="1" InPackage="1"/>
    </Package>
  </Packages>

  <ExternalDevices>
    <Device NodeId="0" Core="0" Class="SPIFlash" Name="bootFlash" Type="AT25DF041A">
      <Attribute Name="PORT_SPI_MISO" Value="PORT_SPI_MISO"/>
      <Attribute Name="PORT_SPI_SS"   Value="PORT_SPI_SS"/>
      <Attribute Name="PORT_SPI_CLK"  Value="PORT_SPI_CLK"/>
      <Attribute Name="PORT_SPI_MOSI" Value="PORT_SPI_MOSI"/>
    </Device>
  </ExternalDevices>

  <JTAGChain>
     <JTAGDevice NodeId="0"/>
     <JTAGDevice NodeId="1"/>
  </JTAGChain>
 
</Network>

Changes include:
<Declaration>tileref tile[2]</Declaration>
<Tile Number="0" Reference="tile[0]">
<Tile Number="0" Reference="tile[1]">

This .xn file worked with Al's code. So I think I get it now. I just wonder if i'm going to screw something up working with the board/chip I have and using the new code style. I guess I'll find out and post other issues if they come up.

So I hope this discussion is helpful to newbies, like me, just getting started with an older kit.

Thanks everyone for your help

MAC
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

MAC wrote: This .xn file worked with Al's code. So I think I get it now. I just wonder if i'm going to screw something up working with the board/chip I have and using the new code style. I guess I'll find out and post other issues if they come up.
The chips and board should not be screwed up, all the code is backward compatible with Xmos hardware AFAIK. However if you have older source code that you need to use you may find older references like "stdcore" within it that need updating etc..

Glad you got it all working Mac

regards
Al
Post Reply