Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8093

Interfacing (DSI, CSI, I2C, etc.) • Re: Detecting BREAKs on PL011 UART

$
0
0
It's working for me, at least on a CM5 (which I had to hand). Which platform are you on?

Here's a simple test app which ignores serial data and just prints out changes to the counters:

Code:

// Mostly copied from https://stackoverflow.com/questions/78796301/c-serial-communication-why-does-read-lose-some-data-bytes-at-high-baud-rates/78800245#78800245#include <stdio.h>#include <fcntl.h>#include <sys/ioctl.h>#include <unistd.h>#include <linux/serial.h>struct serial_icounter_struct scount = { 0 };void chk_serial_rcvr(int serfd, int init){    struct serial_icounter_struct rcount;    if (init && ioctl(serfd, TIOCGICOUNT, &scount) < 0)        perror("TIOCGICOUNT error on init");    else {        if (ioctl(serfd, TIOCGICOUNT, &rcount) < 0)            perror("TIOCGICOUNT error");        else {            if (rcount.frame > scount.frame)                printf("ERROR: framing %d\n", rcount.frame - scount.frame);            if (rcount.overrun > scount.overrun)                printf("ERROR: overrun %d\n", rcount.overrun - scount.overrun);            if (rcount.parity > scount.parity)                printf("ERROR: parity %d\n", rcount.parity - scount.parity);            if (rcount.brk > scount.brk)                printf("ERROR: break %d\n", rcount.brk - scount.brk);            if (rcount.buf_overrun > scount.buf_overrun)                printf("ERROR: buffer overrun %d\n", rcount.buf_overrun - scount.buf_overrun);            scount = rcount;        }    }}int main(void){        char buf[80];        int fd = open("/dev/ttyAMA0", O_RDONLY, 0);        chk_serial_rcvr(fd, 1);        while (1) {//              int bytes = read(fd, buf, sizeof(buf));//              printf("rcvd %d\n", bytes);                chk_serial_rcvr(fd, 0);        }        close(fd);        return 0;}
I called it "sertest.c". Now compile and run it, occasionally pulling pin 10/GPIO 15 to GND:

Code:

$ gcc -o sertest sertest.c$ sudo stty -F /dev/ttyAMA0 115200$ ./sertestERROR: break 1ERROR: break 1ERROR: framing 1ERROR: break 2ERROR: break 2ERROR: framing 1ERROR: break 1ERROR: break 1ERROR: break 1

Statistics: Posted by PhilE — Tue Sep 23, 2025 8:50 am



Viewing all articles
Browse latest Browse all 8093

Trending Articles