Cancelled at wrong moment, now stuck

While working on a project I had an idea for one more change, so I cancelled the upload to my device, edited the code, and hit the "Upload" button again.

Now my device is stuck in update mode. It's acting like a USB storage device, which is great but I have USB thumbdrives for that and I'd really like it to be programmable again.

I think I just barely understand how the upload process works for this device (Xiao SAMD21 from Seeed) so take these suggestions with a grain of salt. But just in case I actually do have the right idea about how this works / should work:

  • If an upload is in progress, and the user clicks cancel, and the device state has changed from the default state, don't cancel until the device has been restored to the default state.

  • If the user clicks the Upload button and the COM port is not available, look for the storage device, put the firmware on it, and reboot it. The problem I (think I) have right now is that Upload fails because the IDE is trying to se the COM port to toggle the device into update mode... but the COM port doesn't exist (because the device is already in update mode). The IDE just gives up. It should skip the toggle step and just keep going.

  • Add a menu item that will toggle the device out of update mode.

And a question: how can I get my device (Seeed Xiao SAMD21) out of update mode so I can run code on it again? I tried power-cycling it, but it just comes back up in storage mode. Perhaps because the old firmware was erased? If so, can I just copy the .bin file from the build\Seeeduino.samd.seeed_XIAO_m0 directory onto it? Or the .elf file?

Thanks in advance for any help.

Look on the SEEED site for instructions to get out of DFU mode.

Apparently that's as simple as copying a new UF2 firmware file to it.

So then the question is, how can I get Arduino IDE 2.0 (or the previous version, I'm not picky) to compile my code into a UF2 file?

I'm not familiar with your board but I suspect that the IDE already does that.

You can use Sketch → Export Compiled Binary in the IDE. After that you will find a Build directory in the sketch directory and somewhere in there should be your UF2 file.

Alternatively (it's a bit more work) is to enable verbose output during compilation under File → Preferences, compile and check the output. You will find something like

Compiling sketch...
"C:\\Users\\bugge\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\bugge\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\cores\\arduino" "-IC:\\Users\\bugge\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\variants\\eightanaloginputs" "C:\\Users\\bugge\\AppData\\Local\\arduino\\sketches\\4CBC6379057918F8372BF28776AC70E1\\sketch\\1386184.05.token.ino.cpp" -o "C:\\Users\\bugge\\AppData\\Local\\arduino\\sketches\\4CBC6379057918F8372BF28776AC70E1\\sketch\\1386184.05.token.ino.cpp.o"

where C:\Users\bugge\AppData\Local\arduino\sketches\4CBC6379057918F8372BF28776AC70E1 is the directory where the UF2 should be.

Well, yes, the IDE normally puts a UF2 file onto the device as part of the upload process, however when I click the upload button it just says "No device found on COM4, Failed uploading: uploading error: exit status 1." apparently because (as noted in my 2nd bullet) the IDE expects to find the device in normal mode, not in DFU mode, and the IDE doesn't proceed to the DFU step if it can't find the device on the serial port first. Catch 22.

"Export compiled binary" is how I got the aforementioned .bin and .elf files, but IDE 2 apparently doesn't produce UF2 files. Or, if it creating a UF2 file, it is not storing it in any obvious place. If it saved it somewhere under the sketch directory, or in \users<me>\appdata\local\arduino, I'd already be back to writing software. :slight_smile:

I found an elf2uf2 utility in the rp2040tools project on github, however that only produces the following output:

Detected FLASH binary
ERROR: Memory segment 00000000->0000fb04 is outside of valid address range for device

I'm stumped.

You asked

And that is what I tried to answer.

And I appreciate the suggestion.

And I don't doubt that your installation creates UF2 files in those directories.

But in my case, the IDE did not produce a UF2 file in any of the C:\Users<user>\AppData\Local\arduino\sketches directories.

It produced .elf, .bin, .hex, and other miscellaneous stuff, but no .uf2 files.

From C:\Users<me>\AppData\Local\arduino\sketches> there are three subdirectories, and if I run "dir /s *.bin" it shows three .bin files, but if I run "dir /s *.uf2" it prints "File Not Found."

Hi @NSFW. Try this:

  1. Disconnect the USB cable from the XIAO board.
  2. Connect a jumper wire to the "GND" pin on the board. The jumper wire must have a male pin on the other end from the connection of the board.
  3. Connect the USB cable to the board.
  4. Examine the top of the board. You will see two gold metal circles (test points) next to the USB socket, opposite from the LEDs. Tap the end of the jumper wire connected to the GND pin against the test point that is marked "RST" quickly twice.
    The double reset activates the bootloader. It will run until the board is reset normally, powered off, or an upload is done.
  5. You should now see the orange LED on the board start pulsing persistently.
  6. Select the port of your board from the Tools > Port menu in Arduino IDE.
  7. Start an upload in Arduino IDE.

The upload should now finish successfully.