Skip to content

Commit

Permalink
Allow entering UF2 bootloader mode by calling E.rebootToDFU()
Browse files Browse the repository at this point in the history
on devices that have such a bootloader

the device will reappear as a USB drive
  • Loading branch information
ssievert42 committed Jan 6, 2025
1 parent ba9eedb commit 610ae6c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
: nRF5x: ensure TIMER1_IRQHandler doesn't always wake idle loop up (fix #1900)
XiaoBLE: add board: Seeed XIAO BLE
Allow entering UF2 bootloader mode by calling E.rebootToDFU() (on boards that have such a bootloader)

2v25 : ESP32C3: Get analogRead working correctly
Graphics: Adjust image alignment when rotating images to avoid cropping (fix #2535)
Expand Down
3 changes: 2 additions & 1 deletion src/jshardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,9 @@ void jsvGetProcessorPowerUsage(JsVar *devices);
/// Perform a proper hard-reboot of the device
void jshReboot();

#ifdef STM32F4
#if defined(STM32F4) || defined(ESPR_HAS_BOOTLOADER_UF2)
/// Reboot into DFU mode
/// If the device has an UF2 bootloader, the device will reappear as a USB drive.
void jshRebootToDFU();
#endif

Expand Down
12 changes: 8 additions & 4 deletions src/jswrap_espruino.c
Original file line number Diff line number Diff line change
Expand Up @@ -2356,17 +2356,21 @@ void jswrap_espruino_reboot() {

/*JSON{
"type" : "staticmethod",
"ifdef" : "STM32F4",
"#if" : "defined(STM32F4) || defined(ESPR_HAS_BOOTLOADER_UF2)",
"class" : "E",
"name" : "rebootToDFU",
"generate" : "jswrap_espruino_rebootToDFU"
}
Forces a hard reboot of the microcontroller into the ST DFU mode
Forces a hard reboot of the microcontroller into DFU mode.
**Note:** The device will stay in DFU mode until it is power-cycled or reset
If this is an ST device, this will be the ST DFU mode.
If this device has an UF2 bootloader, it will reappear as a USB drive.
**Note:** The device will stay in DFU mode until it is power-cycled or reset.
*/
void jswrap_espruino_rebootToDFU() {
#ifdef STM32F4
#if defined(STM32F4) || defined(ESPR_HAS_BOOTLOADER_UF2)
// ensure `E.on('kill',...` gets called and everything is torn down correctly
jsiKill();
jsvKill();
Expand Down
8 changes: 8 additions & 0 deletions targets/nrf5x/jshardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -2887,6 +2887,14 @@ void jshReboot() {
NVIC_SystemReset();
}

#ifdef ESPR_HAS_BOOTLOADER_UF2
void jshRebootToDFU() {
enum { DFU_MAGIC_UF2_RESET = 0x57 };
nrf_power_gpregret_set(DFU_MAGIC_UF2_RESET);
NVIC_SystemReset();
}
#endif

/* Adds the estimated power usage of the microcontroller in uA to the 'devices' object. The CPU should be called 'CPU' */
void jsvGetProcessorPowerUsage(JsVar *devices) {
// draws 4mA flat out, 3uA nothing otherwise
Expand Down

0 comments on commit 610ae6c

Please sign in to comment.