Picomod7 custom serial baud rate

  • Is there a way to set a custom serial baud rate on COM1 (/dev/ttySAC1) on Picomod7 ?


    What I tried:


    Code
    1. struct serial_struct new_serdrvinfo;
    2. ioctl(fd, TIOCGSERIAL, &new_serdrvinfo); // read driver settings
    3. new_serdrvinfo.flags = (new_serdrvinfo.flags & ~ASYNC_SPD_MASK) | ASYNC_SPD_CUST; // activate custom baudrate
    4. printf("BaudBase: %i - Divisor: %i\n",new_serdrvinfo.baud_base,new_serdrvinfo.custom_divisor);
    5. // new_serdrvinfo.baud_base=3000000;
    6. // new_serdrvinfo.custom_divisor = 6; // set custom divisor
    7. ioctl(fd, TIOCSSERIAL, &new_serdrvinfo); // write new driver settings


    The baud_base and custom_divisor parameters both are zero. When I try to set some values the ioctl(fd, TIOSSERIAL, xxx) blocks or the hole program hangs up.


    Calling #setserial -a /dev/ttySAC1 returns zero for the two parameters also. The UART IC is "undefined" and Port ist returned as 0x0000.


    It's possible to use some additional defined values like B460800 or B500000 (they are working) but I need 520000.


    Any idea? Thanks.

  • Could you pls try this:


    Code
    1. struct termios options;
    2. tcgetattr(fd, &options);
    3. cfsetispeed(&options, B38400);
    4. cfsetospeed(&options, B38400);
    5. options.c_cflag |= (CLOCAL | CREAD);
    6. options.c_cflag &= ~PARENB;
    7. options.c_cflag &= ~CSTOPB;
    8. options.c_cflag &= ~CSIZE;
    9. options.c_cflag |= CS8;
    10. tcsetattr(fd, TCSANOW, &options);

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • this already was in the code:


    Code
    1. tcgetattr(fd,&oldtio); /* save current port settings */
    2. newtio.c_cflag = B38400 | CS8 | CLOCAL | CREAD;
    3. newtio.c_iflag = IXANY;
    4. newtio.c_oflag = 0;
    5. newtio.c_lflag = 0;
    6. newtio.c_cc[VMIN]=1;
    7. newtio.c_cc[VTIME]=0;
    8. tcsetattr(fd,TCSANOW,&newtio);


    I also tried your piece of code. The result is the same. Baud_base and divisor are 0 and writing the values causes crashing the serial driver (I have to reboot to get the serial port working again). Maybe the problem ist, that there's no known serial driver (see setserial output)??

  • that code works for PicoMOD7


    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Setting one of the default bitrates defined by Bxxxxx is working. My problem is that I need a custom baudrate (520000 baud) because of communication with a slow CPU where I cannot divide the clock to a fast default value.


    Any ideas? Thanks.

  • What a baud rate do you need to setup?

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • 520000 would be the best rate. The cause is that I'm using a slow CPU on the other end of the serial connection that runs with only 40 MHz. On this slow CPU the clock divisor is verly low (2 or 3) on this high baud rate - so I'ts not possible to fit any standard value. Even at 115200 baud rate the clock error is about 3%.

  • A short check of the sources showed that you have to set the speed to B38400 if you want to use a custom divider. The Samsung serial driver does not set the baud_base correctly, so you can not use this value. I'm not 100% sure right now but I would expect the base clock to be 66.7MHz, so your divider should be something about 128 to get 520000. Using low values as 6 might result in a too high serial speed so that this causes the complete board to hang.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.