Setup Done Flag in Setup - OK to leave in with production Firmware?

Is there any harm in leaving the code that resets the setup done flag in your “production” firmware? I’m tempted to leave it in all the time so I only need to download one program when commissioning new devices instead of 2 or requiring the Particle USB Setup-Done. I.e. Can code like this be left in? If so, any negative side affects besides setting the setup done flag again even though it’s already set every time the device powers up/is reset.

#include "Particle.h"
#include "dct.h"


void setup() {
    // This clears the setup done flag on brand new devices so it won't stay in listening mode
    const uint8_t val = 0x01;
    dct_write_app_data(&val, DCT_SETUP_DONE_OFFSET, 1);

    // This is just so you know the operation is complete
    pinMode(D7, OUTPUT);
    digitalWrite(D7, HIGH);

void loop() {

Reason I ask is, previously I used the following commands to commission a device:

  1. Plug in USB and run “Particle USB Identify” - To Obtain the Device_ID of the device and then manually copy/paste and add it to my product/account/SQL backend
  2. “Particle USB setup-done” command to clear the flag
  3. Particle Flash Application and Device OS

This was all done over USB. I disliked this because my enclosure has limited to no access to the USB port. It also took a fair bit of time to flash over USB compared to SWD. Not crazy amount of time but via JLink/SWD was way faster (like 1-2 seconds). Using SWD/JTAG | Reference | Particle

I also now use USB 2D barcode scanner to quickly add Particle Devices and/or lookup the Serial number using serial look-up tool. Maybe eventually I’d make my own script to call the API to the Particle Cloud API to do all the steps automagically.

So the question is… should I flash 2 programs via SWD/JTAG (1 to reset setup done flag, 2 my application firmware) or am I ok with just flashing 1 (my application firmware that also sets the setup done flag every time)? What’s the harm in leaving it in all the time if any?

So I created my initial Python script to do the necessary steps to commission a new device today. For now I am first flashing a .HEX file via JTAG/SWD, waiting a few seconds and then flashing the user firmware. This seems to work just fine. Since it flashes in just a few seconds via Python script, I guess it’s just as easy to flash it twice but still curious if I can just do it all from my main production firmware build.

For reference in my DeployDevice.PY python script, this is what I am doing to set the Setup Done flag and then load user firmware.

#Flash the Blank Firmware to reset the Setup Done Flag
os.chdir(r"C:\Users\{{Location on my PC where I store the file}}\SetupDoneFlag\hex")
os.system("nrfjprog -f NRF52 --program SetupDone_V3.1.hex --chiperase --reset")

#Wait 5 seconds for the firmware to run one and clear the Setup Done Flag

#Now Flash the Device OS
os.chdir(r"C:\Users\{{Location on my PC where I store the file}}\hex")
os.system("nrfjprog -f NRF52 --program UserFirmwareV3.1.hex --chiperase --reset")

By the way… between having a 2D Barcode scanner and a Python script, it vastly speeds up and reduces user error when deploying new devices. This includes setting setup done flag, loads user firmware (and device OS), claims the device on Particle cloud, updates device name and notes within Particle cloud and adds it to my SQL backend.

You can leave it in. If the DCT doesn’t change, it’s not actually written so there should not be flash wear from doing so. If you’re flashing by JTAG/SWD, it’s probably the best way to do it, because you can’t setup done from SWD.

Very good. Thanks @rickkas7. I’ll add this to the main firmware and just flash the program once. That makes it easy!

Actually, on second though, you should add a check to be safe. It’s just:

    uint8_t read_value = 0x01;
    dct_read_app_data_copy(DCT_SETUP_DONE_OFFSET, &read_value, 1);
    if(read_value != 1)
        const uint8_t write_value = 1;
        dct_write_app_data(&write_value, DCT_SETUP_DONE_OFFSET, 1);

Then it’s definitely safe to leave in your production firmware. We’ve used that technique.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.