Photon flashing

Fellow photoners,

I am trying to Flash my photon with the programmer shield.

I am a little confused as some literature points to openOCD for reflashing the firmware (such as @jvanier’s 5 step post) for which a USB cable connected to the programmer shield is sufficient and others point to stlink software which apparantely also needs the ST-LINK/V2 in-circuit debugger hardware (which I presume would be plugged into the JTAG interface on the programmer shield).

I just wanted to confirm with you experts which one is the way to go and not risk bricking my photon accidentally by choosing the wrong option. The first option only using a USB cable is certainly preferrable as opposed to having a ISP debugger. On that note, couldn’t just the dfu-util on its own accomplish this?

Thank you in advance

The first thing to try would be to use DFU for flashing. This is the preferred way to flash locally built firmware.

With the USB connected to the Photon and the Photon in DFU mode (press and hold SETUP, tap RESET, hold SETUP until blinking yellow), you can run this in the firmware/modules folder.
make all program-dfu PLATFORM=photon

If you build and flash the firmware for debugger usage (make all program-dfu PLATFORM=photon MODULAR=n USE_SWD_JTAG=y in the firmware/main folder), you can use OpenOCD to act as a bridge for GDB, the debugger.

I only flashed with the debugger once, when I wanted to replace the bootloader. It’s not something I ever needed to do for anything else.

When debugging, I do connect the USB to both the programmer shield and the Photon in order to avoid swapping cables for flashing and restarting OpenOCD.

Does that help or is it more confusing than ever? :sweat_smile:


What kind of flashing do you have in mind. For standard firmware (system and application) flashing you don’t need anything else than dfu-util and the Photon’s own USB socket.

Too late: @jvanier was faster with an even better answer.


Hi @jvanier,

Thanks for your awsome reply. I am actually working backwards from the code and just at a point where wanted to actually hack where your reply comes very handy. I note in the firmware/main/makefile if the platform id is that of the photon (6) it MODULAR?=y whereas your post mentions MODULAR=n. Is that OK?

Also can you please clarify:

How would you do it with one cable if you had to swap?

1 Like

The firmware is compiled and flashed in 3 pieces: system 1, system 2 and user. This is useful when only updating the user code because it’s very fast to flash only that part. This configuration is built with MODULAR=y (which is the default).

Since you can only load one executable out of the 3 in the debugger, it’s inconvenient because you see only 1/3 of the symbols.

That’s when you debug, it’s easier to compile everything in one executable with MODULAR=n.

When you are done debugging, flash with a modular firmware.

For the USB, plug the photon, go to dfu mode, flash, unplug and plug the debugger. Restart openocd and gdb.

1 Like

Another awesome reply. Thanks a lot @jvanier.

What you say makes sense as each part defines a few tables and corresponding functions which get mapped to the jump tables in the assembler code defined inside the macro. For some reason however, the user part contains no tables (and functions); or at least that part to me does not seem as obvious as the other two parts.