Uart problem

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
mifay
Member++
Posts: 29
Joined: Wed Dec 28, 2011 4:15 pm

Post 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.


User avatar
paul
XCore Addict
Posts: 169
Joined: Fri Jan 08, 2010 12:13 am
Contact:

Post 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)
User avatar
mifay
Member++
Posts: 29
Joined: Wed Dec 28, 2011 4:15 pm

Post by mifay »

Here is the call stack:

Image
User avatar
mifay
Member++
Posts: 29
Joined: Wed Dec 28, 2011 4:15 pm

Post 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.
User avatar
JasonWhiteman
Active Member
Posts: 63
Joined: Mon Jul 15, 2013 11:39 pm
Contact:

Post 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
sprajagopal
Member++
Posts: 18
Joined: Thu Jul 23, 2015 4:22 pm

Post 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.
Post Reply