Alex Feinman

Invalid baud rate set by blhost when updating over UART (Linux host)

Discussion created by Alex Feinman on Nov 8, 2016

This is actually two-part thing.

1. BLHOST ignores baud rate setting. Here is a snippet from serial.c (KBOOT 2.0)

switch (speed)

{
case 9600:
speed = B9600;
break;
case 38400:
speed = B38400;
break;
case 115200:
speed = B115200;
break;
case 57600:
default:
speed = B57600;
break;
}

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

Quite obviously the requested baud rate is being simply ignored in favor of 57600

This was supposed to be 

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

 

2. Even worse - the baud rate is then overwritten in serial_set_read_timeout

 

memset(&tty, 0x00, sizeof(tty));
cfmakeraw(&tty);

set a bunch of flags (but not speed)

if (tcsetattr(fd, TCSAFLUSH, &tty) < 0)
{
return -1;
}

For this to work properly it needs to be:

 

tcgetattr(fd, &tty);

instead of 

cfmakeraw(&tty);

Since most testing at Freescale has been obviously done on FRDM boards which use cdc_acm driver, this has not been an issue since cdc_acm driver ignores invalid baud rate (0 is invalid). However CP210x driver (Silicon Labs) assumes 300 bps (FTDI defaults to 9600). This results in time required to flash a small 50KB image being about 1hr. 

Outcomes