Trouble

UART Setup

13 13295
vk4tux  
I am tring to setup with these instructions ;
This consists of (a) increasing the clock to the RPi
UART, (b) disabling the getty (to allow terminal login) running on the RPi
serial port, and (c) disable the console on the serial port.

a. Edit the file /boot/config.txt and add the line:

init_uart_clock=3686400

b. Edit the file /etc/inittab and replace or comment the line:

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

with:

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

or delete the line entirely.

c. Edit the file /boot/cmdline.txt and replace or comment the line:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline
rootwait

with:

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4
elevator=deadline rootwait


for
Prepare the DV3000 board. You need to ensure that the board is running at
230400 baud and to do this, ensure that only one jumper is fitted on the board,
BR2, and it is the one between pins 1 and 2. This is the one at the end nearest
to the connector to the Pi. This is the default and is optimum for operation.


is this correct way to setup UART on banana pi please ?

Adrian ... vk4tux
BananaPi don't use /boot/config.txt and cmdline.txt files. It use the the script.bin and uEnv.txt files.

vk4tux  
Ok Thankyou, I am using the raspberry > banana pi noobs image. I cleaned out much of recovery to gain ~1.2 GB of space , but left the main partition files and A20 folder and contents. In A20 > banana pi I see the files you speak. Of.
How can I achieve 'init_uart_clock=3686400 ' please?

also I need the UART to be assigned to a GPIO device, . can  I configure  not to use  any getty at boot etc ?

Thankyou.

Adrian ... vk4tux

vk4tux  
Thankyou, much appreciated.

Adrian ... vk4tux

vk4tux  
root@bananapi:~# cd /home/pi/AMBETools/DV3000
root@bananapi:/home/pi/AMBETools/DV3000# ./dv3000d -d -x
root@bananapi:/home/pi/AMBETools/DV3000# opened the Wiring Pi library
opened the UDP socket on port 2460
opened /dev/ttyS0
Socket data
0000:  61 00 01 00 30                                     *a...0*

I still cannot communicate with the device using the this process make build instruct ;

dv3000d.c

*
*   You should have received a copy of the GNU General Public License
*   along with this program; if not, write to the Free Software
*   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <termios.h>
#include <string.h>
#include <fcntl.h>

#include <sys/stat.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/socket.h>

#include <netinet/in.h>

#if defined(RASPBERRY_PI)
#include <wiringPi.h>
#else
int  wiringPiSetup();
void pinMode(int pin, int mode);
void digitalWrite(int pin, int value);
void delay(unsigned int delay);
#define        OUTPUT        1
#define        HIGH        1
#define        LOW        0
#endif

#define        DV3000_TTY                "/dev/ttyS0"
#define        DV3000_VERSION                "2014-04-23"

#define        AMBE3000_HEADER_LEN        4U
#define        AMBE3000_START_BYTE        0x61U

#define        DEFAULT_PORT                2460U
#define        BUFFER_LENGTH                400U

struct sockaddr_in sa;
int serialFd;
int sockFd;
int debug = 0;

void dump(char *text, unsigned char *data, unsigned int length)
{
        unsigned int offset = 0U;
        unsigned int i;

        fputs(text, stdout);
        fputc('\n', stdout);

        while (length > 0U) {
                unsigned int bytes = (length > 16U) ? 16U : length;

                fprintf(stdout, "%04X:  ", offset);

                for (i = 0U; i < bytes; i++)
                        fprintf(stdout, "%02X ", data[offset + i]);

                for (i = bytes; i < 16U; i++)
                        fputs("   ", stdout);

                fputs("   *", stdout);

                for (i = 0U; i < bytes; i++) {
                        unsigned char c = data[offset + i];

                        if (isprint(c))
                                fputc(c, stdout);
                        else
                                fputc('.', stdout);
                }

                fputs("*\n", stdout);

                offset += 16U;

                if (length >= 16U)
                        length -= 16U;
                else
                        length = 0U;
        }
}

int openWiringPi(void)
{
        int ret = wiringPiSetup();
        if (ret == -1) {
                fprintf(stderr, "dv3000d: error when initialising wiringPi\n");
                return 0;
        }

        pinMode(7, OUTPUT);                // Power

        // Reset the hardware
        digitalWrite(7, LOW);

        delay(20UL);

        digitalWrite(7, HIGH);

        delay(750UL);

        if (debug)
                fprintf(stdout, "opened the Wiring Pi library\n");

        return 1;
}

