Inconsistent bootloader start

When I do the double tap on the side button to get the Wio Terminal into bootloader mode it doesn’t always mount the Arduino drive even if the blue light is doing the slow breathing pulses.

I think this is similar to the issue seen in another post.

The “problem” is resolved by switching the switch to the off position and trying again. This seems to resync with Mac OS X and the Arduino drive is mounted and uploading works.

Sometimes the “Forcing reset using 1200bps open/close on port …” does manage to reset the board into the bootloader but this is pretty rare and when it does the application doesn’t get all the way through uploading.

My question is, can I jump into the bootloader from my application? This would allow me to trigger bootloader mode from the app and would avoid the double pressing dance every time I wanted to upload my app. Alternatively is the source for the bootloader available and I can hack on that instead.

My fingers are beginning to hurt from tweaking the side button!

To enter the bootloader using software method, you can set the baudrate to 1200(you can do this also in arduino ide serial monitor) and it will enter the bootloader.

But you need to make sure the in normal mode, that wio terminal is recognized by your PC so there is a serial port already.

Well that is clever, using the baud rate setting as a side channel!

I tried it and I made it work. I had to set the baud rate to 1200 and then close the connection to get a reset. It went into breathing blue light mode and then the Arduino drive mounted.

It does look like sam-ba program called from PlatformIO is already trying to do this but it doesn’t manage to upload the whole file.

CURRENT: upload_protocol = sam-ba
Looking for upload port...
Auto-detected: /dev/cu.usbmodem143401
Forcing reset using 1200bps open/close on port /dev/cu.usbmodem143401
Waiting for the new upload port...
Uploading .pio/build/seeed_wio_terminal/firmware.bin
Write 76288 bytes to flash (149 pages)

[                              ] 0% (0/149 pages)
[=                             ] 5% (8/149 pages)
[===                           ] 10% (16/149 pages)
[====                          ] 16% (24/149 pages)
[======                        ] 21% (32/149 pages)
[========                      ] 26% (40/149 pages)
[=========                     ] 32% (48/149 pages)
[===========                   ] 37% (56/149 pages)
[============                  ] 42% (64/149 pages)
[==============                ] 48% (72/149 pages)
[================              ] 53% (80/149 pages)
[=================             ] 59% (88/149 pages)
[===================           ] 64% (96/149 pages)
SAM-BA operation failed

If I modify ~/.platformio/platforms/atmelsam/builder/main.py to sleep after the new serial port is found

if bool(upload_options.get("wait_for_upload_port", False)):
    env.Replace(UPLOAD_PORT=env.WaitForNewSerialPort(before_ports))
    from time import sleep
    sleep(0.5)

Then I can upload repeatedly. It resets and sends the bin file without error.

Hi @derekmulcahy

Thanks for your feedback, we will take your advice and add the delay into the flashing tool, so that it hangs a bit before flashing. This will be released with the next SAMD core.

Thanks, adding delays always feels a bit of a kludge. My guess is that when the port reappears after the reset then it isn’t ready to transfer immediately.

Do you have a link to the bootloader code?

For macOS it has this issue and after some testing, adding slight delay right before flashing after detected the serial port did the trick.

Here is the bootloader for Wio Terminal: https://github.com/Seeed-Studio/ArduinoCore-samd/tree/master/bootloaders/wio_terminal