XScope library

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
matrix
Active Member
Posts: 62
Joined: Sat Sep 17, 2011 12:05 pm

XScope library

Post by matrix »

Hi,

I want to use the UART interface of a XC-1A
for debugging.

Code: Select all

#include <platform.h>
#include <xscope.h>

port uart_tx = PORT_UART_TX;

void xscope_user_init(void) {
  xscope_register(0);
  xscope_config_uart(uart_tx);
  xscope_config_io(XSCOPE_IO_BASIC);
}
In the project makefile, I have added: XCC_MAP_FLAGS_Debug = -fxscope.

Compiling fails with:

xscope_xlink_tx.S: Error: Undefined reference to '__sodEnd' (using xScope without specifying -fxscope?)
xscope_api_xlink.c: Error: Undefined reference to '__sodFlag' (using xScope without specifying -fxscope?)
../src/main.xc: Error: Undefined reference to 'xscope_config_uart'

Thanks for any hints.
User avatar
infiniteimprobability
Verified
XCore Legend
Posts: 1164
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

OK - firstly do you have an XK-1 or XK-1A? XK-1 can only use xscope via UART (which is what you are specifying in your source code) whereas the XK-1A has the link pinned out to the XTAG2 connector. The latter is much better - just a few cycles intrusiveness compared with an in-lined UART tx function. It's very close to real time.

If you bought your kit recently, it's likely to be XK-1A.

In this case, delete

Code: Select all

xscope_config_uart(uart_tx);
and

Code: Select all

port uart_tx = PORT_UART_TX;
.

Finally, ensure that your target is

Code: Select all

TARGET = XK-1A
otherwise the xn file with the debug link description won't be referenced.
User avatar
matrix
Active Member
Posts: 62
Joined: Sat Sep 17, 2011 12:05 pm

Post by matrix »

Hi,
I am using a XC-1A kit, not the XK-1.

Thanks.
User avatar
infiniteimprobability
Verified
XCore Legend
Posts: 1164
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

Oops - Ok, XC-1A. Got it.

So tried this in version 12.2.0 and it works: (Note that it's happier with the init code outside of the xscope constructor)

Code: Select all

#include <platform.h>
#include <xscope.h>
#include <stdio.h>

port xscope_uart_port = PORT_UART_TX;

int main(void){
	xscope_config_uart(xscope_uart_port);
	xscope_register(0, 0, "", 0, "");
	xscope_config_io(XSCOPE_IO_TIMED);
	printf("Hello world");
	return 0;
}
Note that

Code: Select all

-fxscope
enables the link connection to the XTAG2. To enable the UART version, you need to use
-lxscope_uart
. That's what I used above.

However, in tools 13 it doesn't seem to work..

The proper way to do this is:

Code: Select all

#include <platform.h>
#include <xscope.h>
#include <stdio.h>

port xscope_uart_port = PORT_UART_TX;

void xscope_init(void) {
	xscope_register(0, 0, "", 0, "");
	xscope_config_io(XSCOPE_IO_TIMED);
}

int main(void){
	printf("Hello world");
	return 0;
}
but there is a bug..and the code gets stuck in the xscope constructor.
Thanks for raising this - a bug has been filed against this.
Jack
Member++
Posts: 24
Joined: Fri Sep 05, 2014 4:41 pm

Post by Jack »

Dears,

any solution to this in the meanwhile? I am using Xtime Composer 14 and try to detour the printf debug to the Uart, but chapte 3 in the app note "Debug with printf in real-time" still does not work.
this function is still not existing:
xscope_config_uart ( uart_tx );

Any workaround?

Thanks!
ahmet
Junior Member
Posts: 6
Joined: Sat Oct 29, 2016 3:05 pm

Post by ahmet »

I have this problem, too. I'm using xTIMEcomposer 14.2.3.

Error output;

1. use of undeclared identifier 'PORT_UART_TX'
2. unknown function identifier 'xscope_config_uart'
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am

Post by mon2 »

Do you have the following required lines in your code ?

Code: Select all

#include  <platform.h>
#include  <xscope.h>
ahmet
Junior Member
Posts: 6
Joined: Sat Oct 29, 2016 3:05 pm

Post by ahmet »

mon2 wrote:Do you have the following required lines in your code ?
Yes.

Code: Select all

#include <xs1.h>
#include <platform.h>
#include <print.h>
#include "startkit_gpio.h"
#include <stdio.h>
#include "startkit_adc.h"
#include <xscope.h>
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am

Post by mon2 »

Can you post your code for a review ? Believe your target is the XMOS StartKit ?
ahmet
Junior Member
Posts: 6
Joined: Sat Oct 29, 2016 3:05 pm

Post by ahmet »

Ok. main.xc file;

Code: Select all

// Copyright (c) 2016, XMOS Ltd, All rights reserved
#include <xs1.h>
#include <platform.h>
#include <print.h>
#include "startkit_gpio.h"
#include <stdio.h>
#include "startkit_adc.h"
#include <xscope.h>

#define LOOP_PERIOD 20000000 //Trigger ADC and print results every 200ms = 20000000

port p = XS1_PORT_32A;
port p2 = XS1_PORT_1D;
out port adc_sample = ADC_TRIG_PORT; //XS1_PORT_1A

void task1(void){ //just an LED animation
    unsigned pattern1 = 0x00000000;     // the pattern output to the leds,
    unsigned time;
    char tmp = 0;
    timer t;

    while(1){
        select {
            case t when timerafter(time) :> void:
                time += 2000000; // 1000000 is 10 msec

                switch (tmp) {
                    case 0:
                        pattern1 = 0x80000;
                        break;
                    case 1:
                        pattern1 = 0x40000;
                        break;
                    case 2:
                        pattern1 = 0x20000;
                        break;
                    case 3:
                        pattern1 = 0x1000;
                        break;
                    case 4:
                        pattern1 = 0x800;
                        break;
                    case 5:
                        pattern1 = 0x400;
                        break;
                    case 6:
                        pattern1 = 0x200;
                        break;
                    case 7:
                        pattern1 = 0x100;
                        break;
                    case 8:
                        pattern1 = 0x80;
                        break;
                    default:
                        break;
                }
                tmp++;
                if(tmp > 8) tmp = 0;
                p <: (0xFFFFFFFF - pattern1);
                break;
        }
    }
}
void task2(void){ // 15 msec LED toggle for debug purpose
    while(1){
        p2 <: 0;
        delay_milliseconds(15);
        p2 <: 1;
        delay_milliseconds(15);
    }
}
void app(client startkit_adc_if i_adc)
{
    timer t_loop; //Loop timer
    int loop_time; //Loop time comparison variable
    unsigned short adc_val[4] = {0, 0, 0, 0};//ADC vals
    //printstrln("App started");
    t_loop :> loop_time; //Take the initial timestamp of the 100Mhz timer
    loop_time += LOOP_PERIOD; //Set comparison to future time
    while (1) {
        select {
            //Loop timeout event
            case t_loop when timerafter(loop_time) :> void:
                i_adc.trigger(); //Fire the ADC!
                loop_time += LOOP_PERIOD; //Setup future time event
                break;
            case i_adc.complete(): //Notification from ADC server when aquisition complete
                i_adc.read(adc_val); //Get the values (and clear the notfication)
//                for(int i = 0; i < 4; i++){
//                    printstr("ADC chan ");
//                    printint(i);
//                    printstr(" = ");
//                    printint(adc_val[i]);
//                }
//                printchar('\n');
                break;
        }
    }
}

/*// this part is not compilling
port uart_tx = PORT_UART_TX;

void xscope_user_init(void) {
  xscope_register(0);
  xscope_config_uart(uart_tx);
  xscope_config_io(XSCOPE_IO_BASIC);
}
*/

int main() {
    startkit_adc_if i_adc; //For triggering/reading ADC
    chan c_adc;

    par{
        on tile[0]:task1();
        on tile[0]:task2();
        on tile[0]: adc_task(i_adc, c_adc, 0, adc_sample);
        startkit_adc(c_adc);
        on tile[0]: app(i_adc);
    }
    return 0;
}