Read Beagle Board xM RS-232 Serial output
環境設置
- Beagle Board xM 使用 OTG USB 供電
- Beagle Board xM RS-232 Serial output 連接到電腦 USB to COM
- 軟體修改老師的 ext_uart.c 如下
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <string.h>
//#include <stdlib.h>
static char *serial_name[]={"/dev/ttyS0","/dev/ttyS1","/dev/ttySAC1","/dev/ttySAC2","/dev/ttyUSB0"};
int main(void)
{
int n, len, fd_max,i;
fd_set readfds;
char buffer[256];
static struct termios oldtio,newtio;
printf(" *** 0:ttyS0 ***\r\n,*** 1:ttyS1 ***\r\n,*** 2:ttySAC1 ***\r\n,*** 3:ttySAC2 ***\r\n,*** 4:ttyUSB0 ***\r\n");
printf("*** please input the open serial : ");
scanf("%d",&i);
int fd = open(serial_name[i],O_RDWR | O_NOCTTY | O_NDELAY);//270
if(fd<0){
perror("Cannot Open Serial Port !\n");
}
else
printf("open Serial Port success !\r\n");
tcgetattr(fd,&oldtio);
tcgetattr(fd,&newtio);
cfsetispeed(&newtio,B115200);
cfsetospeed(&newtio,B115200);
//newtio.c_lflag&= ~(ICANON | ECHO | ECHOE | ISIG);
newtio.c_lflag |= ICANON;
newtio.c_cflag &= ~PARENB;
newtio.c_cflag &= ~CSTOPB;
newtio.c_cflag &= ~CSIZE;
newtio.c_cflag |= CS8;
newtio.c_oflag &= ~OPOST;
newtio.c_cflag |= (CLOCAL | CREAD);
newtio.c_iflag = 0;
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 0;
if(tcsetattr(fd,TCSAFLUSH,&newtio)<0)
{
printf("tcsetattr fail !\n");
exit(1);
}
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
fd_max = fd + 1;
/* Do the select */
//return 0;
while(1)
{
n = select(fd_max,&readfds,NULL,NULL,NULL);
memset(buffer, 0, sizeof(buffer));
if (n<=0)
printf("select failed");
else
{
if (FD_ISSET(fd, &readfds))
{ char buf[16];
len=read(fd, buffer, 256);
fprintf(stderr, "%s", buffer);
/*
buffer[len] = '\0';
fprintf(stderr, "Readed %d data:%s\n",len, buffer);
sprintf(buf, "got data:%s\n",buf);
write(fd,buf,strlen(buf));
*/
}
}
}
}
修改內容:
- 增加 /dev/ttyUSB0 for USB to COM
- Baud Rate 設為 115200
- 採用 ICANON 模式
- VTIME=0 && VMIN=0 : 立即讀取,若無資料則返回
- 將讀到的資料直接顯示出來,並將寫回去的功能移除
程式讀到的結果如下:
U-Boot SPL 2011.12-00010-ga3eb89c (Jan 29 2012 - 14:53:43)
Texas Instruments Revision detection unimplemented
OMAP SD/MMC: 0
timed out in wait_for_bb: I2C_STAT=1000
reading u-boot.img
reading u-boot.img
U-Boot 2011.12-00010-ga3eb89c (Jan 29 2012 - 14:53:43)
OMAP36XX/37XX-GP ES1.2, CPU-OPP2, L3-165MHz, Max CPU Clock 1 Ghz
OMAP3 Beagle board + LPDDR/NAND
I2C: ready
DRAM: 512 MiB
NAND: 0 MiB
MMC: OMAP SD/MMC: 0
*** Warning - readenv() failed, using default environment
In: serial
Out: serial
Err: serial
Beagle xM Rev C
No EEPROM on expansion board
No EEPROM on expansion board
Die ID #465600029ff800000168300f0d030023
Net: Net Initialization Skipped
No ethernet found.
Hit any key to stop autoboot: 2 1 0
The user button is currently NOT pressed.
SD/MMC found on device 0
reading uEnv.txt
** Unable to read "uEnv.txt" from mmc 0:1 **
Loading file "/boot/uImage" from mmc device 0:2 (xxa2)
在上面卡很久,只好等老師解釋了!!
留言