Platform: X86 platform purchased from the Internet (baytrail-d (Cerelon J1900))
The Baytrail platform comes with two serial ports and is basically a low-end desktop configuration
The serial port is the same as the desktop
Problem: This X86 platform (baytrail Cerelon J1900) as a slave device,
It is connected to the serial port of the PC and has no output.
Solution: Both ends of the serial line are female, that is, direct connection, so that the Baytrail TX directly with the PC's TX-phase
So the tune for a long time without any output, the problem is that the Byt TX and the PC's TX phase, resulting in the PC can not see the output of the BYT device
Therefore, to adjust the serial equipment, it is necessary to pay attention to the need to use a crossover line or direct connection, or to pay attention to whether the receiving and sending the corresponding
In addition, the test code on the serial port, this is also a appbox of a routine:
#include <stdio.h> #include <ctype.h> #include <unistd.h> #include <stdlib.h> #include < string.h> #include <errno.h> #include <fcntl.h> #include <time.h> #include <dirent.h># Include <assert.h> #include <linux/unistd.h> #include <pthread.h> #include <semaphore.h># Include <signal.h> #include <termios.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <linux/ioctl.h> #include <sys/times.h> #include <sys/time.h> #include <sys/sysinfo.h> #include <net/if.h> #include <net/if_arp.h> #include <net/route.h> #include <linux/if_ether.h> #include <arpa/inet.h> #include <linux/sockios.h> #include <sys/mman.h>/* Platform: Buy from the Internet X86 Platform (baytrail-d (Cerelon J1900) Baytrail platform with two serial ports, basically is the low-end desktop configuration of the serial port is the same as the desktop problem: this X86 platform (Baytrail Cerelon J1900) as a slave device, will be connected to the serial port of the PC, there is no output solution: Serial line Both ends are female, that is, direct connection, so that, Baytrail TX directly with the PC TX connection so the tune for a long time without any output, the problem is byt TX and PCTX-phase, which causes the output of the BYT device to be invisible on the PC. In addition, the test code on the serial port, which is also appbox a routine: */typedef unsigned int dword;typedef unsigned char by TE; #define Line_max_length128#define name_max_length 32#define max_path_length 128///serial Property structure typedef struct COMM_ATTR { dwordbaudrate;///< the actual baud rate value. bytedatabits;///< the actual number of data bits. byteparity;///< parity option, take an enumeration value of type comm_parity_t. bytestopbits;///< stops the number of bits, taking an enumeration value of type comm_stopbits_t. bytereserved;///< reserved} comm_attr;///serial stop bit type enum comm_stopbits_t {comm_onestopbit,///< 1 Stop bitcomm_ one5stopbits,///< 1.5 Stop bitcomm_twostopbits///< 2 stop bit};///serial check bit type enum comm_parity_t {comm_noparity,/// < No paritycomm_oddparity,///< Odd paritycomm_evenparity,///< even paritycomm_mark,///< COMM_SPACE///< };typedef enum Commtype {commbus_485 = 0x0001,commbus_422 = 0x0002, commbus_232 = 0x0004,} commtype;///serial operation interrupt type typedef e num Commpurgeflags{commpurgetxabort = 0x0001,///< Abort write operation Commpurgerxabort = 0x0002,///< Abort read operation Commpurgetxclear = 0x0004,///< emptying the output buffer commPurgerxclear = 0x0008///< empty input buffer} commpurgeflags;///serial stop bit type typedef enum COMMSTOPBIT{COMMONESTOPBIT = 0,///< 1 Stop bitcommone5stopbits,///< 1.5 Stop bitcommtwostopbits//< 2 stop bit} commstopbit;///serial check bit type typedef enum COMMPARITY Type {commnoparity = 0,///< No paritycommoddparity,///< Odd paritycommevenparity,///< Even paritycommmarkparity,///< Mark paritycommspaceparity///< Space parity} commparitytype;///special serial port flag typedef enum Commspecialflag{commnormal = 0,commredapple} commspecialflag;///serial mode typedef enum COMMMODE{COMMFULLDUPLEX = 0,///< Full-duplex commsemiduplex,///< half-duplex} commmode;int uartfd = -1;int frontboardsetattr (comm_attr *parmaattribute_p) {struct Termios Option; Comm_attr *attribute_p = parmaattribute_p;memset (&option, 0, sizeof (struct termios)); Tcgetattr (UARTFD, & Option), if (Uartfd < 0) {printf ("Index < 0 | | Uartsetattributeex.\n "); return-1;} Cfmakeraw (&option); switch (attribute_p->baudrate) {case 50:cfsetispeed (&option, B50); CFSETospeed (&option, B50); Break;case 75:cfsetispeed (&option, B75); Cfsetospeed (&option, B75); Break;case 110: Cfsetispeed (&option, B110); Cfsetospeed (&option, B110); Break;case 134:cfsetispeed (&option, B134); Cfsetospeed (&option, B134); Break;case 150:cfsetispeed (&option, B150); Cfsetospeed (&option, B150); break; Case 200:cfsetispeed (&option, B200); Cfsetospeed (&option, B200); Break;case 300:cfsetispeed (&option, B300 ); Cfsetospeed (&option, B300); Break;case 600:cfsetispeed (&option, B600); Cfsetospeed (&option, B600); Break;case 1200:cfsetispeed (&option, B1200); Cfsetospeed (&option, B1200); Break;case 1800:cfsetispeed (& Option, B1800); Cfsetospeed (&option, B1800); Break;case 2400:cfsetispeed (&option, B2400); Cfsetospeed (& Option, B2400); Break;case 4800:cfsetispeed (&option, B4800); Cfsetospeed (&option, B4800); Break;case 9600: Cfsetispeed (&option, B9600); Cfsetospeed (&option, B9600); Break;case 19200:cfsetispeed (&optiOn, B19200); Cfsetospeed (&option, B19200); Break;case 38400:cfsetispeed (&option, B38400); Cfsetospeed (& Option, B38400); Break;case 57600:cfsetispeed (&option, B57600); Cfsetospeed (&option, B57600); break;case 115200:cfsetispeed (&option, B115200); Cfsetospeed (&option, B115200); break;default:printf ("Unsupported BaudRate%d\n ", attribute_p->baudrate); return-1;} Switch (attribute_p->parity) {case commnoparity://noneoption.c_cflag &= ~parenb;//Disable PARITYOPTION.C_ Iflag &= ~inpck;//Disable parity checkbreak;case commoddparity://oddoption.c_cflag |= parenb;//enable ParityOption . C_cflag |= parodd;//oddoption.c_iflag |= inpck;//enable parity checkbreak;case commevenparity://EvenOption.c_cflag |= parenb;//Enable Parityoption.c_cflag &= ~parodd;//evenoption.c_iflag |= inpck;//enable parity Checkbreak;case comm MarkParity:Option.c_cflag |= parenb;/* enable Parity*/option.c_cflag |= parodd;/* parity bit is always 1*/break;case CommS Paceparity:option.C_cflag |= parenb;/* Enable parity*/break;default:printf ("Unsupported parity%d\n", attribute_p->parity); return-1;} Option.c_cflag &= ~csize;switch (attribute_p->databits) {case 5:option.c_cflag |= CS5;break;case 6:Option.c_ Cflag |= cs6;break;case 7:option.c_cflag |= cs7;break;case 8:option.c_cflag |= cs8;break;default:printf ("Unsupported Data bits%d\n ", attribute_p->databits); return-1;} Option.c_cflag &= ~cstopb;switch (attribute_p->stopbits) {case CommOneStopBit:Option.c_cflag &= ~CSTOPB; Break;case commone5stopbits:break;case commTwoStopBits:Option.c_cflag |= cstopb;break;default:printf ("Unsupported Stop bits%d\n ", attribute_p->stopbits); return-1;} Option.c_cc[vtime] = 0;option.c_cc[vmin] = 1;tcflush (UARTFD, Tcioflush); if (Tcsetattr (UARTFD, Tcsanow, &Option) < 0) {printf ("tcsetattr failed.\n"); return-1;} return 0;} int frontboardcreate (void) {char Devicename[name_max_length] = {0};int ifbuartindex; Comm_attr Uartattribute;memset (&uartattribute, 0, siZeof (Uartattribute)); if (Uartfd > 0) {return 0;} Ifbuartindex = 0;snprintf (devicename, sizeof (devicename), "%s%d", "/dev/ttys", Ifbuartindex);p rintf ("devicename:%s\n ", devicename); uartfd = open (DeviceName, O_RDWR), if (Uartfd < 0) {printf (" Open%s failed.\n ", devicename); return-1;} Uartattribute.baudrate = 9600; Uartattribute.databits = 8; uartattribute.parity = commnoparity; Uartattribute.stopbits = Commonestopbit;if (frontboardsetattr (&uartattribute) < 0) {printf (" Uartsetattributeex Failed. \ n "); return-1;} return 0;} int frontboarddestory (void) {if (Uartfd > 0) {close (UARTFD); uartfd =-1;} return 0;} int Frontboardread (void *pdata, DWORD nbytes) {int readlength = 0;int readposition = 0;if (NULL = = PData | | nbytes < 0) {p rintf ("Invalid Params, NULL = = PData or nbytes < 0.\n"); return-1;} memset (pData, 0, Nbytes), while (0! = nbytes) {readlength = Read (UARTFD, PData + readposition, nbytes); if (Readlength < 0) { printf ("Read Failed, Readlength < 0.\n"); return-1;} Readposition + = ReadlEngth;nbytes-= readlength;} return readposition;} int frontboardwrite (void *pdata, DWORD nbytes) {int writelength = 0;int writeposition = 0;if (NULL = = PData | | nbytes < 0 ) {printf ("Invalid Params, NULL = = PData | | Nbytes < 0.\n "); return-1;} while (0! = nbytes) {writelength = write (uartfd, PData + writeposition, nbytes); if (Writelength < 0) {printf ("Write failed , nbytes:%d, writelength:%d\n ", Nbytes, writelength); return-1;} Writeposition + = writelength;nbytes-= writelength;} return writeposition;} int main (int argc, char *argv[]) {unsigned char pdata[8] = {0};pD ata[0] = ' A ';pD ata[1] = ' B ';pD ata[2] = ' C ';pD ata[3] = ' d '; PDATA[4] = ' \ n '; Frontboardcreate (); while (1) {printf ("frontboardwrite:\n"); Frontboardwrite ((void*) PData, 8); sleep (1);} return 0;}
Appbox: Linux serial test program