Skip to content

Commit 57226a2

Browse files
committed
stmhal: Implement machine.soft_reset().
1 parent ad3724e commit 57226a2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

stmhal/modmachine.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "extmod/machine_mem.h"
3434
#include "extmod/machine_pulse.h"
3535
#include "extmod/machine_i2c.h"
36+
#include "lib/utils/pyexec.h"
3637
#include "lib/fatfs/ff.h"
3738
#include "lib/fatfs/diskio.h"
3839
#include "gccollect.h"
@@ -172,6 +173,12 @@ STATIC mp_obj_t machine_reset(void) {
172173
}
173174
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
174175

176+
STATIC mp_obj_t machine_soft_reset(void) {
177+
pyexec_system_exit = PYEXEC_FORCED_EXIT;
178+
nlr_raise(mp_obj_new_exception(&mp_type_SystemExit));
179+
}
180+
MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset);
181+
175182
// Activate the bootloader without BOOT* pins.
176183
STATIC NORETURN mp_obj_t machine_bootloader(void) {
177184
pyb_usb_dev_deinit();
@@ -502,6 +509,7 @@ STATIC const mp_map_elem_t machine_module_globals_table[] = {
502509
{ MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&machine_info_obj },
503510
{ MP_OBJ_NEW_QSTR(MP_QSTR_unique_id), (mp_obj_t)&machine_unique_id_obj },
504511
{ MP_OBJ_NEW_QSTR(MP_QSTR_reset), (mp_obj_t)&machine_reset_obj },
512+
{ MP_OBJ_NEW_QSTR(MP_QSTR_soft_reset), (mp_obj_t)&machine_soft_reset_obj },
505513
{ MP_OBJ_NEW_QSTR(MP_QSTR_bootloader), (mp_obj_t)&machine_bootloader_obj },
506514
{ MP_OBJ_NEW_QSTR(MP_QSTR_freq), (mp_obj_t)&machine_freq_obj },
507515
#if MICROPY_HW_ENABLE_RNG

0 commit comments

Comments
 (0)