Uart problem

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
Alexb
Member
Posts: 10
Joined: Tue Apr 03, 2012 1:35 pm

Uart problem

Postby Alexb » Mon Apr 16, 2012 9:27 pm

Hello,

I'm been also having some trouble with the simple uart module. I've modified the uart_back2back code so it would just listen to incoming transmission from a Arduino (simulating a sensor I would like to connect to the xmos)
Here the modified xmos code:

Code: Select all

// Copyright (c) 2011, XMOS Ltd, All rights reserved
// This software is freely distributable under a derivative of the
// University of Illinois/NCSA Open Source License posted in
// LICENSE.txt and at <http://github.xcore.com/>

#include <xs1.h>
#include <platform.h>
#include "uart_rx.h"
#include "uart_tx.h"
#include <print.h>

void forward(chanend uartTX, chanend uartRX)
{
  uart_rx_client_state rxState;
  unsigned char rcvbuffer[26];
  unsigned char byte;
  int i;
  unsigned int gotest;
  gotest=1;
  byte=0;
  uart_rx_init(uartRX, rxState);
  while(gotest) {
   // printstr("Echo : ");

    for(i=0;i<13;i++) {
      rcvbuffer[i] = uart_rx_get_byte(uartRX, rxState);
    }
    for(i=0;i<13;i++) {
      printchar(rcvbuffer[i]);
    }
    //printstr(" done\n");
  }
  printstr("Test Completed\n");
}

//buffered in port:1 rx = on stdcore[0] : XS1_PORT_1A;
//out port tx = on stdcore[0] : XS1_PORT_1B;
buffered in port:1 rx = on stdcore[0] : XS1_PORT_1G;
out port tx = on stdcore[0] : XS1_PORT_1H;


#define BAUD_RATE 115200

#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))

#pragma unsafe arrays
int main() {
  chan chanTX, chanRX;
  par {
    on stdcore[0] : {
      unsigned char tx_buffer[64];
      unsigned char rx_buffer[64];
      tx <: 1;
      printstr("Listening...\n");
      par {
        uart_rx(rx, rx_buffer, ARRAY_SIZE(rx_buffer), BAUD_RATE, 8, UART_TX_PARITY_NONE, 1, chanRX);
        uart_tx(tx, tx_buffer, ARRAY_SIZE(tx_buffer), BAUD_RATE, 8, UART_TX_PARITY_NONE, 1, chanTX);
      }
    }
    on stdcore[0] : {
      forward(chanTX, chanRX);
    }
  }
  return 0;
}


Here is the Arduino test Code :

Code: Select all

void setup() {
   
    Serial.begin(115200);
}

void loop() {
   
    Serial.print("Hello World!\n");
 // delay(5);
 


}


There is no problem if I keep the delay around 50 milisec but if I lower it, I start getting errors. I'M I doing something wrong?

Thanks

Alex

(P.s. I moved this post from the other one since I felt It was in the wrong section)
User avatar
Bianco
XCore Expert
Posts: 721
Joined: Thu Dec 10, 2009 6:56 pm
Contact:

Postby Bianco » Mon Apr 16, 2012 10:29 pm

The print statements are using JTAG for printing to the console on the host.
During printing the entire core can be halted, this means that the UART RX thread can be halted while the other thread is printing, hence the loss of data.

For real-time non-intrusive printing you can use the print functionality of Xscope (only works on XS1-L) or use the UART lines on the XTAG2 adapter, or implement another UART and use a RS-232 connection to the host computer. You can also create a large buffer and store more lines until it is ok to print, if that fits the case.
Alexb
Member
Posts: 10
Joined: Tue Apr 03, 2012 1:35 pm

Postby Alexb » Fri Apr 20, 2012 7:50 pm

Hi,

Thanks for the quick reply. I'm trying to use the print function with the Xscope since I am using the XK-1A board but I'm having some trouble. I used using the Debug-with-printf-in-real-time(X1093C) pdf as a guide and made the following changes to my code :

Code: Select all

// Copyright (c) 2011, XMOS Ltd, All rights reserved
// This software is freely distributable under a derivative of the
// University of Illinois/NCSA Open Source License posted in
// LICENSE.txt and at <http://github.xcore.com/>

#include <xs1.h>
#include <stdio.h>
#include <xscope.h>
#include <platform.h>
#include "uart_rx.h"
#include "uart_tx.h"
//#include <print.h>



void forward(chanend uartTX, chanend uartRX)
{
  uart_rx_client_state rxState;
  unsigned char rcvbuffer;
  unsigned char byte;
  int i;
  unsigned int gotest;
  gotest=1;
  byte=0;
  uart_rx_init(uartRX, rxState);
  while(gotest) {

      rcvbuffer = uart_rx_get_byte(uartRX, rxState);

  }
}