int openSerial()
{
        struct termios tty;
        int fd;
       
        fd = open(DV3000_TTY, O_RDWR | O_NOCTTY | O_SYNC);
        if (fd < 0) {
                fprintf(stderr, "dv3000d: error when opening " DV3000_TTY ", errno=%d", errno);
                return fd;
        }

        if (tcgetattr(fd, &tty) != 0) {
                fprintf(stderr, "dv3000d: error %d from tcgetattr\n", errno);
                return -1;
        }

        cfsetospeed(&tty, B230400);
        cfsetispeed(&tty, B230400);

        tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
        tty.c_iflag &= ~IGNBRK;
        tty.c_lflag = 0;

        tty.c_oflag = 0;
        tty.c_cc[VMIN]  = 0;
        tty.c_cc[VTIME] = 5;

        tty.c_iflag &= ~(IXON | IXOFF | IXANY);

        tty.c_cflag |= (CLOCAL | CREAD);

        tty.c_cflag &= ~(PARENB | PARODD);
        tty.c_cflag &= ~CSTOPB;
        tty.c_cflag &= ~CRTSCTS;

        if (tcsetattr(fd, TCSANOW, &tty) != 0) {
                fprintf(stderr, "dv3000d: error %d from tcsetattr\n", errno);
                return -1;
        }

        if (debug)
                fprintf(stdout, "opened " DV3000_TTY "\n");

        return fd;
}

int openSocket(uint16_t port)
{
        struct sockaddr_in sa;
        int ret;
        int fd;

        fd = socket(AF_INET, SOCK_DGRAM, 0);
        if (fd < 0) {
                fprintf(stderr, "dv3000d: error when creating the socket, errno=%d", errno);
                return fd;
        }

        memset(&sa, 0x00, sizeof(struct sockaddr_in));
        sa.sin_family = AF_INET;
        sa.sin_port = htons(port);
        sa.sin_addr.s_addr = htonl(INADDR_ANY);

        ret = bind(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in));
        if (ret < 0) {
                fprintf(stderr, "dv3000d: error when binding the socket to port %u, errno=%d", port, errno);
                return fd;
        }

        if (debug)
                fprintf(stdout, "opened the UDP socket on port %u\n", port);

        return fd;
}

int processSerial(void)
{
        unsigned char buffer[BUFFER_LENGTH];
        unsigned int respLen;
        unsigned int offset;
        ssize_t len;

        len = read(serialFd, buffer, 1);
        if (len != 1) {
                fprintf(stderr, "dv3000d: error when reading from the serial port, errno=%d", errno);
                return 0;
        }

        if (buffer[0U] != AMBE3000_START_BYTE) {
                fprintf(stderr, "dv3000d: unknown byte from the DV3000, 0x%02X", buffer[0U]);
                return 1;
        }

        offset = 0U;
        while (offset < (AMBE3000_HEADER_LEN - 1U)) {
                len = read(serialFd, buffer + 1U + offset, AMBE3000_HEADER_LEN - 1 - offset);

                if (len == 0)
                        delay(5UL);

                offset += len;
        }

        respLen = buffer[1U] * 256U + buffer[2U];

        offset = 0U;
        while (offset < respLen) {
                len = read(serialFd, buffer + AMBE3000_HEADER_LEN + offset, respLen - offset);

                if (len == 0)
                        delay(5UL);

                offset += len;
        }

        respLen += AMBE3000_HEADER_LEN;

        if (debug)
                dump("Serial data", buffer, respLen);

        if (sa.sin_port != 0U) {
                len = sendto(sockFd, buffer, respLen, 0, (struct sockaddr *)&sa, sizeof(struct sockaddr_in));
                if (respLen != len) {
                        fprintf(stderr, "dv3000d: error when writing to the socket, len=%d, errno=%d", len, errno);
                        return 0;
                }
        }

        return 1;
}

