Commit 36808d4e authored by Damien George's avatar Damien George

esp8266/main: Activate UART(0) on dupterm for REPL before boot.py runs.

So that the user can explicitly deactivate UART(0) if needed.  See
issue #4314.

This introduces some risk to "brick" the device, if the user disables the
REPL without providing an alternative REPL (eg WebREPL), or any way to
reenable it.  In such a case the device needs to be erased and
reprogrammed.  This seems unavoidable, given the desire to have the option
to use the UART for something other than the REPL.
parent 5064df20
......@@ -63,23 +63,9 @@ STATIC void mp_reset(void) {
pin_init0();
readline_init0();
dupterm_task_init();
#if MICROPY_MODULE_FROZEN
pyexec_frozen_module("_boot.py");
pyexec_file("boot.py");
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
pyexec_file("main.py");
}
#endif
// Check if there are any dupterm objects registered and if not then
// activate UART(0), or else there will never be any chance to get a REPL
size_t idx;
for (idx = 0; idx < MICROPY_PY_OS_DUPTERM; ++idx) {
if (MP_STATE_VM(dupterm_objs[idx]) != MP_OBJ_NULL) {
break;
}
}
if (idx == MICROPY_PY_OS_DUPTERM) {
// Activate UART(0) on dupterm slot 1 for the REPL
{
mp_obj_t args[2];
args[0] = MP_OBJ_NEW_SMALL_INT(0);
args[1] = MP_OBJ_NEW_SMALL_INT(115200);
......@@ -87,8 +73,15 @@ STATIC void mp_reset(void) {
args[1] = MP_OBJ_NEW_SMALL_INT(1);
extern mp_obj_t os_dupterm(size_t n_args, const mp_obj_t *args);
os_dupterm(2, args);
mp_hal_stdout_tx_str("Activated UART(0) for REPL\r\n");
}
#if MICROPY_MODULE_FROZEN
pyexec_frozen_module("_boot.py");
pyexec_file("boot.py");
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
pyexec_file("main.py");
}
#endif
}
void soft_reset(void) {
......
......@@ -45,7 +45,7 @@ def setup():
#import esp
#esp.osdebug(None)
import uos, machine
uos.dupterm(machine.UART(0, 115200), 1)
#uos.dupterm(None, 1) # disable REPL on UART(0)
import gc
#import webrepl
#webrepl.start()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment