From c3e37a0cdee6f85ba2d184c98074f0364786bd2b Mon Sep 17 00:00:00 2001
From: Dave Hylands <dhylands@gmail.com>
Date: Tue, 28 Apr 2015 17:25:32 -0700
Subject: [PATCH] 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()
---
 stmhal/pyexec.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/stmhal/pyexec.c b/stmhal/pyexec.c
index 8b409bf46..1a121ce3e 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, ">>> ");
 
-- 
GitLab