int processSocket(void)
{
        unsigned char buffer[BUFFER_LENGTH];
        socklen_t sl = sizeof(struct sockaddr_in);
        unsigned int len;
        ssize_t n;
       
        n = recvfrom(sockFd, buffer, BUFFER_LENGTH, 0, (struct sockaddr *)&sa, &sl);
        if (n < 0) {
                fprintf(stderr, "dv3000d: error when reading from the socket, errno=%d", errno);
                return 0;
        }

        if (debug)
                dump("Socket data", buffer, n);

        if (buffer[0U] != AMBE3000_START_BYTE) {
                fprintf(stderr, "dv3000d: invalid start byte when reading from the socket, 0x%02X", buffer[0U]);
                return 1;
        }

        len = buffer[1U] * 256U + buffer[2U] + AMBE3000_HEADER_LEN;
        if (n != len) {
                fprintf(stderr, "dv3000d: invalid length when reading from the socket, %u=%d", len, n);
                return 1;
        }

        n = write(serialFd, buffer, len);
        if (n != len) {
                fprintf(stderr, "dv3000d: error when writing to the serial port, errno=%d", errno);
                return 0;
        }

        return 1;
}

int main(int argc, char **argv)
{
        uint16_t port = DEFAULT_PORT;
        int daemon = 0;
        int topFd;
        fd_set fds;
        int ret;
        int c;

        while ((c = getopt(argc, argv, "dp:vx")) != -1) {
                switch (c) {
                        case 'd':
                                daemon = 1;
                                break;
                        case 'p':
                                port = (uint16_t)atoi(optarg);
                                break;
                        case 'v':
                                fprintf(stdout, "dv3000d: version " DV3000_VERSION "\n");
                                return 0;
                        case 'x':
                                debug = 1;
                                break;
                        default:
                                fprintf(stderr, "Usage: dv3000d [-d] [-p port] [-v] [-x]\n");
                                return 1;
                }
        }

        if (daemon) {
                pid_t pid = fork();

                if (pid < 0) {
                        fprintf(stderr, "dv3000d: error in fork(), exiting\n");
                        return 1;
                }

                // If this is the parent, exit
                if (pid > 0)
                        return 0;

                // We are the child from here onwards
                setsid();

                chdir("/");

                umask(0);
        }

        ret = openWiringPi();
        if (!ret)
                return 1;
       
        sockFd = openSocket(port);
        if (sockFd < 0)
                return 1;
               
        serialFd = openSerial();
        if (serialFd < 0)
                return 1;

        memset(&sa, 0x00, sizeof(struct sockaddr_in));

        topFd = sockFd;
        if (serialFd > topFd)
                topFd = serialFd;
        topFd++;

        for (;;) {
                FD_ZERO(&fds);
                FD_SET(sockFd, &fds);
                FD_SET(serialFd, &fds);
                ret = select(topFd, &fds, NULL, NULL, NULL);
                if (ret < 0) {
                        fprintf(stderr, "dv3000d: error from select, errno=%d\n", errno);
                        return 1;
                }
               
                if (FD_ISSET(sockFd, &fds)) {
                        ret = processSocket();
                        if (!ret)
                                return 1;
                }

                if (FD_ISSET(serialFd, &fds)) {
                        ret = processSerial();
                        if (!ret)
                                return 1;
                }
        }

        return 0;
}


makefile

all:        dv3000d

GCC := gcc

CFLAGS := -O2 -DRASPBERRY_PI -Wall
LIBS := -lwiringPi

dv3000d:        dv3000d.o
        $(GCC) $(LDFLAGS) -o dv3000d dv3000d.o $(LIBS)
       
dv3000d.o:        dv3000d.c
        $(GCC) $(CFLAGS) -c dv3000d.c

clean:
        $(RM) -f dv3000d *~ *.bak *.o

Adrian ... vk4tux

Did you use the wiringPi ???

If you use the wiringPI, maybe it can not work now. The original wiringPi didn't work well on bananapi, we need modify it. So Lemaker are developing it to makt it work well on BPs.

vk4tux  
Thankyou, yes yoy can see the source code is setup for wiring pi. I hope you can
make it compatible with the bananapi . Also there is a A20 fedora 20 image available, but it doees not have a banana pi option yet,

see

http://fedoraproject.org/wiki/Ar ... A10_.2F_A13_.2F_A20

Does someone can setup uart speed more than 115200?

If I understand right, I should increase pll6 value in script.bin. Should I update all other pll values to correspond with pll6?

vk4tux, were you able to configure banana pi uart correctly?

You have to log in before you can reply Login | Sign Up

Points Rules