Firmware Tips and Tricks

##Script DFU mode for local build and flash##

I build locally using the command line, and putting the spark into DFU mode manually can be a fiddle, so this simple addition to all sketches has allowed me to script the make and spark flash process. Its a little crude as the curl command just times out but it works for me. Perhaps the spark team can include this ability in a future firmware and spark-cli version.

#include "application.h"

int doDFU(String command) {

 FLASH_OTA_Update_SysFlag = 0x0000;
 Save_SystemFlags();
 BKP_WriteBackupRegister(BKP_DR10, 0x0000);
 USB_Cable_Config(DISABLE);
 NVIC_SystemReset();
 
 return 0;
}

void setup() {
    Spark.function("dfu",doDFU);
} 

void loop() {
}

Then your build script needs to include

make
curl https://api.spark.io/v1/devices/{{device}}/dfu -d access_token={{token}} -d "args=DO"
spark flash firmware core-firmware.bin
14 Likes