cancel
Showing results for 
Search instead for 
Did you mean: 

USART bootloader, make connecting to device more dependable

Gordon Madden
Associate III
Posted on May 09, 2018 at 18:27

I have written a firmware updater for the STM32F417, using the USART bootloader as described in AN3155. The updater/installer app is written in C# as a Windows app. It works on my dev computer (Windows 10), but additional testing on a Windows 7 computer failed. It always fails in the same place in the program and even on my computer, during debug, I see the same failure.

The failure occurs during the connection of the updater to the device running in bootloader mode. Here is the page from AN3155 describing the connection process:

0690X0000060B6TQAU.png

And here is my code implementing the above:

```

 public void SetUpComm(SerialPort _serialPort)

        {

            int byte_read = 0x00;

            var sevenF = new byte[] { 0x7F };##

            // Send 0x55 and 0xAA to peripheral input to execute SwitchToBootloader()

            // This will force a reboot and run River from the Upgrade Driver (River bootloader)

            var byte1 = new byte[] { 0x55 };

            var byte2 = new byte[] { 0xAA };

            _serialPort.Write(byte1, 0, 1);

            _serialPort.Write(byte2, 0, 1);

            _serialPort.ReadTimeout = 15000;

            // Wait for acknowledge byte from USART

            while (byte_read != ACK)

            {

                _serialPort.Write(sevenF, 0, 1);

                Thread.Sleep(100);

                // read ACK byte after parameters set and bootloader running

                try

                {

                    byte_read = _serialPort.ReadByte();

                }

                catch (TimeoutException)

                {

                    MessageBox.Show(''Failed to connect to device. Please check connections and run installer again.'',

                                    ''Serial Connection Failed!'',

                                    MessageBoxButtons.OK,

                                    MessageBoxIcon.Error);

                }

            }

        }

```

The first two bytes sent, 0x55 and 0xAA, are received by the running 417 board, which then resets and runs code in the startup file to place the processor in bootloader mode. Then the 0x7F byte is sent to establish communication with the 417 which can now receive bootloader commands per AN3155.

This works on my computer during a normal update. I run the Windows app, choose a COM port, a hex file, and hit update. The app is basically a state machine that goes through all the steps to complete the firmware update.

But during debug on my machine, and on upgrades on a Windows 7 machine, the program hangs on the line of code looking to receive an acknowledge byte from the 417.

         byte_read = _serialPort.ReadByte();

How can I get this section of code to be more reliable? I have added a timeout, so that if the connection is not made, at least the client gets an indication that something went wrong rather then indefinitely hanging.

This problem is hard to troubleshoot because the board has recently restarted and is running in bootloader mode.

I thought of restarting the board using code, but since the line it hangs on is reading from the USART, sending more bytes to the board is not an option.

If you have any ideas, either on the app (C#) or board (bootloader) side, please let me know.

Thanks!

0 REPLIES 0