Quick Start for startKIT and Command Line Tools

All technical discussions and projects around startKIT
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Quick Start for startKIT and Command Line Tools

Postby Bianco » Tue Dec 31, 2013 7:44 pm

Example 1
In this example we will compile, simulate and run a single source file application
  1. create a new dir called example1 and navigate to that dir.
  2. save the below code in a file called example.xc in the newly created dir

    Code: Select all

    #include <platform.h>
    #include <stdio.h>
    
    on tile[0] : out port led = XS1_PORT_1A;
    
    void counting_task()
    {
      timer t;
      unsigned ctime;
      unsigned count = 0;
      
      t :> ctime;
      
      while (1) {
        printf("count: %u\n", count);
        count++;
        t when timerafter(ctime + 50000000) :> ctime;
      }
    }
    
    void led_task() {
      timer t;
      unsigned ctime;
      
      t :> ctime;
      
      while (1) {
        t when timerafter(ctime + 25000000) :> ctime;
        led <: 0;
        t when timerafter(ctime + 25000000) :> ctime;
        led <: 1;
      }
    }
    
    int main(void)
    {
      par {
        on tile[0] : counting_task();
        on tile[0] : led_task();
      }
      
      return 0;
    }
    
    
  3. Let's use the command line tools! On windows start the "xTIME Composer Command Prompt" and a cmd prompt will appear.
    On OS X and Linux, open a new terminal window, navigate to xTIME Composer installation root dir (on OS X in /Applications/XMOS... on Linux wherever you extracted the tools), then run 'source SetEnv.sh'.
  4. Navigate back to the example1 dir.
  5. Compile the source file: 'xcc -target=STARTKIT -O2 -report -o example.xe example.xc', (build for target STARTKIT, optimization level 2, report constraints check, output binary example.xe).
  6. Simulate the application: 'xsim example.xe', you will see 'count: 0', if you are really patient you will see more print statements. It takes a while because succeeding print statements are millions of cycles apart due to the timer delay. You can use Control+C to stop the simulation. Try the simulation again with instruction trace: 'xsim -t example.xe'. Observe that the instruction trace stops after a while, this is because both logical cores are blocked waiting for a timer event. Again if you are patient you will see it continue after some time. The simulation in the command line tools is particular useful to examinate crashing programs and studying program behaviour at the instruction level. Port toggling etcetera can also be captured but it is more convenient to use the simulator from the xTIME Composer Studio in combination with the waveform viewer.
  7. Check if the startKIT is detected: 'xrun -l'
  8. Run the application on the startKIT. 'xrun --io example.xe'. The --io flag instructs the debugger to stay attached, this enables us to print to the console.
Example 2
In this example we will build, run and flash an application example from github.
  1. Create a new dir called example2.
  2. Save the following dirs from https://github.com/xcore/sw_startkit_examples to example2: app_absolute, module_startkit_gpio. You can do this by cloning the repository using a git client and copy the dirs or use the download zip function at the right side.
  3. Save the following dir from https://github.com/xcore/sc_capacitive_sensing to example2: module_capacitive_sensing. example2 now should contain the following sub dirs: app_absolute, module_startkit_gpio, module_capacitive_sensing.
  4. Navigate to example2/app_absolute.
  5. Build the project: run 'xmake' or 'xmake all'.
  6. Navigate to example2/app_absolute/bin
  7. Run on the startkit: 'xrun --io app_absolute.xe'
  8. Flash the application to the boot flash: 'xflash app_absolute.xe'. (Do not make the mistake to use xburn instead of xflash, xburn is used to burn the One Time Programmable memory).
xgdb is a very powerful debugging tool for setting breakpoints and checking register contents etc that I have not discussed here.

The command line tools are documented in the xTIME Composer Studio user guide
User avatar
ahenshaw
Experienced Member
Posts: 96
Joined: Mon Mar 22, 2010 8:55 pm

Postby ahenshaw » Wed Jan 01, 2014 3:23 am

Excellent tutorial - thanks! I will definitely be using this info.
paf
Newbie
Posts: 1
Joined: Tue Jan 07, 2014 3:50 pm

Postby paf » Tue Jan 07, 2014 4:12 pm

Many thanks for a very useful guide!
User avatar
rithesh
Member
Posts: 11
Joined: Wed Jun 24, 2015 12:21 am

Postby rithesh » Wed Jun 24, 2015 12:34 am

You sir, are a genius! Thank you soo much :) this feels much better! however, what if you have multiple classes/implementations? how do you include a makefile? could you please share the link to the documentation for using xmos in command line?

Also, in the xcc command, what does -O2 mean? what is its purpose?
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Postby Bianco » Wed Jun 24, 2015 9:15 am

If you have multiple files you can compile them at once by adding the files like this:

xcc -target=STARTKIT -O2 -report -o example.xe file1.xc file2.xc file3.xc

The -O2 is a compiler flag to instruct it to compile with optimization level 2.

Makefiles are just the same as for any other toolchain.
User avatar
rithesh
Member
Posts: 11
Joined: Wed Jun 24, 2015 12:21 am

Postby rithesh » Wed Jun 24, 2015 4:57 pm

Thank you so much! :)

Who is online

Users browsing this forum: No registered users and 0 guests