non-standard baud rate for the uart

I need the serial port supports non-standard baud rate,in the nano system
such as 250000
How do I do it?
the following code, I can not set the baut

//set the non-standard baud rate,lg:250000
int serial_set_speci_baud(int fd,int baud)
int ret =-1;
struct termios options;
struct serial_struct ss,ss_set;
tcflush(fd,TCIFLUSH);/handle unrecevie char/
if((ioctl(fd,TIOCGSERIAL,&ss)) < 0)
printf(“BAUD: error to get the serial_struct info:%s\n”,strerror(errno));
return -1;
ss.flags = ASYNC_SPD_CUST;
ss.custom_divisor = ss.baud_base / baud;
printf(“ss.custom_divisor = %d \r\n”,ss.custom_divisor);
if((ioctl(fd,TIOCSSERIAL,&ss)) < 0)
printf(“BAUD: error to set serial_struct:%s\n”,strerror(errno));
return -1;

ret = ioctl(fd,TIOCGSERIAL,&ss_set);
int boudrate11 = cfgetospeed(&options);
printf("ret= %d,BAUD: success set baud to %d,custom_divisor=%d,baud_base=%d\n",ret,baud,ss_set.custom_divisor,ss_set.baud_base);

return 0;


hello tpwang2000,

you might refer to Technical Reference Manual, please refer to divisor values for the MSB and LSB bits of the baud rate generator.
you might refer to below for default clock sources, and also adjust baud-rate settings.
for example,

you might also refer to discussion thread, Topic 1069632.
you’ll need to use termios2 struct settings and TCGET2/TCSET2 to set higher (>4Mbps) baudrates,