Skip to content

Commit a4246bc

Browse files
committed
Fix two watchdog crashes
Fixes a crash from trying to raise an exception when trying to deinit a RESET wdt by not raising an exception. Fixes a crash when raise a wdt exception in the REPL when waiting for input. We now catch and print any exceptions raised. Fixes #5261
1 parent 8fbb3e6 commit a4246bc

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

lib/utils/pyexec.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,21 @@ int pyexec_friendly_repl(void) {
650650
}
651651

652652
vstr_reset(&line);
653-
int ret = readline(&line, ">>> ");
653+
654+
nlr_buf_t nlr;
655+
nlr.ret_val = NULL;
656+
int ret = 0;
657+
if (nlr_push(&nlr) == 0) {
658+
ret = readline(&line, ">>> ");
659+
} else {
660+
// Uncaught exception
661+
mp_handle_pending(false); // clear any pending exceptions (and run any callbacks)
662+
663+
// Print exceptions but stay in the REPL. There are very few delayed
664+
// exceptions. The WatchDogTimer can raise one though.
665+
mp_hal_stdout_tx_str("\r\n");
666+
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
667+
}
654668
mp_parse_input_kind_t parse_input_kind = MP_PARSE_SINGLE_INPUT;
655669

656670
if (ret == CHAR_CTRL_A) {

locale/circuitpython.pot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3939,6 +3939,7 @@ msgstr ""
39393939
#: ports/esp32s2/boards/gravitech_cucumber_r/mpconfigboard.h
39403940
#: ports/esp32s2/boards/gravitech_cucumber_rs/mpconfigboard.h
39413941
#: ports/esp32s2/boards/lilygo_ttgo_t8_s2_st7789/mpconfigboard.h
3942+
#: ports/esp32s2/boards/lolin_s2_mini/mpconfigboard.h
39423943
#: ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h
39433944
#: ports/esp32s2/boards/morpheans_morphesp-240/mpconfigboard.h
39443945
#: ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/mpconfigboard.h

ports/nrf/common-hal/watchdog/WatchDogTimer.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <math.h>
2929
#include <string.h>
3030

31+
#include "py/gc.h"
3132
#include "py/obj.h"
3233
#include "py/objproperty.h"
3334
#include "py/runtime.h"
@@ -94,7 +95,11 @@ void common_hal_watchdog_feed(watchdog_watchdogtimer_obj_t *self) {
9495

9596
void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) {
9697
if (self->mode == WATCHDOGMODE_RESET) {
97-
mp_raise_NotImplementedError(translate("WatchDogTimer cannot be deinitialized once mode is set to RESET"));
98+
if (gc_alloc_possible()) {
99+
mp_raise_NotImplementedError(translate("WatchDogTimer cannot be deinitialized once mode is set to RESET"));
100+
}
101+
// Don't change anything because RESET cannot be undone.
102+
return;
98103
}
99104
if (timer) {
100105
timer_free();

supervisor/shared/bluetooth/file_transfer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ STATIC uint8_t _process_delete(const uint8_t *raw_buf, size_t command_len) {
404404
FATFS *fs = &((fs_user_mount_t *)MP_STATE_VM(vfs_mount_table)->obj)->fatfs;
405405
char *path = (char *)((uint8_t *)command) + header_size;
406406
path[command->path_length] = '\0';
407-
FRESULT result;
407+
FRESULT result = FR_OK;
408408
FILINFO file;
409409
if (f_stat(fs, path, &file) == FR_OK) {
410410
if ((file.fattrib & AM_DIR) != 0) {

0 commit comments

Comments
 (0)