diff --git a/src/jshardware.h b/src/jshardware.h index d2cd1a078..d20d519e7 100644 --- a/src/jshardware.h +++ b/src/jshardware.h @@ -407,6 +407,11 @@ void jsvGetProcessorPowerUsage(JsVar *devices); /// Perform a proper hard-reboot of the device void jshReboot(); +#ifdef STM32F4 +/// Reboot into DFU mode +void jshRebootToDFU(); +#endif + #if JSH_PORTV_COUNT>0 /// handler for virtual ports (eg. pins on an IO Expander). This should be defined for each type of board used void jshVirtualPinInitialise(); diff --git a/src/jswrap_espruino.c b/src/jswrap_espruino.c index d8f2a7500..20fa1d03f 100644 --- a/src/jswrap_espruino.c +++ b/src/jswrap_espruino.c @@ -2348,6 +2348,30 @@ void jswrap_espruino_reboot() { #endif } +/*JSON{ + "type" : "staticmethod", + "ifdef" : "STM32F4", + "class" : "E", + "name" : "rebootToDFU", + "generate" : "jswrap_espruino_rebootToDFU" +} +Forces a hard reboot of the microcontroller into the ST DFU mode + +**Note:** The device will stay in DFU mode until it is power-cycled or reset +*/ +void jswrap_espruino_rebootToDFU() { +#ifdef STM32F4 + // ensure `E.on('kill',...` gets called and everything is torn down correctly + jsiKill(); + jsvKill(); + jshKill(); + + jshRebootToDFU(); +#else // EMULATED + // if emulated, just call reset() to avoid a crash + jswrap_interface_reset(false); +#endif +} // ----------------------------------------- USB Specific Stuff diff --git a/src/jswrap_espruino.h b/src/jswrap_espruino.h index c482585a1..8f6fa81d2 100644 --- a/src/jswrap_espruino.h +++ b/src/jswrap_espruino.h @@ -73,6 +73,7 @@ JsVar *jswrap_espruino_memoryMap(JsVar *baseAddress, JsVar *registers); void jswrap_espruino_asm(JsVar *callspec, JsVar *args); void jswrap_espruino_compiledC(JsVar *code); void jswrap_espruino_reboot(); +void jswrap_espruino_rebootToDFU(); void jswrap_espruino_setUSBHID(JsVar *arr); bool jswrap_espruino_sendUSBHID(JsVar *arr);