Flashing a Spark Core you bought elsewhere or in case of emergency

Update! The latest version includes a script that all the work below for you!
You just have to put your core in DFU mode and run:
sudo python /home/brewpi/utils/flashDfu.py

If you cannot flash via the web interface, because you do not have the BrewPi firmware on the device anymore (no 2 beeps at startup) or in any other emergency case, you can still flash via DFU by booting into the bootloader. Below are instructions on how to do that from the Raspberry Pi. Installing DFU under Linux is much easier than on windows, so below are the few easy steps.

To do this, download a compiled binary of dfu-util (this instruction is for the raspberry pi, if you are not running on a pi, you will need a different version). Do not install it from apt-get, the version on apt is outdated (0.5). After download, change the permissions to allow executing it with chmod:

cd ~
wget http://dfu-util.sourceforge.net/releases/dfu-util-0.7-binaries/linux-armel/dfu-util
sudo chmod 777 dfu-util

Also download the binary to flash to the user’s home directory:

wget https://github.com/BrewPi/firmware/releases/download/0.2.7/brewpi.bin

Put your spark core in DFU mode. This is done by resetting the device while holding the mode button until you see a yellow LED flashing. With the Spark Core being inside the enclosure, this is a bit harder.
There are two holes in the bottom. When looking into the USB connector, the right hole is above the mode button and the left hole is above the reset button.

I find it easiest to hold the mode button down with a pin, while plugging in the USB cable. After 3 seconds, the light should flash. If you hold it for 10 seconds, this will do a factory reset. Don’t do this.

List devices with dfu-util:

sudo ./dfu-util -l

It should show your device:

Found DFU: [1d50:607f] devnum=0, cfg=1, intf=0, alt=0, name="UNDEFINED"
Found DFU: [1d50:607f] devnum=0, cfg=1, intf=0, alt=1, name="UNDEFINED"

Now flash brewpi.bin to the spark core, with the following command:

sudo ./dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D brewpi.bin

The output should look like this:

dfu-util 0.7

Copyright 2005-2008 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2012 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to dfu-util@lists.gnumonks.org

Filter on vendor = 0x1d50 product = 0x607f
Opening DFU capable USB device... ID 1d50:607f
Run-time device DFU version 011a
Found DFU: [1d50:607f] devnum=0, cfg=1, intf=0, alt=0, name="@Internal Flash  /0x08000000/20*001Ka,108*001Kg"
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuDNLOAD-IDLE, status = 0
aborting previous incomplete transfer
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 1024
No valid DFU suffix signature
Warning: File has no DFU suffix
DfuSe interface name: "Internal Flash  "
Downloading to address = 0x08005000, size = 96308
...............................................................................................
File downloaded successfully
Transitioning to dfuMANIFEST state
Error during download get_status
That last error is normal. Your controller should beep and be back with version 0.2.7

After programming, run the following command to load default settings to the controller:

echo -ne 'E\n' > /dev/ttyACM0

I’m still waiting for my Raspberry Pi (my own misunderstanding of how things work), but…

If anyone wants to play around with flashing the core using dfu-util on Windows, I was able to get the Spark Core flashed using the instructions here: https://community.spark.io/t/tutorial-installing-dfu-driver-on-windows-24-feb-2015/3518 with the binaries available here: http://dfu-util.sourceforge.net/releases/dfu-util-0.7-binaries/win32-mingw32/

Hope it helps someone else out.

Update! The latest version includes a script that all the work below for you!You just have to put your core in DFU mode and run:

sudo python /home/brewpi/utils/flashDfu.py

Elco, I’m getting an error when trying to run the script.

pi@raspberrypi ~ $ sudo /home/brewpi/utils/flashDfu.py
/home/brewpi/utils/flashDfu.py: 17: /home/brewpi/utils/flashDfu.py: import: not found
/home/brewpi/utils/flashDfu.py: 19: /home/brewpi/utils/flashDfu.py: Syntax error: “(” unexpected

When I run as sudo, I get the following additional line.
/home/brewpi/utils/flashDfu.py: line 19: `if sys.version_info < (2, 7):’

Am I missing something on my Pi?

oops, missed python in command, updated instructions.

I just flashed mine. The instructions worked great. I’m glad you included the holes in the case. I don’t look forward to ever having to take that thing apart.

What should I do, I am unable to place the core into DFU mode? Is this core defective?

I have seen cores on which the mode button was a bit unreliable. Pressing harder or trying a different angle usually helped.
If it is the reset button that is giving issues, you can just plug in the power while holding the mode button.

Can you confirm that the mode button is what’s giving you issues?

The button appears to be working, because that is how I wiped the firmware. I am able to get it into blinking blue(listening) and attempt setup from command prompt but it gets hung up on either flashing green or fast flashing cyan. When I have tried to get it to reset (yellow and white lights) it won’t do anything.

You can put in in DFU mode by holding the mode button at power up for 3 seconds. It should be flashing yellow. Then use our flashdfu.py script to download and flash the firmware from the pi.

I have tried several times, but it won’t flash yellow.

It’s key that the mode button is pressed and held at the point of power on, or it won’t work and will boot up normally where DFU mode isn’t available.

I just tried this again, when holding down the mode button at power up it toggles between flashing green and fast flashing cyan. At no point will it flash yellow.

Maybe I’m not seeing the color as yellow, maybe what I think is green is actually yellow. Where should the spark be connected to? My windows pc or the raspberry pi? How do I run this script? Sorry for the basic questions I am not well versed in this, I’m going to need the spoon fed version step by step.

This is how to do it:

1 Like

I bought a Photon on my own, and finally had a bit of time to try flashing it.
For some reason, flashDfu.py wouldn’t detect the photon.
This method seemed promising… but at the end of all this, I just have a blank white screen. Any ideas?

Get the latest stable BrewPi release

$ wget https://github.com/BrewPi/firmware/releases/download/0.2.11/brewpi-0.2.11-photon.bin

Check connection to the photon

$ particle login
$ particle list
griffenbeer [1b0022000647343232363230] (Photon) is online

Put the Photon in DFU mode and check connection

$ sudo dfu-util -l
dfu-util 0.8

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2014 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/

Found DFU: [2b04:d006] ver=0200, devnum=6, cfg=1, intf=0, alt=1, name="@DCT Flash /0x00000000/01*016Kg", serial="00000000010C"
Found DFU: [2b04:d006] ver=0200, devnum=6, cfg=1, intf=0, alt=0, name="@Internal Flash /0x08000000/03*016Ka,01*016Kg,01*064Kg,07*128Kg", serial="00000000010C"

Then flash the photon

$ sudo dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D brewpi-0.2.11-photon.bin
dfu-util 0.8

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2014 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:d006
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 = 0x080a0000, size = 57432
Download	[=========================] 100% 57432 bytes
Download done.
File downloaded successfully
dfu-util: Error during download get_status