Zerocat Chipflasher  v0.4.10-732-9a3cc90b
Flash free firmware to BIOS chips, kick the Management Engine.
Serial Howto
Todo:
Fix missing copyright and license infos in subsections!

How to setup a Serial Connection

Sample code was used to start building connect. The sample code had been picked from Serial_Programming.pdf, found at Wikipedia.

Then, we learned how to control the DTR-line, which is used to reset the Propeller. Again, sample code helped us, found at the Linux Programmer's Manual, i.e.:

  • $ man tty_ioctl, section 'modem control' and section 'EXAMPLE'.
  • $ man termios

More Places of Information

Infos by Copy&Paste

From <tt>$ man tty_ioctl</tt>...

EXAMPLE
//Check the condition of DTR on the serial port.
#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
int
main(void)
{
int fd, serial;
fd = open("/dev/ttyS0", O_RDONLY);
ioctl(fd, TIOCMGET, &serial);
if (serial & TIOCM_DTR)
puts("TIOCM_DTR is not set");
else
puts("TIOCM_DTR is set");
close(fd);
}

From <tt>Serial_Programming.pdf</tt>...

Cutout 1:

5.1.5 termios

A simple terminal program with termios.h can look like this:

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
int main(int argc, char ** argv)
{
struct termios tio;
struct termios stdio;
struct termios old_stdio;
int tty_fd;
unsigned char c = 'D';
tcgetattr(STDOUT_FILENO, &old_stdio);
printf("Please start with %s /dev/ttyS0\n", argv[0]);
memset(&stdio, 0, sizeof(stdio));
stdio.c_iflag = 0;
stdio.c_oflag = 0;
stdio.c_cflag = 0;
stdio.c_lflag = 0;
stdio.c_cc[VMIN] = 1;
stdio.c_cc[VTIME] = 0;
tcsetattr(STDOUT_FILENO, TCSANOW, &stdio);
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &stdio);
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
// make the reads non-blocking
memset(&tio, 0, sizeof(tio));
tio.c_iflag = 0;
tio.c_oflag = 0;
tio.c_cflag = CS8|CREAD|CLOCAL;
// 8n1, see termios.h for more information
tio.c_lflag = 0;
tio.c_cc[VMIN] = 1;
tio.c_cc[VTIME] = 5;
tty_fd=open(argv[1], O_RDWR | O_NONBLOCK);
cfsetospeed(&tio, B115200); // 115200 baud
cfsetispeed(&tio, B115200); // 115200 baud
tcsetattr(tty_fd, TCSANOW, &tio);
while (c != 'q')
{
if (read(tty_fd, &c, 1) > 0) write(STDOUT_FILENO, &c, 1);
// if new data is available on the serial port, print it out
if (read(STDIN_FILENO, &c, 1) > 0) write(tty_fd, &c, 1);
// if new data is available on the console, send it to the serial port
}
close(tty_fd);
tcsetattr(STDOUT_FILENO, TCSANOW, &old_stdio);
return
EXIT_SUCCESS;
}

Cutout 2: How to detect your UART

Pseudo Code from Page 52:

Set the value "0xE7" to the FCR to test the status of the FIFO flags.
Read the value of the IIR to test for what flags actually got set.

If Bit 6 is set Then

  If Bit 7 is set Then

    If Bit 5 is set Then
      UART is 16750
    Else
      UART is 16550A
    End If

  Else

    UART is 16550

  End If

Else

  you know the chip doesn't use FIFO, so we need to check the scratch register
  Set some arbitrary value like 0x2A to the Scratch Register.
  You don't want to use 0xFF or 0x00 as those might be returned by
  the Scratch Register instead for a false postive result.

  Read the value of the Scratch Register

  If the arbitrary value comes back identical
    UART is 16450
  Else
    UART is 8250
  End If

End If