void xscope_user_init ( void ) {
   xscope_register(0,XSCOPE_CONTINUOUS, "Continuous Value 1", XSCOPE_UINT, "Value") ;
   xscope_config_io(XSCOPE_IO_BASIC);
}


buffered in port:1 rx = on stdcore[0] : XS1_PORT_1G;
out port tx = on stdcore[0] : XS1_PORT_1H;

#define BAUD_RATE 115200

#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))

#pragma unsafe arrays
int main() {



  chan chanTX, chanRX;


  par {
    on stdcore[0] : {
      unsigned char tx_buffer[64];
      unsigned char rx_buffer[64];

      tx <: 1;
      printf("Test Start...\n");
      par {
        uart_rx(rx, rx_buffer, ARRAY_SIZE(rx_buffer), BAUD_RATE, 8, UART_TX_PARITY_NONE, 1, chanRX);
        uart_tx(tx, tx_buffer, ARRAY_SIZE(tx_buffer), BAUD_RATE, 8, UART_TX_PARITY_NONE, 1, chanTX);
      }
    }
    on stdcore[0] : {

      forward(chanTX, chanRX);
    }
  }
  return 0;
}


Unfortunately I'm unable to build the project.
My getting this error

Code: Select all

**** Build of configuration Debug for project Oronos_Uart ****

xmake CONFIG=Debug all
Creating dependencies for  Oronos_Uart.xc
Compiling  Oronos_Uart.xc
"Updating eclipse config"
Using modules: module_uart_rx module_uart_tx
Creating Oronos_Uart_Debug.xe
../src/Oronos_Uart.xc: Error: L00067 Undefined reference to 'xscope_config_io'
../src/Oronos_Uart.xc: Error: L00067 Undefined reference to 'xscope_register'
xmake[1]: *** [bin/Debug/Oronos_Uart_Debug.xe] Error 1
xmake: *** [bin/Debug/Oronos_Uart_Debug.xe] Error 2


Any help would be greatly appreciated.

Alexandre Borowczyk
User avatar
Bianco
XCore Expert
Posts: 721
Joined: Thu Dec 10, 2009 6:56 pm
Contact:

Postby Bianco » Fri Apr 20, 2012 8:01 pm

I think you may have to tick a box somewhere that you want to use xscope.
The problem is that the xscope library is not linked against your application.
I do not have experience with xscope projects in combination with the XDE.
Alexb
Member
Posts: 10
Joined: Tue Apr 03, 2012 1:35 pm

Postby Alexb » Sat Apr 21, 2012 3:41 pm

Hello,

Yes it's seems this way. I've tried copying my code in the app_xscope_continuous files and it's compile without any problem and works! I was also wondering where can I find some info on the uart_moduale, specially on how the buffer works and what happens when it's full. It's seem that I my case, the programme crashed.

Thanks

Alexandre
Alexb
Member
Posts: 10
Joined: Tue Apr 03, 2012 1:35 pm

Postby Alexb » Sun May 06, 2012 2:19 pm

Hi,

I'm looking to use 6 pins for a Uart implementation. how should I processed so I dont clog 6 thread? Also did anyone find out how to include the scope, so far I've been using a scope demo file as a host for my program.

Thanks

Alex
User avatar
Bianco
XCore Expert
Posts: 721
Joined: Thu Dec 10, 2009 6:56 pm
Contact:

Postby Bianco » Sun May 06, 2012 3:36 pm

Alexb wrote:Hi,

I'm looking to use 6 pins for a Uart implementation. how should I processed so I dont clog 6 thread? Also did anyone find out how to include the scope, so far I've been using a scope demo file as a host for my program.

Thanks

Alex


You may want to take a look at this: https://github.com/xcore/sc_multi_uart
What do you mean with scope? Xscope?
Alexb
Member
Posts: 10
Joined: Tue Apr 03, 2012 1:35 pm

Postby Alexb » Thu May 10, 2012 5:12 pm

Hello,

I decided to master the simple uart first before moving to the multi-uart. Right now I'm running a simple receive then send code but I kept hitting this error :

0x0001048a in uart_rx_impl ()

or

xrun: Program received signal ET_ECALL, Application exception.
0x00010482 in uart_rx_impl ()

did anyone else had this problem?
User avatar
paul
XCore Addict
Posts: 169
Joined: Fri Jan 08, 2010 12:13 am
Contact:

Postby paul » Fri May 11, 2012 10:57 am

Looks like you are trying to interact with an array beyond it's bounds. ET_ECALL is a exception that is called by the code itself. XC automatically inserts array bounds checks for you - this is probably what you are running up against.
Alexb
Member
Posts: 10
Joined: Tue Apr 03, 2012 1:35 pm

Postby Alexb » Sun May 13, 2012 3:57 am

I narrowed down the error to the uart modules I use the one from the xmos website. I think it's called when the buffer is full, but the documentation says it should empty itself in that case.

Return to “Development Tools and Programming”

Who is online

Users browsing this forum: ers35 and 5 guests