Page 2 of 2

Re: Uart problem

Posted: Sun May 13, 2012 7:42 pm
by mifay
I'm having a similar problem when using two rx ports at once. I guess without sc_multi_uart, it isn't possible.

Here is my error message :

Code: Select all

xrun: Program received signal ET_ECALL, Application exception.
      [Switching to stdcore[0] hwthread 2]
The code I'm using is the following one:

Code: Select all

///////////////////////////////////////////////////////////////////////////////////
//
// File 	: uart.xc
//
// Sypnosis : Communication between xmos, arduino and gps.
//
///////////////////////////////////////////////////////////////////////////////////
#include <xs1.h>
#include <platform.h>
#include "uart_tx.h"
#include "uart_rx.h"
#include "ports.h"

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

// uart communication function
void forward(chanend arduinoRX, chanend loggerTX, chanend gpsRX);

#define BUFF_SIZE 640

//baud rates
#define BAUD_9600 	9600
#define BAUD_115200 115200

///////////////////////////////////////////////////////////////////////////////////
//
// Name 		: main
//
// Sypnosis 	: main function
//
// Parameters 	: None
//
// Returns 		: ErrorCode
//
///////////////////////////////////////////////////////////////////////////////////
#pragma unsafe arrays
int main()
{
	chan arduinoRX, dntTX, gpsRX;

	par
	{
		// Set UART context
		on stdcore[0] :
		{
			unsigned char dnt_tx_buffer[BUFF_SIZE];
			unsigned char arduino_rx_buffer[BUFF_SIZE];
			unsigned char gps_rx_buffer[BUFF_SIZE];

			tx_dnt <: 1;

			par
			{
				uart_rx(rx_gps, gps_rx_buffer, ARRAY_SIZE(gps_rx_buffer), BAUD_115200, 8, UART_TX_PARITY_NONE, 1, gpsRX);
				uart_rx(rx_arduino, arduino_rx_buffer, ARRAY_SIZE(arduino_rx_buffer), BAUD_115200, 8, UART_TX_PARITY_NONE, 1, arduinoRX);
		    	uart_tx(tx_dnt, dnt_tx_buffer, ARRAY_SIZE(dnt_tx_buffer), BAUD_115200, 8, UART_TX_PARITY_NONE, 1, dntTX);
			}
		}

		// UART communication
	    on stdcore[0] :
	    {
	      forward(arduinoRX, dntTX, gpsRX);
	    }
	}

	return 0;
}

///////////////////////////////////////////////////////////////////////////////////
//
// Name 		: forward
//
// Sypnosis 	: UART communication between xmos, arduino and logger
//
// Parameters 	: chanend arduinoTX, chanend arduinoRX, chanend loggerTX
//
// Returns 		: Nothing
//
///////////////////////////////////////////////////////////////////////////////////
void forward(chanend arduinoRX, chanend dntTX, chanend gpsRX)
{
	uart_rx_client_state rxStateArduino;
	uart_rx_client_state rxStateGPS;
	unsigned char receivedByteArduino;
	unsigned char receivedByteGPS;

	uart_rx_init(arduinoRX, rxStateArduino);
	uart_rx_init(gpsRX, rxStateGPS);

	while(1)
	{
		receivedByteArduino = uart_rx_get_byte(arduinoRX, rxStateArduino);
		uart_tx_send_byte(dntTX, receivedByteArduino);

		receivedByteGPS = uart_rx_get_byte(gpsRX, rxStateGPS);
		uart_tx_send_byte(dntTX, receivedByteGPS);
	}
}

P.S. : I'm working on the same project as alexb. I'm hoping this additional information can help solve the problem.

Re: Uart problem

Posted: Mon May 14, 2012 2:37 pm
by paul
Unfortunately I don't have time to look at the RX code you are using (and I am unfamilar with it). But running it in the XDE debugger should tell you where in the code it is barfing.

(... or if you are familar with GDB you can use XGDB)

Re: Uart problem

Posted: Tue May 15, 2012 1:19 am
by mifay
Here is the call stack:

Image

Re: Uart problem

Posted: Tue May 15, 2012 3:00 am
by mifay
I removed the trap() function and it's working ok besides the fact that once in a while, uart received data is corrupted.

Re: Uart problem

Posted: Wed Jul 31, 2013 5:09 am
by JasonWhiteman
... fast forward quite some time, change developers. I am seeing issues running the app_sk_gpio_com_demo. I've tried a couple of different baud rates and generally get the same performance regardless of the settings. For the most part, output (TX) looks ok. Rarely, but sometimes garbled.

However, input is difficult to pass without corruption.

Furthermore, I have also seen the failure:

xrun: Program received signal ET_ECALL, Application exception.
[Switching to stdcore[1] core[2]]

Board is XMOS XP-SKC-L2 1V2, running in IDE, only testing UART using serial on same host connected to XMOS XTAG2.

I admit I have not yet dug into the code to determine if it appropriate for this target.

Regards,
Jason Whiteman

Re: Uart problem

Posted: Fri Apr 29, 2016 10:25 am
by sprajagopal
For anybody who still faces this, the ET_ECALL cannot be circumvented by changing baud rates. The error simply means that the rx buffer is full (this is the unsigned char array that you declare in the main function, where the tasks are assigned).
The reason for the error could be that the host function is not "sampling" data fast enough from the buffer. Sampling is when you call uart_rx_get_byte from a host function. When this function is called, the uart server removes that byte from the buffer allowing for it to read more.
At times, there could be flooding of data in the port. To avoid the trap() function being called, you could empty and reinitiate the buffer. Just removing trap() will not help. It'll simply give corrupted bytes for the length of the buffer. Instead, do something like:

Code: Select all

  buffer_state.entries = 0;
  buffer_state.read_index = 0;
  buffer_state.write_index = 0;
  buffer_state.sent_bytes = 0;
in the trap() function instead of the asm call.