If you’ve developed code for the photon, you know how annoying the necessity to develop and compile code in the “particle cloud.” Every time you have to make a change, you have to:
- upload your code
- wait for it to compile
- download it
- Flash it back to the photon
- Sometimes… this makes me angry.
This post is a walks through the process to completely bypass those steps. After the walkthrough, you should be able to:
- Write / Develop Code on your machine
- Compile that code on your machine
- Flash the compiled code to your photon over usb
Use
- No need to use the particle dev editor
- Alternatively, no need to copy and paste the files over and over
- At the end of the compilation, before the firmware is flashed, the code is validated
- If you don’t have internet, you can still check your code
- If your code breaks and your photon won’t boot, you can factory reset (sortof)
- Run the make clean all command at the bottom
- There is a way to completely bypass the entire cloud api
- Run the rest api locally on a computer
Photon -> Router -> Telcom -> Some Server at the NSA -> Particle- Photon -> Router -> Your Laptop
- This means no need for outbound internet (particle rest api etc)
- I might post a walkthrough if someone wants it
- Run the rest api locally on a computer
- You hate the man
I Have not tested this walkthrough…
Let me know if anything breaks or doesn’t work, and I can help you fix it.
Requirements
This assumes you have git as well as command line tools / xcode.
If you don’t know them, you can just ask me or something.
You can follow the confusing version here, or…
OS X users can install the toolchain with Homebrew:
brew install cmake
brew tap PX4/homebrew-px4
brew update
brew install gcc-arm-none-eabi-49
arm-none-eabi-gcc --version
(should now say v4.9.x)brew install dfu-util
- GCC
- Make
- Device Firmware Upgrade Utilities
- Zatig (for windows users only)
- Git
If you’re on Windows… may the odds be ever in your favor…
No Mercy :*(
Step 1: Get the firmware
The firmware contains the code that makes the photon operate, the libraries, routines, etc. You need to download the firmware so your computer has access to all the files necessary to compile the binaries that will be written to the photons memory.
- Open the Terminal app
- Enter the following
1 2 3 4 5 6 7 8 9 |
# working_dir is whatever directory you want to develop in cd "<working_dir>" git clone https://github.com/spark/firmware.git cd firmware/modules git checkout latest |
The directories should look something like this
Step 2: Nice Environment Vars
This is one I found recently, if you add the following env variable, make will automatically put the photon in dfu mode.
1 2 3 4 5 6 7 |
# /dev/tty.usbmodem12345 is the usb connected photon port export PARTICLE_SERIAL_DEV=/dev/tty.usbmodem12345 # Set the platform default export PLATFORM=photon |
If you want them to stay after you close the terminal, ask someone how to add them to your bash profile.
Step 3: First Build
This will clean and build the file at firmware/user/src/application.cpp which should contain the default tinker app. It will build the system firmware as well as the app.
PUT THE BOARD INTO DFU MODE
If you didn’t put in the env variables above, or it didn’t automatically put the board into dfu mode ( orange ish yellow ), or you just wanna do it manually because you’re a badass and nobody tells you what to do…
- Press both buttons
- let go of one
- Wait… Should immediately turn purple… Wait…
- Should blink orange-ish yellow
1 2 3 4 5 |
make clean all PLATFORM=photon -s program-dfu # This will transfer the code to the photon make program-dfu |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# EXAMPLE OUTPUT [snow@snow modules]$ make all PLATFORM=photon APP=test program-dfu /Users/snow/Documents/dev/hardware/particle/firmware/modules/photon/system-part1/makefile /Users/snow/Documents/dev/hardware/particle/firmware/modules/photon/system-part2/makefile /Users/snow/Documents/dev/hardware/particle/firmware/modules/photon/user-part/makefile /Applications/Xcode.app/Contents/Developer/usr/bin/make -C /Users/snow/Documents/dev/hardware/particle/firmware/modules/photon/system-part1/ all program-dfu APP=test PLATFORM=photon ..... ..... Cut out the middle man ..... Copyright 2011-2012 Stefan Schmidt, 2013-2014 Tormod Volden This program is Free Software and has ABSOLUTELY NO WARRANTY Please report bugs to dfu-util@lists.gnumonks.org Suffix successfully added to file Serial device PARTICLE_SERIAL_DEV : not available Flashing using dfu: dfu-util -d 0x2B04:0xD006 -a 0 -s 0x80A0000:leave -D ../../../build/target/user-part/platform-6-m/test.dfu 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 dfu-util@lists.gnumonks.org 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 = 6812 Download [ ] 0% Download [ ] 0% Download [=============== ] 60% 409 Download [=========================] 100% 6812 bytes Download done. File downloaded successfully |
The Compiled Files
Step 4: Build Options
You can use any/all of these clean all of these
make
- clean – will remove the compiled firmwares, for (re)compile system
- all – compile all the changed code
- program-dfu – flash the firmware to a photon
- -s – stands for silent, if you’re having issues take it out
- APPDIR – an external directory containing code to compile
OR - APP – an app stored in “firmware/user/applications/< app_name>“
1 |
make clean all program-dfu PLATFORM=photon -s APPDIR=~/app_name |
DON’T TRY AT HOME
SUPER MEGA ADVANCED
To Escape the Hardware Abstraction Layer (enabling direct hardware calls)
1 2 3 |
make clean make APPDIR=~/app_name SPARK_NO_PLATFORM=y |
More
There are more detailed docs at:
github wiki It’s hard to navigate, and I imagine it’s a bit confusing.
gettingstarted Other potentially helpful github wiki
Leave a Reply