Firmware Tips and Tricks

@mdma Finally I have discovered where the problem was!! :facepunch:

This behaviour seems to be particular to some versions of Ubuntu. I’m testing it with the 14.04.2 LTS version, and it also seems to be present in the 12.04 version.

It’s not due to a permission problem writing the ttyACM0 device, nor due to a userserial module problem (that one guy commented in the StackOverflow post you have linked, using modprobe -r usbserial and then modprobe usbserial).

The problem is that in some Ubuntu versions, the 14400 baudrate is NOT supported as an standard port speed. The stty command fails at that speed, but not in many others like 9600, 19200, 38400, 115200, etc.

Let’s see. The port is by default configured at 115200, nothing special here:

$ stty -F /dev/ttyACM0
speed 115200 baud; line = 0;
kill = ^H; eof = ^A; min = 1; time = 0;
-icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

Setting it to 14400 fails!!, as it would fail when setting at any non standard baudrate:

$ stty -F /dev/ttyACM0 14400
stty: invalid argument ‘14400’
Try 'stty --help' for more information.

$ stty -F /dev/ttyACM0 56000
stty: invalid argument ‘56000’
Try 'stty --help' for more information.

But setting it to other rates doesn’t fail:

$ stty -F /dev/ttyACM0 9600
$ stty -F /dev/ttyACM0 
speed 9600 baud; line = 0;
kill = ^H; eof = ^A; min = 1; time = 0;
-icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

$ stty -F /dev/ttyACM0 19200
$ stty -F /dev/ttyACM0 
speed 19200 baud; line = 0;
kill = ^H; eof = ^A; min = 1; time = 0;
-icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

$ stty -F /dev/ttyACM0 38400
$ stty -F /dev/ttyACM0 
speed 38400 baud; line = 0;
kill = ^H; eof = ^A; min = 1; time = 0;
-icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

After this, I found out that you have a constant variable START_DFU_FLASHER_SERIAL_SPEED=14400 defined in build/module.mk file, related exactly to this behavious of auto DFU. And after changing it to 19200 (for example) the problem is solved!!!.

Now, when calling stty from both GNU/Linux and Mac OSX with 19200 baudrate, it puts the Photon in DFU mode automatically!!.

Summarising, to auto enter and exit DFU mode with the Photon without touching any button:

Mac OSX:

$ stty -f /dev/tty.usbmodemXXXXX 19200
$ dfu-util -d 2b04:d006 -a 0 -s 0x080A0000:leave -D /dev/null

GNU/Linux:

$ stty -F /dev/ttyACM0 19200
$ dfu-util -d 2b04:d006 -a 0 -s 0x080A0000:leave -D /dev/null

NOTE: The 28800 baud rate to enter in Ymodem mode is also not supported in Ubuntu, but yes in OSX, so the same should be made in the build/module.mk file with the START_YMODEM_FLASHER_SERIAL_SPEED=28800 in order to make it work in Ubuntu using stty.

$ stty -F /dev/ttyACM0 28800
stty: invalid argument ‘28800’
Try 'stty --help' for more information.

@mdma I don’t really know the possible side effects of changing the START_DFU_FLASHER_SERIAL_SPEED to 19200, or the START_YMODEM_FLASHER_SERIAL_SPEED to any other rate. Could you clarify if this has any side effect or if this values are just chosen to detect the baudrate changing from 115200 to these fixed values to force entering in the corresponding mode?

As always, thank you very much for your support!! :+1::+1::+1:

2 Likes