# Workbench feature suggestion: auto-DFU when flashing locally

**URL:** https://community.particle.io/t/workbench-feature-suggestion-auto-dfu-when-flashing-locally/46484
**Category:** Particle Workbench
**Created:** [December 21, 2018, 5:32am UTC](https://community.particle.io/t/workbench-feature-suggestion-auto-dfu-when-flashing-locally/46484 "2018-12-21T05:32:48Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![chuank](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/chuank/32/3617_2.png) [@chuank](https://community.particle.io/u/chuank)
#### Post date: [December 21, 2018, 5:32am UTC](https://community.particle.io/t/workbench-feature-suggestion-auto-dfu-when-flashing-locally/46484/1 "2018-12-21T05:32:48Z")

</div>

It will be great if we have an option to automatically bring a device into DFU mode without having to perform the hardware button-pressing combination.

Opening & closing a serial terminal to the device at 14400 baud will put it into DFU mode. On the mac, I’m using `stty` to trigger DFU right before flashing:

```auto
stty -f /dev/cu.usbmodem141110 14400

```

Hope a cross-platform implementation of this can be Included as part of the local flashing build task in the next alpha release in 2019… 🙂

---

<div class="post-metadata">

### Author: ![kubark42](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kubark42](https://community.particle.io/u/kubark42)
#### Post date: [January 2, 2019, 3:53pm UTC](https://community.particle.io/t/workbench-feature-suggestion-auto-dfu-when-flashing-locally/46484/2 "2019-01-02T15:53:21Z")

</div>

That’s a wonderful idea, and thanks a lot for the tip on programatically forcing devices into DFU mode.

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [January 2, 2019, 4:00pm UTC](https://community.particle.io/t/workbench-feature-suggestion-auto-dfu-when-flashing-locally/46484/3 "2019-01-02T16:00:21Z")

</div>

For Windows users: `mode COMx 14400` will do the trick too.

The intent is to implement USB control requests which don’t require the devices to expose a USB CDC device for this to function - once these are in place a platform independent solution should be a no-brainer 😉

* * *

@chuank, excuse the ignorance, but will it _always_ be `usbmodem141110` on any Mac or is this just as “volatile” as the COMx on Windows?

---

<div class="post-metadata">

### Author: ![kubark42](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kubark42](https://community.particle.io/u/kubark42)
#### Post date: [January 2, 2019, 4:05pm UTC](https://community.particle.io/t/workbench-feature-suggestion-auto-dfu-when-flashing-locally/46484/4 "2019-01-02T16:05:59Z")

</div>

> [@ScruffR](#):
>
> ...will it always be `usbmodem141110` on any Mac or is this just as “volatile” as the COMx on Windows?

@ScruffR, happily on macOS it's not volatile in the slightest. But it is unique, so other users will have to figure out which `usbmodemXXXXXX` to use. 99.9% of the time this is just a matter of hitting `<TAB>` to autocomplete. The only reason there would ever be a conflict here is if you have multiple serial port devices plugged in at once.

I've never understood why Windows makes it difficult/impossible to have a truly unique serial port ID, but it is what it is.

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [January 2, 2019, 4:15pm UTC](https://community.particle.io/t/workbench-feature-suggestion-auto-dfu-when-flashing-locally/46484/5 "2019-01-02T16:15:36Z")

</div>

> [@kubark42](#):
>
> I’ve never understood why Windows makes it difficult/impossible to have a truly unique serial port ID, but it is what it is.

For me it's not really volatile for the same machine but between machines.  
Once I've assigned a definet COM port number for that device (or group of devices - when I'm sure to have only one device at a time plugged, all Particle devices can share the same port number).

---

<div class="post-metadata">

### Author: ![chuank](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/chuank/32/3617_2.png) [@chuank](https://community.particle.io/u/chuank)
#### Post date: [January 3, 2019, 1:18am UTC](https://community.particle.io/t/workbench-feature-suggestion-auto-dfu-when-flashing-locally/46484/6 "2019-01-03T01:18:55Z")

</div>

> [@kubark42](#):
>
> @ScruffR, happily on macOS it’s not volatile in the slightest. But it is unique, so other users will have to figure out which usbmodemXXXXXX to use.

Yes on the mac it stays the same. In my above example I have a 4-port USB hub plugged in via a KVM, and even in this scenario, they enumerated themselves consistently to the point where I have stuck labels on my USB hub to remind me which is which.

Interestingly, the ports directly on the Mac itself are shorter (`usbmodemXXXXX`), and are not volatile as well.

However, the recent Mojave (or was it the one before?) update did assign slightly new port numbers (`usbmodem1421` is now `usbmodem14201`). I'm guessing the macOS developers wanted to add a leading zero to the port enumeration. Why I do not know, but like @kubark42 said it's just a matter of hitting the `<TAB>` key twice in terminal to show a list of devices beginning with `/dev/cu.usbmodem` ...

Looking forward to the USB control request implementation, the less finger oil we can deposit on the hardware the better 🙂

---

<div class="post-metadata">

### Author: ![Erich](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@Erich](https://community.particle.io/u/Erich)
#### Post date: [March 23, 2019, 7:26am UTC](https://community.particle.io/t/workbench-feature-suggestion-auto-dfu-when-flashing-locally/46484/7 "2019-03-23T07:26:59Z")

</div>

Is there a way to add the “stty -f /dev/cu.usbmodem141110 14400” line to the workbench “Particle:Flash local” command?

---

<div class="post-metadata">

### Author: ![Blaszki](https://avatars.discourse-cdn.com/v4/letter/b/b77776/32.png) [@Blaszki](https://community.particle.io/u/Blaszki)
#### Post date: [June 25, 2019, 9:10am UTC](https://community.particle.io/t/workbench-feature-suggestion-auto-dfu-when-flashing-locally/46484/8 "2019-06-25T09:10:01Z")

</div>

Hi Erich,  
you can modified some target (e.g flash-user) from Makefile in .particle/toolchains/buildscripts/x.y.z/Makefile  
I use “particle usb dfu && sleep 2” instead “stty -f /dev/cu.usbmodem141110 14400”

```auto
***.particle/toolchains/buildscripts/1.5.1/Makefile_old	2019-06-25 10:39:47.869966515 +0200
--- .particle/toolchains/buildscripts/1.5.1/Makefile	2019-06-25 10:54:38.230963118 +0200
***************
 ***49,69****
--- 49,73 ----
  
  # Compile and flash the user part
  flash-user: preprocess
+ particle usb dfu && sleep 2
  	cd "${DEVICE_OS_PATH}/main" && make all program-dfu
  	$(call print_success,FLASHED SUCCESSFULLY)
  
  # Compile and flash the user and system parts
  flash-all: preprocess
+ particle usb dfu && sleep 2
  	cd "${DEVICE_OS_PATH}/modules" && make all program-dfu
  	$(call print_success,FLASHED SUCCESSFULLY)
  
  # Compile and flash debug build
  flash-debug: preprocess
+ particle usb dfu && sleep 2
  	cd "${DEVICE_OS_PATH}/main" && make all program-dfu MODULAR=n USE_SWD_JTAG=y DEBUG_BUILD=y
  	$(call print_notice,ONCE YOU ARE FINISHED DEBUGGING REMEMBER TO RUN `Particle: Flash application & DeviceOS (local)`)
  	$(call print_success,FLASHED SUCCESSFULLY)

```
