Set dfu mode from software

Is there a way to set the dfu mode from software.
I have a setup where i have my uno r4 minima connected to a device remotely and I communicate with it remotely.

I used to do this with an atmel328p, where uploading the firmware was very straightforward and could very reliably upload code using the avrdude tool and a ssh terminal.

With the r4 minima i often find that the board fails to upload code with "no dfu capable device found". I then need to time a reset just before upload starts or in some cases double press the reset. From what I understand this puts the board into dfu mode.

Is there a way to get the board into this mode through the Arduino framework? If not how much work would it be to modify the bootloader to allow such a feature?

You can do a software reset into the double-tap mode. Give me just a second to find the code.

Here it is. I'll link you to the thread. Further up we were discovering how the DOUBLE_TAP_MAGIC thing works. It's all pretty well explained but it's a pretty long read.

The sketch in this post sets the DOUBLE_TAP_MAGIC up and then lets the watchdog time out to reset the board. This results in the board coming up in the slowly blinking bootloader mode that you get when you double tap.

Hi thank you so much for this, reading through the investigation you all did in such a documented thread is such a treat to go through.

Just a question, you mentioned pulling the ground low then letting the WDT reset the board puts us into bootloader pulsing led mode. Would i be wrong to call this DFU mode?

You also mention tapping the reset just before this happens get us bootloader mode. Is this the same as grounding the boot pin and double pressing reset? i.e. the mode that we can use the Renesas flash tool to put on a bootloader via usb?

Nope. That's what it is.

The point there was that it didn't matter if the reset happened because of the watchdog or because I hit reset. The simple fact that DOUBLE_TAP_MAGIC is in place means that when it resets it come sup in the DFU bootloader.

If you ground the boot pin then you come up in a mode ready to flash a bootloader. Without grounding the boot pin you end up in a mode ready to program.

Yes. That.

1 Like