DMA testing ( SPI mode in USART controller )

Discussions about all user software around SAM Series.

Moderator: nferre

rpateric
Posts: 2
Joined: Wed Dec 10, 2014 4:45 pm

DMA testing ( SPI mode in USART controller )

Wed Dec 10, 2014 4:50 pm

Hello,
We have a problem on DMA related to SAMA5D3 USART. We have enabled DMA at the driver level in SPI mode for USART controller and using stty command to view the ascii data value transferred to master and slave side.
Our application sends data to both master and slave side, doing proper configurations. 
Now when we tried to display the received dats using stty, the issues are as follows.

For Hex data values as inputs, 
(1) if we send exactly 32 bytes, it is coming, both at the master and slave side.
- The first byte is not received at both the master and slave side .
- From second byte onwards, it shows '0' in between the hex values . 
Byte Reception at Slave and Master end,
 <---- First byte missed out here.
slave ff Master 1
slave fe Master 2 
slave fd Master 3 
slave fc Master 4 
slave fb Master 5 
slave fa Master 6 
slave f9 Master 7 
slave f8 Master 8 
slave f7 Master 0 <----- Zero coming '0' in between hex values ( actually it should be 9 )
slave f6 Master 9 
slave f5 Master 10 
slave f4 Master 11 
slave f3 Master 12 
slave f2 Master 13 
slave f1 Master 14 
slave f0 Master 15 
slave ef Master 16 
slave ee Master 17 
slave ed Master 18 
slave ec Master 19 
slave eb Master 20 
slave ea Master 21 
slave e9 Master 22 
slave e8 Master 23 
slave e7 Master 24 
slave e6 Master 25 
slave e5 Master 26 
slave e4 Master 27 
slave e3 Master 28 
slave e2 Master 29 
slave e1 Master 30 
slave a  Master 31

(2) If we send less than 32 bytes nothing is coming at both master and slave end
(3) if we send more than 32 bytes, garbage values are coming after 32 bytes. 

In case of ASCII data, we receive the data correctly at both the master and the slave side for the above tests.

The stty command which we used is
stty -F /dev/ttyS1 -echo -onlcr 

Now, when we tried using "stty raw crtscts < /dev/ttyS1 -echo -onlcr", the slave is receiving correctly but at the master side, the first five datas are zeros.
For "stty raw clocal < /dev/ttyS1 -echo -onlcr", the master is receiving correctly, but at the slave side, zero is comming( both in case of ASCII and hex )
For "stty raw < /dev/ttyS1 -echo -onlcr",the master is receiving correctly, but at the slave side, zero is coming ( both in case of ASCII and hex )

Kindly let us know, if there is any issue in testing or how exactly do we want to proceed here ? Are we using correct method using stty command ?

Best Regards,
Rupesh
blue_z
Location: USA
Posts: 1505
Joined: Thu Apr 19, 2007 10:15 pm

Re: DMA testing ( SPI mode in USART controller )

Thu Dec 11, 2014 2:25 am

rpateric wrote:... using stty command to view the ascii data value transferred to master and slave side.
Maybe something is getting lost in translation, but I fail to comprehend your descriptions. Perhaps your familiarity of your setup prevents you from writing a clear description of the circumstances.

The stty command is for "change and print terminal line settings"; the salient word is settings. It's not for "viewing data".

"Master and slave" of what? The SPI interface?
rpateric wrote:Our application sends data to both master and slave side, doing proper configurations.
Where is this application executing?
How are you "sending" data to two different destinations at once? 
rpateric wrote:Now when we tried to display the received dats using stty, the issues are as follows.
stty is not a command that will display data.
So what are you really doing?
rpateric wrote:For Hex data values as inputs, 
(1) if we send exactly 32 bytes, it is coming, both at the master and slave side.
- The first byte is not received at both the master and slave side .
- From second byte onwards, it shows '0' in between the hex values .
By "hex" you presumably mean binary (bytes).
Where and how in the data path is this data being sampled?
rpateric wrote:(2) If we send less than 32 bytes nothing is coming at both master and slave end
I don't understand ''coming at both master and slave end".
rpateric wrote:The stty command which we used is
stty -F /dev/ttyS1 -echo -onlcr 

Now, when we tried using "stty raw crtscts < /dev/ttyS1 -echo -onlcr", the slave is receiving correctly but at the master side, the first five datas are zeros.
Using input redirection is non-standard with the stty command. You should -F to specify the target device.

Why does your title mention DMA?

Even though it's configured for SPI mode, the Linux API to the USART is the tty subsystem interface that includes line discipline processing.
If data are text and delimited as "lines", then you can use canonical mode.
If data are text but not delimited as "lines", then you should use non-canonical mode.
If the data are not text but binary, then you must use non-canonical mode.
Your testing is not adhering to these basic rules.

Regards
rpateric
Posts: 2
Joined: Wed Dec 10, 2014 4:45 pm

Re: DMA testing ( SPI mode in USART controller )

Fri Dec 12, 2014 10:14 am

Hello,
We have modified our application to use non-canonical mode, and the updated one is as following, but still we are facing issue while transmitting bytes less than 32.

The psuedo code is as follows,
/*data from slave to master*/
uint8_t sl_buf[512]={< Bytes here >};
    
/*data from master to slave*/ 
uint8_t  tx[512]={<Bytes here> };
    
struct termios newtio;
 
/* structure defined for spi transfer */
struct spi_ioc_transfer tr = {
.tx_buf = (unsigned long)tx,
.rx_buf = (unsigned long)lx_buf,
.len = 32,
.delay_usecs = 0,
.speed_hz = speed,
.bits_per_word = bits,
.cs_change = 0,
};

/* opening file descriptors now */
   fd_m=open("/dev/spidev32766.0", O_RDWR | O_NONBLOCK);
 fd=open("/dev/ttyS1", O_RDWR | O_NONBLOCK );
 
/* clear struct for new port settings */   
bzero(&newtio, sizeof(newtio)); 
     
/* for non canonical input*/
newtio.c_lflag =0;
    
/* now clean the modem line and activate the settings for the port */
tcflush(fd, TCIOFLUSH);
tcsetattr(fd,TCSANOW,&newtio);

Now Set the max speed in hz, bits per word etc 
  
/* Write function for slave */       
write (fd, sl_buf,32)
 
 /* ioctl command for spi master read and write operation*/     
 ret = ioctl(fd_m, SPI_IOC_MESSAGE(1), &tr);     
 
for(i=0;i<32;i++)
{  
 /* Read function for slave */   
      read(fd,&rx_buf[0], 1);
      printf ("slave %x ",rx_buf[0]);     
      printf ("Master %x \n", lx_buf);
}
...

Best Regards,
Rupesh
blue_z
Location: USA
Posts: 1505
Joined: Thu Apr 19, 2007 10:15 pm

Re: DMA testing ( SPI mode in USART controller )

Mon Dec 15, 2014 9:48 pm

rpateric wrote:The psuedo code is as follows,
What do you mean by "psuedo code"?
Is it worth anyone's time to analyze/critique this "psuedo code" instead of the real code?
rpateric wrote:struct termios newtio;
 
/* clear struct for new port settings */   
bzero(&newtio, sizeof(newtio)); 
     
/* for non canonical input*/
newtio.c_lflag =0;
    
/* now clean the modem line and activate the settings for the port */
tcflush(fd, TCIOFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
If this is supposed to be real code, then it is very broken.
Study the Serial Programming Guide for POSIX Operating Systems
and Setting Terminal Modes Properly for proper use of the termios API.

Regards

Return to “Software”

Who is online

Users browsing this forum: No registered users and 1 guest