Local Compile - Electron Workflow

Seems Electron uses data of the grid, I would like to keep flashing locally thru USB.

What’s the recommended easiest workflow for flashing from a MAC?

Hey @frlobo – one of the easiest ways is to download the binary using the Web IDE, and flashing using the CLI. Click this button at build.particle.io to compile and download a binary!

Let me know if that helps!

@frlobo, if you tired to flash an Electron via Particle Build you would get a message box, warning you about the data consumption and in there also a button USB FLASHING GUIDE that would have directed you to the exact same instructions @will just gave you.
https://docs.particle.io/guide/tools-and-features/cli/electron/#flashing-over-serial-for-the-electron

Thanks Much @will @ScruffR !

I was actually looking to see if anyone had a better workflow like an ATOM extension that can program via USB or a suggestion to make the process faster.

With a local gcc-arm build on my Mac, I can compile a small app and flash it over USB to an electron in under 6 seconds with a single command. Setting it up the first time may be a pain, but it’s worth it in the end if you expect to build with any frequency.

Can you elaborate a little more :smile:

Sounds like what I am looking for!

Right now, I have a text editor opened and a terminal window open on the right.

I compile using CLI and then flash using CLI. I am going to write a script that I can do both commands with one shell script. But I don't want to write the wheel. That's why I ask!

This is how I did build my own wheel for Windows (have a link which executes in the source folder and provides photon or electron as target parameter %1)
I guess Mac would be just as simple (not really a wheel, just a nob :wink: )

del *.bin
cmd /c "particle compile %1 . firmware.bin"
cmd /c "particle flash --usb firmware.bin"
pause

If I was lazy, I’d even open COM3 with 14400 for DFU Mode :sunglasses:

1 Like

It will be much easier to write a script to automate the CLI. The CLI uses the Particle build farm over the Internet to do your build and works quite well. I’d start there first.

The local build uses a local compiler tool chain and a copy of the open source repository to build entirely on your computer, no Internet required. Also, it’s how you build with develop version of the system firmware (pre-release). The instructions are here:

One of the members here wrote up something that looks pretty good for installing all of the local build tools on OS X and Linux, though I’ve never used it.

1 Like

Hi @frlobo
As @rickkas7 just mentioned, my script works pretty well.

  • Run my script with install to install the particle toolchain and dfu-util on your machine:
./po-util.sh install
  • Put your Electron into dfu mode and run this command to recompile the system firmware so that you can trigger dfu without pressing the buttons on your Electron:
./po-util.sh patch

This changes the baud rate to trigger DFU from 14400 to 19200, a much nicer baud rate that is more compatible.

  • The rest of my script’s commands can be found on its gist page.

If you just want to be able to flash locally and you are okay with compiling in the cloud, make another script with this in it:

#elup.sh - Electron Upload: Compile in the cloud and flash over USB with DFU-util
#!/bin/bash

code_directory ="$1"
modem=`ls -1 /dev/cu.* | grep -vi bluetooth | tail -1`

stty -f $modem 19200

rm -rf electron_firmware*

particle compile electron "$code_directory"

particle flash --usb electron_firmware*

Create an alias for the script in your .bashrc so you can use it anywhere with:

echo 'alias elup="~/elup.sh"' >> .bashrc

To use the script simply type elup and the folder that contains your code. For example, if your code is in a folder called firmware, you would type elup firmware.

Example Output:

$ elup firmware

Compiling code for electron

Including:
    /Users/nrobinson/electron-project/firmware/main.cpp
    /Users/nrobinson/electron-project/firmware/LiquidCrystal.h
    /Users/nrobinson/electron-project/firmware/LiquidCrystal.cpp
attempting to compile firmware 
pushing file: /Users/nrobinson/electron-project/firmware/main.cpp
pushing file: /Users/nrobinson/electron-project/firmware/LiquidCrystal.h
pushing file: /Users/nrobinson/electron-project/firmware/LiquidCrystal.cpp
downloading binary from: /v1/binaries/5701506e1a9247501e5cbc55
saving to: electron_firmware_1459703915924.bin
Memory use: 
   text	   data	    bss	    dec	    hex	filename
   4428	     12	    460	   4900	   1324	/spark/compile_service/shared/workspace/10_electron_15_1/firmware/ae3f1b2cbced536e267c6bc0edb42c6624f8f867573d1734d384f80efbda/ae3f1b2cbced536e267c6bc0edb42c6624f8f867573d1734d384f80efbda.elf

Compile succeeded.
Saved firmware to: /Users/nrobinson/electron-project/electron_firmware_1459703915924.bin
running dfu-util -l
Found DFU device 2b04:d00a
checking file electron_firmware_1459703915924.bin
spawning dfu-util -d 2b04:d00a -a 0 -i 0 -s 0x08080000:leave -D electron_firmware_1459703915924.bin
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
Opening DFU capable USB device...
ID 2b04:d00a
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 4096
DfuSe interface name: "Internal Flash   "
Downloading to address = 0x08080000, size = 4440
Download	[=========================] 100%         4440 bytes
Download done.
File downloaded successfully

Flash success!
1 Like

This is a treasure trove!

Why doesn’t particle-dev has USB flashing capabilities?

Alright so I think the best bet is to start with cloud compile and then move on to local compile.

Thanks for the info!

Question:

How will the electron go into DFU mode without pressing the buttons?

Can this also be used to do cloud compile and local USB flashing?

You can force an Electron (or a Photon) into DFU mode without touching the buttons when directly connected by USB by opening a serial connection to it at an appropriate baud rate. The default is 14400 baud. On the Mac, I use this command:

stty -f /dev/cu.usbmodemfd3411 14400

The number part after the usbmodemfd will vary and also differentiates which device you want if you have multiple devices connected by USB.

1 Like

I prefer to change the baud rate to 19200 on my devices. 14440 baud rate does not work on Linux.

Yes, this can be used for cloud compile and local flashing. The script above uses the cloud to generate a binary, downloads it and flashes it to an Electron over USB using dfu-util.

Cloud compile is much more convenient. Local compile is only better when your computer has no internet or if you want to modify and recompile the system firmware.

Just a note: you can install the terminal-plus package in atom to give you an embedded terminal in your atom workspace.

1 Like

Hey all--this is something that we've spec'ed out and would also like to see added to Dev. Can't commit to a timeline yet, but it's where the offline IDE is headed.

1 Like

UPDATE: Build Status

I have moved my script over from a gist to a repository.

I have also made it super easy to install my script:

curl -fsSL https://git.io/vwRRf | bash

Additional functions have also been added, including OTA flashing and manual DFU control.
Find out more in my repository, https://github.com/nrobinson2000/po-util

1 Like