Tool/software: Linux
We have a custom board based on AM335x Starter kit. Our board is booting successfully. Ethernet is also working fine. Now we want to test UART interface between my processor and FPGA (XILINX ARTIX). My UART1 is connected to FPGA Side.
When i write data to UART which is connected to FPGA, nothing is coming on FPGA Side. This I observed on Vivado.
Same issue when I send data from FPGA. Nothing is received at the processor side. This I observed on Qt.
I am posting my code below. please check this and suggest me what to do to complete this UART test further. We are using RS232 protocol for communication.
Pinmux:
uart0_pins: pinmux_uart0_pins {
pinctrl-single,pins = <
AM33XX_IOPAD(0x970, PIN_INPUT_PULLUP | MUX_MODE0) /* uart0_rxd.uart0_rxd */
AM33XX_IOPAD(0x974, PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* uart0_txd.uart0_txd */
>;
};
uart1_pins: pinmux_uart1_pins {
pinctrl-single,pins = <
AM33XX_IOPAD(0x978, PIN_INPUT | MUX_MODE0) /* uart1_ctsn.uart1_ctsn */
AM33XX_IOPAD(0x97C, PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* uart1_rtsn.uart1_rtsn */
AM33XX_IOPAD(0x980, PIN_INPUT_PULLUP | MUX_MODE0) /* uart1_rxd.uart1_rxd */
AM33XX_IOPAD(0x984, PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* uart1_txd.uart1_txd */
>;
};
&uart0 {
pinctrl-names = "default";
pinctrl-0 = <&uart0_pins>;
status = "okay";
};
&uart1 {
pinctrl-names = "default";
pinctrl-0 = <&uart1_pins>;
status = "okay";
};
Linux-Version: ti-processor-sdk-linux-am335x-evm-05.00.00.15.
C Code:
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <termios.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
int g_UARTFile;
int setParameters (int speed, int parity)
{
// DCB p;
struct termios tty;
memset (&tty, 0, sizeof tty);
if (tcgetattr (g_UARTFile, &tty) != 0)
{
fprintf (stderr, "setParameters error %d from tcgetattr\n\n", errno);
return -1;
}
cfsetospeed (&tty, speed);
cfsetispeed (&tty, speed);
tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars
// disable IGNBRK for mismatched speed tests; otherwise receive break
// as \000 chars
tty.c_iflag &= ~IGNBRK; // disable break processing
tty.c_lflag = 0; // no signaling chars, no echo,
// no canonical processing
tty.c_oflag = 0; // no remapping, no delays
tty.c_cc[VMIN] = 0; // read doesn't block
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls,
// enable reading
tty.c_cflag &= ~(PARENB | PARODD); // shut off parity
tty.c_cflag |= parity;
tty.c_cflag &= ~CSTOPB;
tty.c_cflag &= ~CRTSCTS;
if (tcsetattr (g_UARTFile, TCSANOW, &tty)!= 0)
{
fprintf (stderr, "setParameters error %d from tcsetattr\n\n", errno);
return -1;
}
else
printf("Successfully set parameters\n\n");
//return 0;
}
void set_blocking (int should_block)
{
struct termios tty;
memset (&tty, 0, sizeof tty);
if (tcgetattr (g_UARTFile, &tty) != 0)
{
fprintf (stderr, "set_blocking error %d from tggetattr\n\n", errno);
return;
}
tty.c_cc[VMIN] = should_block ? 1 : 0;
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
if (tcsetattr (g_UARTFile, TCSANOW, &tty) != 0)
fprintf (stderr, "set_blocking error %d setting term attributes\n\n", errno);
}
void UartOpen()
{
g_UARTFile = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_SYNC);
if (g_UARTFile < 0) {
perror("UART Open Denied\n");
exit(1);
}
printf("UART Open is successful\n\n");
setParameters(9600, 1);
set_blocking(0);
printf("UART is connected successfully!!!!!\n\n");
}
void writeData(){
unsigned char temp = 'AA';
char a = 1;
int spot=0,n_written=0;
unsigned char cmd[]="INITIALIZE\n";
while(1){
int spot=0,n_written=0;
n_written = write(g_UARTFile,&a,sizeof(a));
spot += n_written;
/*int n_written = 0, spot =0;
do{
n_written = write(g_UARTFile,&cmd[spot],1);
spot += n_written;
}while(cmd[spot-1] != '\n' && n_written > 0);
if(spot>0)*/
printf("successfully written %d characters.\n\n",spot);
}
}
void readData(){
char response[1024],buf;
int spot = 0,n;
memset(response, '\0', sizeof response);
do{
n = read(g_UARTFile, &buf,1);
sprintf(&response[spot],"%c",buf);
spot+=n;
}while(buf!='\r' && n >0);
if(n<0) printf("Error Reading\n\n");
else if(n==0) printf("Read Nothing!\n\n");
else printf("Response %s\n\n",response);
}
int main(int argc, char *argv[])
{
UartOpen();
// writeData();
readData();
}