Skip to content

Commit

Permalink
add E.rebootToUF2() for entering UF2 bootloader mode
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 5, 2025
1 parent 48787f2 commit 1922c57
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 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
Add E.rebootToUF2() for entering UF2 bootloader mode (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
5 changes: 5 additions & 0 deletions src/jshardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ void jshReboot();
void jshRebootToDFU();
#endif

#ifdef ESPR_HAS_BOOTLOADER_UF2
/// Reboot to the UF2 bootloader. Device will reappear as a USB drive.
void jshRebootToUF2Bootloader();
#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
20 changes: 20 additions & 0 deletions src/jswrap_espruino.c
Original file line number Diff line number Diff line change
Expand Up @@ -2379,6 +2379,26 @@ void jswrap_espruino_rebootToDFU() {
#endif
}

/*JSON{
"type" : "staticmethod",
"ifdef" : "ESPR_HAS_BOOTLOADER_UF2",
"class" : "E",
"name" : "rebootToUF2",
"generate" : "jswrap_espruino_rebootToUF2"
}
Forces a hard reboot of the microcontroller into the UF2 bootloader.
**Note:** The device will stay in bootloader mode until it is power-cycled or reset.
*/
void jswrap_espruino_rebootToUF2() {
#ifdef ESPR_HAS_BOOTLOADER_UF2
jsiKill();
jsvKill();
jshKill();
jshRebootToUF2Bootloader();
#endif
}

// ----------------------------------------- USB Specific Stuff

#ifdef USE_USB_HID
Expand Down
1 change: 1 addition & 0 deletions src/jswrap_espruino.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ 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_rebootToUF2();

void jswrap_espruino_setUSBHID(JsVar *arr);
bool jswrap_espruino_sendUSBHID(JsVar *arr);
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 jshRebootToUF2Bootloader() {
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 1922c57

Please sign in to comment.