8000 Add pyb.soft_reset() and pyb.hard_reset() commands. by dhylands · Pull Request #826 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

Add pyb.soft_reset() and pyb.hard_reset() commands. #826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stmhal/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ int main(void) {
led_state(3, 0);
led_state(4, 0);
uint reset_mode = 1;
pyexec_soft_reset = 0;

#if MICROPY_HW_HAS_SWITCH
if (switch_get()) {
Expand Down Expand Up @@ -527,7 +528,7 @@ int main(void) {

// Main script is finished, so now go into REPL mode.
// The REPL mode can change, or it can request a soft reset.
for (;;) {
for (; pyexec_soft_reset == 0;) {
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
if (pyexec_raw_repl() != 0) {
break;
Expand Down
9 changes: 9 additions & 0 deletions stmhal/modpyb.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ STATIC NORETURN mp_obj_t pyb_bootloader(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_bootloader_obj, pyb_bootloader);

STATIC mp_obj_t pyb_hard_reset(void) {
NVIC_SystemReset();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_hard_reset_obj, pyb_hard_reset);


/// \function info([dump_alloc_table])
/// Print out lots of information about the board.
STATIC mp_obj_t pyb_info(uint n_args, const mp_obj_t *args) {
Expand Down Expand Up @@ -356,6 +363,8 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_pyb) },

{ MP_OBJ_NEW_QSTR(MP_QSTR_bootloader), (mp_obj_t)&pyb_bootloader_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_soft_reset), (mp_obj_t)&pyb_soft_reset_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_hard_reset), (mp_obj_t)&pyb_hard_reset_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pyb_info_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_unique_id), (mp_obj_t)&pyb_unique_id_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_freq), (mp_obj_t)&pyb_freq_obj },
Expand Down
15 changes: 15 additions & 0 deletions stmhal/pyexec.c
8000
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "genhdr/py-version.h"

pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL;
bool pyexec_soft_reset = 0;
STATIC bool repl_display_debugging_info = 0;

// parses, compiles and executes the code in the lexer
Expand Down Expand Up @@ -127,6 +128,7 @@ int pyexec_raw_repl(void) {
raw_repl_reset:
stdout_tx_str("raw REPL; CTRL-B to exit\r\n");

pyexec_soft_reset = false;
for (;;) {
vstr_reset(&line);
stdout_tx_str(">");
Expand Down Expand Up @@ -172,6 +174,9 @@ int pyexec_raw_repl(void) {

// indicate end of output with EOF character
stdout_tx_str("\004");
if (pyexec_soft_reset) {
return 1;
}
}
}

Expand Down Expand Up @@ -207,6 +212,7 @@ int pyexec_friendly_repl(void) {
}
*/

pyexec_soft_reset = false;
for (;;) {
vstr_reset(&line);
int ret = readline(&line, ">>> ");
Expand Down Expand Up @@ -249,6 +255,9 @@ int pyexec_friendly_repl(void) {
} else {
parse_compile_execute(lex, MP_PARSE_SINGLE_INPUT, true);
}
if (pyexec_soft_reset) {
return 1;
}
}
}

Expand All @@ -269,3 +278,9 @@ mp_obj_t pyb_set_repl_info(mp_obj_t o_value) {
}

MP_DEFINE_CONST_FUN_OBJ_1(pyb_set_repl_info_obj, pyb_set_repl_info);

STATIC mp_obj_t pyb_soft_reset(void) {
pyexec_soft_reset = true;
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_0(pyb_soft_reset_obj, pyb_soft_reset);
2 changes: 2 additions & 0 deletions stmhal/pyexec.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ typedef enum {
} pyexec_mode_kind_t;

extern pyexec_mode_kind_t pyexec_mode_kind;
extern bool pyexec_soft_reset;

int pyexec_raw_repl(void);
int pyexec_friendly_repl(void);
bool pyexec_file(const char *filename);

MP_DECLARE_CONST_FUN_OBJ(pyb_set_repl_info_obj);
MP_DECLARE_CONST_FUN_OBJ(pyb_soft_reset_obj);
2 changes: 2 additions & 0 deletions stmhal/qstrdefsport.h
74A8
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Q(help)
Q(pyb)
Q(unique_id)
Q(bootloader)
Q(hard_reset)
Q(soft_reset)
Q(info)
Q(sd_test)
Q(present)
Expand Down
0