summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDave Hylands <dhylands@gmail.com>2015-04-28 17:25:32 -0700
committerDamien George <damien.p.george@gmail.com>2015-04-29 08:27:38 +0100
commitc3e37a0cdee6f85ba2d184c98074f0364786bd2b (patch)
tree2e57e906ff9ca812d18bcc38494db0913170b7d8
parentf27aa27a0c91dac8f3abe300c5de2c01342fd20d (diff)
downloadmicropython-c3e37a0cdee6f85ba2d184c98074f0364786bd2b.tar.gz
micropython-c3e37a0cdee6f85ba2d184c98074f0364786bd2b.zip
stmhal: Automatically re-enable IRQs on the USB REPL.
This allows errors to be seen and prevents hanging the board from doing: pyb.disable_irq()
-rw-r--r--stmhal/pyexec.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/stmhal/pyexec.c b/stmhal/pyexec.c
index 8b409bf460..1a121ce3e5 100644
--- a/stmhal/pyexec.c
+++ b/stmhal/pyexec.c
@@ -36,6 +36,10 @@
#ifdef MICROPY_HAL_H
#include MICROPY_HAL_H
#endif
+#if defined(USE_DEVICE_MODE)
+#include "irq.h"
+#include "usb.h"
+#endif
#include "readline.h"
#include "pyexec.h"
#include "genhdr/mpversion.h"
@@ -307,6 +311,20 @@ friendly_repl_reset:
for (;;) {
input_restart:
+
+ #if defined(USE_DEVICE_MODE)
+ if (usb_vcp_is_enabled()) {
+ // If the user gets to here and interrupts are disabled then
+ // they'll never see the prompt, traceback etc. The USB REPL needs
+ // interrupts to be enabled or no transfers occur. So we try to
+ // do the user a favor and reenable interrupts.
+ if (query_irq() == IRQ_STATE_DISABLED) {
+ enable_irq(IRQ_STATE_ENABLED);
+ mp_hal_stdout_tx_str("PYB: enabling IRQs\r\n");
+ }
+ }
+ #endif
+
vstr_reset(&line);
int ret = readline(&line, ">>> ");