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
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.
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
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>“
DON’T TRY AT HOME
SUPER MEGA ADVANCED
To Escape the Hardware Abstraction Layer (enabling direct hardware calls)
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