diff --git a/ChangeLog b/ChangeLog index c27301b24..cd39e5b13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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) diff --git a/src/jshardware.h b/src/jshardware.h index 186ad9a1b..71d38b673 100644 --- a/src/jshardware.h +++ b/src/jshardware.h @@ -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 diff --git a/src/jswrap_espruino.c b/src/jswrap_espruino.c index d7ef62f23..ae417c2cd 100644 --- a/src/jswrap_espruino.c +++ b/src/jswrap_espruino.c @@ -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(); diff --git a/targets/nrf5x/jshardware.c b/targets/nrf5x/jshardware.c index 143ec5307..a95903022 100644 --- a/targets/nrf5x/jshardware.c +++ b/targets/nrf5x/jshardware.c @@ -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