Skip to content

Commit

Permalink
Add STM32 rebootToDFU
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Nov 21, 2024
1 parent 61d9f11 commit 5d6ae8d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/jshardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
24 changes: 24 additions & 0 deletions src/jswrap_espruino.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/jswrap_espruino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5d6ae8d

Please sign in to comment.