Skip to content

Commit c3e37a0

Browse files
dhylandsdpgeorge
authored andcommitted
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()
1 parent f27aa27 commit c3e37a0

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

stmhal/pyexec.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
#ifdef MICROPY_HAL_H
3737
#include MICROPY_HAL_H
3838
#endif
39+
#if defined(USE_DEVICE_MODE)
40+
#include "irq.h"
41+
#include "usb.h"
42+
#endif
3943
#include "readline.h"
4044
#include "pyexec.h"
4145
#include "genhdr/mpversion.h"
@@ -307,6 +311,20 @@ int pyexec_friendly_repl(void) {
307311

308312
for (;;) {
309313
input_restart:
314+
315+
#if defined(USE_DEVICE_MODE)
316+
if (usb_vcp_is_enabled()) {
317+
// If the user gets to here and interrupts are disabled then
318+
// they'll never see the prompt, traceback etc. The USB REPL needs
319+
// interrupts to be enabled or no transfers occur. So we try to
320+
// do the user a favor and reenable interrupts.
321+
if (query_irq() == IRQ_STATE_DISABLED) {
322+
enable_irq(IRQ_STATE_ENABLED);
323+
mp_hal_stdout_tx_str("PYB: enabling IRQs\r\n");
324+
}
325+
}
326+
#endif
327+
310328
vstr_reset(&line);
311329
int ret = readline(&line, ">>> ");
312330

0 commit comments

Comments
 (0)